endpoints: Allow access to latest snapshot directly.

This change adds an API call to allow direct access to the latest
snapshot of an ast_endpoint. This is then used by chan_pjsip when
calculating device state, eliminating the need to access the cache
which would incur a container find and access.
pull/1778/head
Joshua C. Colp 3 weeks ago committed by github-actions[bot]
parent 46a8521b00
commit ff34444a4b

@ -1188,9 +1188,7 @@ static int chan_pjsip_devicestate(const char *data)
return AST_DEVICE_INVALID;
}
endpoint_snapshot = ast_endpoint_latest_snapshot(ast_endpoint_get_tech(endpoint->persistent),
ast_endpoint_get_resource(endpoint->persistent));
endpoint_snapshot = ast_endpoint_get_snapshot(endpoint->persistent);
if (!endpoint_snapshot) {
return AST_DEVICE_INVALID;
}

@ -169,6 +169,18 @@ const char *ast_endpoint_get_id(const struct ast_endpoint *endpoint);
*/
enum ast_endpoint_state ast_endpoint_get_state(const struct ast_endpoint *endpoint);
/*!
* \brief Gets the latest snapshot of the given endpoint.
*
* \param endpoint The endpoint.
* \return Latest snapshot of the endpoint.
* \retval NULL if endpoint is \c NULL.
* \since 20.19.0
* \since 22.9.0
* \since 23.3.0
*/
struct ast_endpoint_snapshot *ast_endpoint_get_snapshot(struct ast_endpoint *endpoint);
/*!
* \brief Updates the state of the given endpoint.
*

@ -71,6 +71,8 @@ struct ast_endpoint {
struct ao2_container *channel_ids;
/*! Forwarding subscription from an endpoint to its tech endpoint */
struct stasis_forward *tech_forward;
/*! The latest snapshot of the endpoint */
struct ast_endpoint_snapshot *snapshot;
};
AO2_STRING_FIELD_HASH_FN(ast_endpoint, id)
@ -137,6 +139,10 @@ static void endpoint_publish_snapshot(struct ast_endpoint *endpoint)
return;
}
stasis_publish(ast_endpoint_topic(endpoint), message);
ao2_lock(endpoint);
ao2_replace(endpoint->snapshot, snapshot);
ao2_unlock(endpoint);
}
static void endpoint_dtor(void *obj)
@ -149,6 +155,9 @@ static void endpoint_dtor(void *obj)
ao2_cleanup(endpoint->channel_ids);
endpoint->channel_ids = NULL;
ao2_cleanup(endpoint->snapshot);
endpoint->snapshot = NULL;
ast_string_field_free_memory(endpoint);
}
@ -362,6 +371,21 @@ enum ast_endpoint_state ast_endpoint_get_state(const struct ast_endpoint *endpoi
return endpoint->state;
}
struct ast_endpoint_snapshot *ast_endpoint_get_snapshot(struct ast_endpoint *endpoint)
{
struct ast_endpoint_snapshot *snapshot;
if (!endpoint) {
return NULL;
}
ao2_lock(endpoint);
snapshot = ao2_bump(endpoint->snapshot);
ao2_unlock(endpoint);
return snapshot;
}
void ast_endpoint_set_state(struct ast_endpoint *endpoint,
enum ast_endpoint_state state)
{

Loading…
Cancel
Save