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;
}
*/
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.
*
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)
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)
ao2_cleanup(endpoint->channel_ids);
endpoint->channel_ids = NULL;
+ ao2_cleanup(endpoint->snapshot);
+ endpoint->snapshot = NULL;
+
ast_string_field_free_memory(endpoint);
}
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)
{