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

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int mwi_cached_cb (void *obj, void *arg, int flags)
 
static void mwi_update_cb (void *data, struct stasis_subscription *sub, struct stasis_message *msg)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "MWI Device State Subscriptions" , .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_PROVIDER, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_subscriptionmwi_sub
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 105 of file res_mwi_devstate.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 105 of file res_mwi_devstate.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 105 of file res_mwi_devstate.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 71 of file res_mwi_devstate.c.

References ao2_callback, ao2_ref, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_DEVSTATE_PROVIDER, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_mwi_state_cache(), ast_mwi_state_type(), ast_mwi_topic_all(), ASTERISK_GPL_KEY, mwi_cached_cb(), mwi_update_cb(), NULL, OBJ_NODATA, stasis_cache_dump(), stasis_subscribe, stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and unload_module().

72 {
73  struct ao2_container *cached;
74 
77  }
78 
80  unload_module();
82  }
83 
85  unload_module();
87  }
88 
90  if (!cached) {
91  unload_module();
93  }
95  ao2_ref(cached, -1);
96 
98 }
struct stasis_cache * ast_mwi_state_cache(void)
Backend cache for ast_mwi_topic_cached().
Definition: mwi.c:90
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition: stasis.c:1079
struct stasis_topic * ast_mwi_topic_all(void)
Get the Stasis Message Bus API topic for MWI messages.
Definition: mwi.c:85
struct ao2_container * stasis_cache_dump(struct stasis_cache *cache, struct stasis_message_type *type)
Dump cached items to a subscription for the ast_eid_default entity.
Definition: stasis_cache.c:736
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define stasis_subscribe(topic, callback, data)
Definition: stasis.h:652
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int mwi_cached_cb(void *obj, void *arg, int flags)
static int unload_module(void)
static void mwi_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition: stasis.c:1025
Generic container type.
static struct stasis_subscription * mwi_sub

◆ mwi_cached_cb()

static int mwi_cached_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 56 of file res_mwi_devstate.c.

References mwi_update_cb(), and NULL.

Referenced by load_module().

57 {
58  struct stasis_message *msg = obj;
59  mwi_update_cb(NULL, mwi_sub, msg);
60 
61  return 0;
62 }
#define NULL
Definition: resample.c:96
static void mwi_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
static struct stasis_subscription * mwi_sub

◆ mwi_update_cb()

static void mwi_update_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message msg 
)
static

Definition at line 33 of file res_mwi_devstate.c.

References ast_debug, AST_DEVICE_INUSE, AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, ast_devstate_changed(), ast_mwi_state_type(), ast_mwi_state::new_msgs, stasis_message_data(), stasis_message_type(), and ast_mwi_state::uniqueid.

Referenced by load_module(), and mwi_cached_cb().

35 {
36  struct ast_mwi_state *mwi_state;
37 
39  return;
40  }
41 
42  mwi_state = stasis_message_data(msg);
43  if (!mwi_state) {
44  return;
45  }
46 
47  if (mwi_state->new_msgs > 0) {
48  ast_debug(1, "Sending inuse devstate change for MWI:%s\n", mwi_state->uniqueid);
50  } else {
51  ast_debug(1, "Sending not inuse devstate change for MWI:%s\n", mwi_state->uniqueid);
53  }
54 }
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:510
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
int new_msgs
Definition: mwi.h:461
const ast_string_field uniqueid
Definition: mwi.h:460
The structure that contains MWI state.
Definition: mwi.h:457

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 64 of file res_mwi_devstate.c.

References stasis_unsubscribe().

Referenced by load_module().

65 {
67 
68  return 0;
69 }
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition: stasis.c:973
static struct stasis_subscription * mwi_sub

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "MWI Device State Subscriptions" , .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_PROVIDER, }
static

Definition at line 105 of file res_mwi_devstate.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 105 of file res_mwi_devstate.c.

◆ mwi_sub

struct stasis_subscription* mwi_sub
static