diff options
author | David M. Lee <dlee@digium.com> | 2013-06-11 15:46:35 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-06-11 15:46:35 +0000 |
commit | dbdb2b1b3a618a79b3e42c77c05cb2688b4da08d (patch) | |
tree | 6d7174c03a0388cf81bee13403cf4c118184d1d9 /main/manager.c | |
parent | 2053fc31594d4069cb178e591ab2b4e0df08b268 (diff) |
Add vtable and methods for to_json and to_ami for Stasis messages
When a Stasis message type is defined in a loadable module, handling
those messages for AMI and res_stasis events can be cumbersome.
This patch adds a vtable to stasis_message_type, with to_ami and
to_json virtual functions. These allow messages to be handled
abstractly without putting module-specific code in core.
As an example, the VarSet AMI event was refactored to use the to_ami
virtual function.
(closes issue ASTERISK-21817)
Review: https://reviewboard.asterisk.org/r/2579/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391403 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/manager.c')
-rw-r--r-- | main/manager.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/main/manager.c b/main/manager.c index b8e55de4f..eb01cc536 100644 --- a/main/manager.c +++ b/main/manager.c @@ -1313,6 +1313,23 @@ struct ast_str *ast_manager_str_from_json_object(struct ast_json *blob, key_excl return output_str; } +static void manager_default_msg_cb(void *data, struct stasis_subscription *sub, + struct stasis_topic *topic, + struct stasis_message *message) +{ + RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup); + + ev = stasis_message_to_ami(message); + + if (ev == NULL) { + /* Not and AMI message; disregard */ + return; + } + + manager_event(ev->event_flags, ev->manager_event, "%s", + ev->extra_fields); +} + static void manager_generic_msg_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message) @@ -7686,7 +7703,12 @@ static void manager_shutdown(void) */ static int manager_subscriptions_init(void) { - STASIS_MESSAGE_TYPE_INIT(ast_manager_get_generic_type); + int res; + + res = STASIS_MESSAGE_TYPE_INIT(ast_manager_get_generic_type); + if (res != 0) { + return -1; + } manager_topic = stasis_topic_create("manager_topic"); if (!manager_topic) { return -1; @@ -7696,10 +7718,13 @@ static int manager_subscriptions_init(void) return -1; } - if (stasis_message_router_add(stasis_router, - ast_manager_get_generic_type(), - manager_generic_msg_cb, - NULL)) { + res |= stasis_message_router_set_default(stasis_router, + manager_default_msg_cb, NULL); + + res |= stasis_message_router_add(stasis_router, + ast_manager_get_generic_type(), manager_generic_msg_cb, NULL); + + if (res != 0) { return -1; } return 0; |