#include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision: $") #include "asterisk/module.h" #include "asterisk/logger.h" static int load_module(void){ // Init code here return AST_MODULE_LOAD_SUCCESS; } static int unload_module(void){ // Destroy code here return 0; } AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hello World");
stasis_subscribe(ast_endpoint_topic_all(),acl_change_stasis_dev_status,NULL);
ast_endpoint_topic_all () - returns the name of the "Topic" of the message.
acl_change_stasis_dev_status - This is the function that will be called when the necessary message for us from the specified topic appears in stasis.
static void acl_change_stasis_dev_status(void *data, struct stasis_subscription *sub, struct stasis_message *msg){ }
ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
void ast_endpoint_blob_publish(struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob) { RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); if (blob) { message = ast_endpoint_blob_create(endpoint, type, blob); } if (message) { stasis_publish(ast_endpoint_topic(endpoint), message); } } struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob) { RAII_VAR(struct ast_endpoint_blob *, obj, NULL, ao2_cleanup); RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); if (!type) { return NULL; } if (!blob) { blob = ast_json_null(); } if (!(obj = ao2_alloc(sizeof(*obj), endpoint_blob_dtor))) { return NULL; } if (endpoint) { if (!(obj->snapshot = ast_endpoint_snapshot_create(endpoint))) { return NULL; } } obj->blob = ast_json_ref(blob); if (!(msg = stasis_message_create(type, obj))) { return NULL; } ao2_ref(msg, +1); return msg; }
if(ast_endpoint_state_type() != stasis_message_type(msg))return; // , ? // Asterisk struct ast_endpoint_blob * n=stasis_message_data(msg); // ast_endpoint_blob // JSON struct ast_json * m; struct ast_endpoint_snapshot *snap; // c JSON ast_endpoint_snapshot snap=n->snapshot; // m=n->blob; // JSON char buffer[1050]; sprintf(buffer,"Device %s (%s): %s\n",snap->id,ast_endpoint_state_to_string(snap->state),ast_json_dump_string_format(m,AST_JSON_COMPACT)); ast_log(LOG_NOTICE,buffer); //
#include "asterisk/stasis_endpoints.h" #include "asterisk/stasis.h" #include "asterisk/stasis_message_router.h" #include "asterisk/stasis_channels.h" #include "asterisk/stasis_bridges.h" #include "asterisk/stasis_system.h" #include "asterisk/devicestate.h" #include "asterisk/json.h"
#include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision: $") #include "asterisk/module.h" #include "asterisk/logger.h" #include "asterisk/stasis_endpoints.h" #include "asterisk/stasis.h" #include "asterisk/stasis_message_router.h" #include "asterisk/stasis_channels.h" #include "asterisk/stasis_bridges.h" #include "asterisk/stasis_system.h" #include "asterisk/devicestate.h" #include "asterisk/json.h" static void acl_change_stasis_dev_status(void *data, struct stasis_subscription *sub, struct stasis_message *msg){ if(ast_endpoint_state_type() != stasis_message_type(msg))return; struct ast_endpoint_blob * n=stasis_message_data(msg); struct ast_json * m; struct ast_endpoint_snapshot *snap; snap=n->snapshot; m=n->blob; char buffer[1050]; sprintf(buffer,"Device %s (%s): %s\n",snap->id,ast_endpoint_state_to_string(snap->state),ast_json_dump_string_format(m,AST_JSON_COMPACT)); ast_log(LOG_NOTICE,buffer); } static int load_module(void){ stasis_subscribe(ast_endpoint_topic_all(),acl_change_stasis_dev_status,NULL); return AST_MODULE_LOAD_SUCCESS; } static int unload_module(void){ // return 0; }
Source: https://habr.com/ru/post/312630/
All Articles