Asterisk - The Open Source Telephony Project  21.4.1
Functions | Variables
manager_mwi.c File Reference

The Asterisk Management Interface - AMI (MWI event handling) More...

#include "asterisk.h"
#include "asterisk/manager.h"
#include "asterisk/app.h"
#include "asterisk/mwi.h"
#include "asterisk/channel.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stasis.h"

Go to the source code of this file.

Functions

static int exclude_event_cb (const char *key)
 Callback function used by mwi_app_event_cb to weed out "Event" keys.
 
int manager_mwi_init (void)
 Initialize support for AMI MWI events. More...
 
static void manager_mwi_shutdown (void)
 
static void mwi_app_event_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 Generic MWI event callback used for one-off events from voicemail modules.
 
static void mwi_update_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 

Variables

struct stasis_message_routermwi_state_router
 
static struct stasis_forwardtopic_forwarder
 The Stasis Message Bus API subscription returned by the forwarding of the MWI topic to the manager topic.
 

Detailed Description

The Asterisk Management Interface - AMI (MWI event handling)

Author
Matt Jordan mjord.nosp@m.an@d.nosp@m.igium.nosp@m..com

Definition in file manager_mwi.c.

Function Documentation

int manager_mwi_init ( void  )

Initialize support for AMI MWI events.

Since
12
Return values
0on success
non-zeroon error

Definition at line 155 of file manager_mwi.c.

References ast_manager_get_message_router(), ast_manager_get_topic(), ast_mwi_state_type(), ast_mwi_topic_all(), ast_mwi_vm_app_type(), ast_register_cleanup(), manager_topic, mwi_app_event_cb(), stasis_forward_all(), and stasis_message_router_add().

156 {
157  int ret = 0;
158  struct stasis_topic *manager_topic;
159  struct stasis_topic *mwi_topic;
160  struct stasis_message_router *message_router;
161 
162  manager_topic = ast_manager_get_topic();
163  if (!manager_topic) {
164  return -1;
165  }
166  message_router = ast_manager_get_message_router();
167  if (!message_router) {
168  return -1;
169  }
170  mwi_topic = ast_mwi_topic_all();
171  if (!mwi_topic) {
172  return -1;
173  }
174 
175  topic_forwarder = stasis_forward_all(mwi_topic, manager_topic);
176  if (!topic_forwarder) {
177  return -1;
178  }
179 
180  ast_register_cleanup(manager_mwi_shutdown);
181 
182  ret |= stasis_message_router_add(message_router,
184  mwi_update_cb,
185  NULL);
186 
187  ret |= stasis_message_router_add(message_router,
190  NULL);
191 
192  /* If somehow we failed to add any routes, just shut down the whole
193  * thing and fail it.
194  */
195  if (ret) {
196  manager_mwi_shutdown();
197  return -1;
198  }
199 
200  return 0;
201 }
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition: manager.c:1644
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
static void mwi_app_event_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Generic MWI event callback used for one-off events from voicemail modules.
Definition: manager_mwi.c:55
struct stasis_message_router * ast_manager_get_message_router(void)
Get the stasis_message_router for AMI.
Definition: manager.c:1885
static struct stasis_forward * topic_forwarder
The Stasis Message Bus API subscription returned by the forwarding of the MWI topic to the manager to...
Definition: manager_mwi.c:43
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1880
struct stasis_topic * ast_mwi_topic_all(void)
Get the Stasis Message Bus API topic for MWI messages.
Definition: mwi.c:89
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
struct stasis_message_type * ast_mwi_vm_app_type(void)
Get the Stasis Message Bus API message type for voicemail application specific messages.