Files
asterisk/res/res_manager_devicestate.c
George Joseph 8c07517a6f docs: Add version information to manager event instance XML elements
* Do a git blame on the embedded XML managerEvent elements.

* From the commit hash, grab the summary line.

* Do a git log --grep <summary> to find the cherry-pick commits in all
  branches that match.

* Do a git patch-id to ensure the commits are all related and didn't get
  a false match on the summary.

* Do a git tag --contains <commit> to find the tags that contain each
  commit.

* Weed out all tags not ..0.

* Sort and discard any .0.0 and following tags where the commit
  appeared in an earlier branch.

* The result is a single tag for each branch where the application or function
  was defined.

The events defined in res/res_pjsip/pjsip_manager.xml were done by hand
because the XML was extracted from the C source file relatively recently.

Two bugs were fixed along the way...

* The get_documentation awk script was exiting after it processed the first
  DOCUMENTATION block it found in a file.  We have at least 1 source file
  with multiple DOCUMENTATION blocks so only the first one in them was being
  processed.  The awk script was changed to continue searching rather
  than exiting after the first block.

* Fixing the awk script revealed an issue in logger.c where the third
  DOCUMENTATION block contained a XML fragment that consisted only of
  a managerEventInstance element that wasn't wrapped in a managerEvent
  element.  Since logger_doc.xml already existed, the remaining fragments
  in logger.c were moved to it and properly organized.

(cherry picked from commit a47b8e2d40)
2025-01-23 18:39:42 +00:00

155 lines
4.3 KiB
C

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2014, Digium, Inc.
*
* Mark Michelson <mmichelson@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*** MODULEINFO
<support_level>core</support_level>
***/
/*** DOCUMENTATION
<manager name="DeviceStateList" language="en_US">
<since>
<version>13.0.0</version>
</since>
<synopsis>
List the current known device states.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
</syntax>
<description>
<para>This will list out all known device states in a
sequence of <replaceable>DeviceStateChange</replaceable> events.
When finished, a <replaceable>DeviceStateListComplete</replaceable> event
will be emitted.</para>
</description>
<see-also>
<ref type="managerEvent">DeviceStateChange</ref>
<ref type="function">DEVICE_STATE</ref>
</see-also>
<responses>
<list-elements>
<xi:include xpointer="xpointer(/docs/managerEvent[@name='DeviceStateChange'])" />
</list-elements>
<managerEvent name="DeviceStateListComplete" language="en_US">
<managerEventInstance class="EVENT_FLAG_COMMAND">
<since><version>13.0.0</version></since>
<synopsis>
Indicates the end of the list the current known extension states.
</synopsis>
<syntax>
<parameter name="EventList">
<para>Conveys the status of the event list.</para>
</parameter>
<parameter name="ListItems">
<para>Conveys the number of statuses reported.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
</responses>
</manager>
***/
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/manager.h"
#include "asterisk/stasis.h"
#include "asterisk/devicestate.h"
static struct stasis_forward *topic_forwarder;
static int action_devicestatelist(struct mansession *s, const struct message *m)
{
RAII_VAR(struct ao2_container *, device_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;
device_states = stasis_cache_dump_by_eid(ast_device_state_cache(),
ast_device_state_message_type(), NULL);
if (!device_states) {
astman_send_error(s, m, "Memory Allocation Failure");
return 0;
}
astman_send_listack(s, m, "Device State Changes will follow", "start");
it_states = ao2_iterator_init(device_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_send_list_complete_start(s, m, "DeviceStateListComplete", count);
astman_send_list_complete_end(s);
return 0;
}
static int unload_module(void)
{
topic_forwarder = stasis_forward_cancel(topic_forwarder);
ast_manager_unregister("DeviceStateList");
return 0;
}
static int load_module(void)
{
struct stasis_topic *manager_topic;
manager_topic = ast_manager_get_topic();
if (!manager_topic) {
return AST_MODULE_LOAD_DECLINE;
}
topic_forwarder = stasis_forward_all(ast_device_state_topic_all(), manager_topic);
if (!topic_forwarder) {
return AST_MODULE_LOAD_DECLINE;
}
if (ast_manager_register_xml("DeviceStateList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING,
action_devicestatelist)) {
topic_forwarder = stasis_forward_cancel(topic_forwarder);
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Device State Topic Forwarder",
.support_level = AST_MODULE_SUPPORT_CORE,
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
);