X-Git-Url: http://git.asterisk.org/gitweb/?p=asterisk%2Fasterisk.git;a=blobdiff_plain;f=res%2Fres_manager_presencestate.c;h=e2cfca506578002a01a72de6374a88a5ee1273bf;hp=ef22307516ae6baeee40f9677b2981cb6168b388;hb=485d0379aeac18563f2fd3b3fee8516e32f16675;hpb=cac711fc95d205d586d451c027b7e542ce9c64b3 diff --git a/res/res_manager_presencestate.c b/res/res_manager_presencestate.c index ef22307..e2cfca5 100644 --- a/res/res_manager_presencestate.c +++ b/res/res_manager_presencestate.c @@ -20,15 +20,105 @@ core ***/ +/*** DOCUMENTATION + + + List the current known presence states. + + + + + + This will list out all known presence states in a + sequence of PresenceStateChange events. + When finished, a PresenceStateListComplete event + will be emitted. + + + PresenceState + PresenceStatus + PRESENCE_STATE + + + + + + + + + Indicates the end of the list the current known extension states. + + + + Conveys the status of the event list. + + + Conveys the number of statuses reported. + + + + + + + ***/ + #include "asterisk.h" #include "asterisk/module.h" +#include "asterisk/manager.h" #include "asterisk/stasis.h" #include "asterisk/presencestate.h" static struct stasis_forward *topic_forwarder; +static int action_presencestatelist(struct mansession *s, const struct message *m) +{ + RAII_VAR(struct ao2_container *, presence_states, NULL, ao2_cleanup); + const char *action_id = astman_get_header(m, "ActionID"); + struct stasis_message *msg; + struct ao2_iterator it_states; + int count = 0; + + presence_states = stasis_cache_dump(ast_presence_state_cache(), + ast_presence_state_message_type()); + if (!presence_states) { + astman_send_error(s, m, "Memory Allocation Failure"); + return 0; + } + + astman_send_listack(s, m, "Presence State Changes will follow", "start"); + + it_states = ao2_iterator_init(presence_states, 0); + for (; (msg = ao2_iterator_next(&it_states)); ao2_ref(msg, -1)) { + struct ast_manager_event_blob *blob = stasis_message_to_ami(msg); + + if (!blob) { + continue; + } + + count++; + + astman_append(s, "Event: %s\r\n", blob->manager_event); + if (!ast_strlen_zero(action_id)) { + astman_append(s, "ActionID: %s\r\n", action_id); + } + astman_append(s, "%s\r\n", blob->extra_fields); + ao2_ref(blob, -1); + } + ao2_iterator_destroy(&it_states); + + astman_append(s, "Event: PresenceStateListComplete\r\n"); + if (!ast_strlen_zero(action_id)) { + astman_append(s, "ActionID: %s\r\n", action_id); + } + astman_append(s, "EventList: Complete\r\n" + "ListItems: %d\r\n\r\n", count); + + return 0; +} + static int unload_module(void) { + ast_manager_unregister("PresenceStateList"); topic_forwarder = stasis_forward_cancel(topic_forwarder); return 0; } @@ -41,8 +131,16 @@ static int load_module(void) if (!manager_topic) { return AST_MODULE_LOAD_DECLINE; } - topic_forwarder = stasis_forward_all(ast_presence_state_topic_all(), manager_topic); + if (!topic_forwarder) { + return AST_MODULE_LOAD_DECLINE; + } + + if (ast_manager_register_xml("PresenceStateList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, + action_presencestatelist)) { + topic_forwarder = stasis_forward_cancel(topic_forwarder); + return AST_MODULE_LOAD_DECLINE; + } return AST_MODULE_LOAD_SUCCESS; }