Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
res_manager_devicestate.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014, Digium, Inc.
5 *
6 * Mark Michelson <mmichelson@digium.com>
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"
76
78
79static 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
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)) {
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);
117
118 return 0;
119}
120
121static int unload_module(void)
122{
124 ast_manager_unregister("DeviceStateList");
125
126 return 0;
127}
128
129static int load_module(void)
130{
132
134 if (!manager_topic) {
136 }
138 if (!topic_forwarder) {
140 }
141
146 }
147
149}
150
151AST_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,
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
Device state management.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
struct stasis_cache * ast_device_state_cache(void)
Backend cache for ast_device_state_topic_cached()
Definition: devicestate.c:676
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
Definition: devicestate.c:671
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:2028
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1986
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:2064
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:454
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1647
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:2072
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:1907
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:186
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_REPORTING
Definition: manager.h:84
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:192
#define EVENT_FLAG_CALL
Definition: manager.h:76
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODPRI_DEVSTATE_CONSUMER
Definition: module.h:347
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int action_devicestatelist(struct mansession *s, const struct message *m)
static int load_module(void)
static int unload_module(void)
static struct stasis_forward * topic_forwarder
#define NULL
Definition: resample.c:96
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
struct ast_manager_event_blob * stasis_message_to_ami(struct stasis_message *msg)
Build the AMI representation of the message.
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1575
struct ao2_container * stasis_cache_dump_by_eid(struct stasis_cache *cache, struct stasis_message_type *type, const struct ast_eid *eid)
Dump cached items to a subscription for a specific entity.
Definition: stasis_cache.c:718
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition: stasis.c:1605
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
Struct containing info for an AMI event to send out.
Definition: manager.h:503
const ast_string_field extra_fields
Definition: manager.h:508
const char * manager_event
Definition: manager.h:505
In case you didn't read that giant block of text above the mansession_session struct,...
Definition: manager.c:327
Forwarding information.
Definition: stasis.c:1558
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941