| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 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 |
); |