Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
res_manager_devicestate.c File Reference
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/manager.h"
#include "asterisk/stasis.h"
#include "asterisk/devicestate.h"
Include dependency graph for res_manager_devicestate.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int action_devicestatelist (struct mansession *s, const struct message *m)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Manager Device State Topic Forwarder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEVSTATE_CONSUMER, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_forwardtopic_forwarder
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 150 of file res_manager_devicestate.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 150 of file res_manager_devicestate.c.

◆ action_devicestatelist()

static int action_devicestatelist ( struct mansession s,
const struct message m 
)
static

Definition at line 73 of file res_manager_devicestate.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_device_state_cache(), ast_device_state_message_type(), ast_strlen_zero, astman_append(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), ast_manager_event_blob::extra_fields, ast_manager_event_blob::manager_event, NULL, RAII_VAR, stasis_cache_dump_by_eid(), and stasis_message_to_ami().

Referenced by load_module().

74 {
75  RAII_VAR(struct ao2_container *, device_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;
79  int count = 0;
80 
83  if (!device_states) {
84  astman_send_error(s, m, "Memory Allocation Failure");
85  return 0;
86  }
87 
88  astman_send_listack(s, m, "Device State Changes will follow", "start");
89 
90  it_states = ao2_iterator_init(device_states, 0);
91  for (; (msg = ao2_iterator_next(&it_states)); ao2_ref(msg, -1)) {
93 
94  if (!blob) {
95  continue;
96  }
97 
98  count++;
99 
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);
103  }
104  astman_append(s, "%s\r\n", blob->extra_fields);
105  ao2_ref(blob, -1);
106  }
107  ao2_iterator_destroy(&it_states);
108 
109  astman_send_list_complete_start(s, m, "DeviceStateListComplete", count);
111 
112  return 0;
113 }
Struct containing info for an AMI event to send out.
Definition: manager.h:491
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
const ast_string_field extra_fields
Definition: manager.h:496
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:3237
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define NULL
Definition: resample.c:96
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
const char * manager_event
Definition: manager.h:493
struct ast_manager_event_blob * stasis_message_to_ami(struct stasis_message *msg)
Build the AMI representation of the message.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#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:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
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_cache * ast_device_state_cache(void)
Backend cache for ast_device_state_topic_cached()
Definition: devicestate.c:673
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
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:3201

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 150 of file res_manager_devicestate.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 123 of file res_manager_devicestate.c.

References action_devicestatelist(), ast_device_state_topic_all(), ast_manager_get_topic(), ast_manager_register_xml, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_DEVSTATE_CONSUMER, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, EVENT_FLAG_CALL, EVENT_FLAG_REPORTING, manager_topic, stasis_forward_all(), stasis_forward_cancel(), and unload_module().

124 {
125  struct stasis_topic *manager_topic;
126 
127  manager_topic = ast_manager_get_topic();
128  if (!manager_topic) {
130  }
132  if (!topic_forwarder) {
134  }
135 
140  }
141 
143 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1490
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
Definition: devicestate.c:668
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1548
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
#define EVENT_FLAG_REPORTING
Definition: manager.h:80
static int action_devicestatelist(struct mansession *s, const struct message *m)
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:1578
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:186
static struct stasis_forward * topic_forwarder

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 115 of file res_manager_devicestate.c.

References ast_manager_unregister(), and stasis_forward_cancel().

Referenced by load_module().

116 {
118  ast_manager_unregister("DeviceStateList");
119 
120  return 0;
121 }
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7258
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1548
static struct stasis_forward * topic_forwarder

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Manager Device State Topic Forwarder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEVSTATE_CONSUMER, }
static

Definition at line 150 of file res_manager_devicestate.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 150 of file res_manager_devicestate.c.

◆ topic_forwarder

struct stasis_forward* topic_forwarder
static

Definition at line 71 of file res_manager_devicestate.c.