2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2014, Digium, Inc.
6 * Mark Michelson <mmichelson@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 <support_level>core</support_level>
24 <manager name="PresenceStateList" language="en_US">
26 List the current known presence states.
29 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
32 <para>This will list out all known presence states in a
33 sequence of <replaceable>PresenceStateChange</replaceable> events.
34 When finished, a <replaceable>PresenceStateListComplete</replaceable> event
35 will be emitted.</para>
38 <ref type="manager">PresenceState</ref>
39 <ref type="managerEvent">PresenceStatus</ref>
40 <ref type="function">PRESENCE_STATE</ref>
44 <xi:include xpointer="xpointer(/docs/managerEvent[@name='PresenceStateChange'])" />
46 <managerEvent name="PresenceStateListComplete" language="en_US">
47 <managerEventInstance class="EVENT_FLAG_COMMAND">
49 Indicates the end of the list the current known extension states.
52 <parameter name="EventList">
53 <para>Conveys the status of the event list.</para>
55 <parameter name="ListItems">
56 <para>Conveys the number of statuses reported.</para>
59 </managerEventInstance>
66 #include "asterisk/module.h"
67 #include "asterisk/manager.h"
68 #include "asterisk/stasis.h"
69 #include "asterisk/presencestate.h"
71 static struct stasis_forward *topic_forwarder;
73 static int action_presencestatelist(struct mansession *s, const struct message *m)
75 RAII_VAR(struct ao2_container *, presence_states, NULL, ao2_cleanup);
76 const char *action_id = astman_get_header(m, "ActionID");
77 struct stasis_message *msg;
78 struct ao2_iterator it_states;
81 presence_states = stasis_cache_dump(ast_presence_state_cache(),
82 ast_presence_state_message_type());
83 if (!presence_states) {
84 astman_send_error(s, m, "Memory Allocation Failure");
88 astman_send_listack(s, m, "Presence State Changes will follow", "start");
90 it_states = ao2_iterator_init(presence_states, 0);
91 for (; (msg = ao2_iterator_next(&it_states)); ao2_ref(msg, -1)) {
92 struct ast_manager_event_blob *blob = stasis_message_to_ami(msg);
100 astman_append(s, "Event: %s\r\n", blob->manager_event);
101 if (!ast_strlen_zero(action_id)) {
102 astman_append(s, "ActionID: %s\r\n", action_id);
104 astman_append(s, "%s\r\n", blob->extra_fields);
107 ao2_iterator_destroy(&it_states);
109 astman_append(s, "Event: PresenceStateListComplete\r\n");
110 if (!ast_strlen_zero(action_id)) {
111 astman_append(s, "ActionID: %s\r\n", action_id);
113 astman_append(s, "EventList: Complete\r\n"
114 "ListItems: %d\r\n\r\n", count);
119 static int unload_module(void)
121 ast_manager_unregister("PresenceStateList");
122 topic_forwarder = stasis_forward_cancel(topic_forwarder);
126 static int load_module(void)
128 struct stasis_topic *manager_topic;
130 manager_topic = ast_manager_get_topic();
131 if (!manager_topic) {
132 return AST_MODULE_LOAD_DECLINE;
134 topic_forwarder = stasis_forward_all(ast_presence_state_topic_all(), manager_topic);
135 if (!topic_forwarder) {
136 return AST_MODULE_LOAD_DECLINE;
139 if (ast_manager_register_xml("PresenceStateList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING,
140 action_presencestatelist)) {
141 topic_forwarder = stasis_forward_cancel(topic_forwarder);
142 return AST_MODULE_LOAD_DECLINE;
145 return AST_MODULE_LOAD_SUCCESS;
148 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Presence State Topic Forwarder",
149 .support_level = AST_MODULE_SUPPORT_CORE,
151 .unload = unload_module,
152 .load_pri = AST_MODPRI_DEVSTATE_CONSUMER,