Debian Codegraph @

res/res_manager_devicestate.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014, Digium, Inc.
5 *
6 * Mark Michelson <[email protected]>
7 *
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.
13 *
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.
17 */
18
19 /*** MODULEINFO
20 <support_level>core</support_level>
21 ***/
22
23 /*** DOCUMENTATION
24 <manager name="DeviceStateList" language="en_US">
25 <since>
26 <version>13.0.0</version>
27 </since>
28 <synopsis>
29 List the current known device states.
30 </synopsis>
31 <syntax>
32 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
33 </syntax>
34 <description>
35 <para>This will list out all known device states in a
36 sequence of <replaceable>DeviceStateChange</replaceable> events.
37 When finished, a <replaceable>DeviceStateListComplete</replaceable> event
38 will be emitted.</para>
39 </description>
40 <see-also>
41 <ref type="managerEvent">DeviceStateChange</ref>
42 <ref type="function">DEVICE_STATE</ref>
43 </see-also>
44 <responses>
45 <list-elements>
46 <xi:include xpointer="xpointer(/docs/managerEvent[@name='DeviceStateChange'])" />
47 </list-elements>
48 <managerEvent name="DeviceStateListComplete" language="en_US">
49 <managerEventInstance class="EVENT_FLAG_COMMAND">
50 <since>
51 <version>13.0.0</version>
52 </since>
53 <synopsis>
54 Indicates the end of the list the current known extension states.
55 </synopsis>
56 <syntax>
57 <parameter name="EventList">
58 <para>Conveys the status of the event list.</para>
59 </parameter>
60 <parameter name="ListItems">
61 <para>Conveys the number of statuses reported.</para>
62 </parameter>
63 </syntax>
64 </managerEventInstance>
65 </managerEvent>
66 </responses>
67 </manager>
68 ***/
69
70
71 #include "asterisk.h"
72 #include "asterisk/module.h"
73 #include "asterisk/manager.h"
74 #include "asterisk/stasis.h"
75 #include "asterisk/devicestate.h"
76
77 static struct stasis_forward *topic_forwarder;
78
79 static int action_devicestatelist(struct mansession *s, const struct message *m)
80 {
81 RAII_VAR(struct ao2_container *, device_states, NULL, ao2_cleanup);
82 const char *action_id = astman_get_header(m, "ActionID");
83 struct stasis_message *msg;
84 struct ao2_iterator it_states;
85 int count = 0;
86
87 device_states = stasis_cache_dump_by_eid(ast_device_state_cache(),
88 ast_device_state_message_type(), NULL);
89 if (!device_states) {
90 astman_send_error(s, m, "Memory Allocation Failure");
91 return 0;
92 }
93
94 astman_send_listack(s, m, "Device State Changes will follow", "start");
95
96 it_states = ao2_iterator_init(device_states, 0);
97 for (; (msg = ao2_iterator_next(&it_states)); ao2_ref(msg, -1)) {
98 struct ast_manager_event_blob *blob = stasis_message_to_ami(msg);
99
100 if (!blob) {
101 continue;
102 }
103
104 count++;
105
106 astman_append(s, "Event: %s\r\n", blob->manager_event);
107 if (!ast_strlen_zero(action_id)) {
108 astman_append(s, "ActionID: %s\r\n", action_id);
109 }
110 astman_append(s, "%s\r\n", blob->extra_fields);
111 ao2_ref(blob, -1);
112 }
113 ao2_iterator_destroy(&it_states);
114
115 astman_send_list_complete_start(s, m, "DeviceStateListComplete", count);
116 astman_send_list_complete_end(s);
117
118 return 0;
119 }
120
121 static int unload_module(void)
122 {
123 topic_forwarder = stasis_forward_cancel(topic_forwarder);
124 ast_manager_unregister("DeviceStateList");
125
126 return 0;
127 }
128
129 static int load_module(void)
130 {
131 struct stasis_topic *manager_topic;
132
133 manager_topic = ast_manager_get_topic();
134 if (!manager_topic) {
135 return AST_MODULE_LOAD_DECLINE;
136 }
137 topic_forwarder = stasis_forward_all(ast_device_state_topic_all(), manager_topic);
138 if (!topic_forwarder) {
139 return AST_MODULE_LOAD_DECLINE;
140 }
141
142 if (ast_manager_register_xml("DeviceStateList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING,
143 action_devicestatelist)) {
144 topic_forwarder = stasis_forward_cancel(topic_forwarder);
145 return AST_MODULE_LOAD_DECLINE;
146 }
147
148 return AST_MODULE_LOAD_SUCCESS;
149 }
150
151 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Device State Topic Forwarder",
152 .support_level = AST_MODULE_SUPPORT_CORE,
153 .load = load_module,
154 .unload = unload_module,
155 .load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
156 );