Asterisk - The Open Source Telephony Project  18.5.0
res_mwi_devstate.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2014, Schmooze Com, Inc.
5  *
6  * Jason Parker <[email protected]>
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 #include "asterisk.h"
24 
25 #include "asterisk/mwi.h"
26 #include "asterisk/devicestate.h"
27 #include "asterisk/module.h"
29 #include "asterisk/stasis.h"
30 
32 
33 static void mwi_update_cb(void *data, struct stasis_subscription *sub,
34  struct stasis_message *msg)
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 }
55 
56 static int mwi_cached_cb(void *obj, void *arg, int flags)
57 {
58  struct stasis_message *msg = obj;
59  mwi_update_cb(NULL, mwi_sub, msg);
60 
61  return 0;
62 }
63 
64 static int unload_module(void)
65 {
66  mwi_sub = stasis_unsubscribe(mwi_sub);
67 
68  return 0;
69 }
70 
71 static int load_module(void)
72 {
73  struct ao2_container *cached;
74 
75  if (!(mwi_sub = stasis_subscribe(ast_mwi_topic_all(), mwi_update_cb, NULL))) {
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 }
99 
100 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "MWI Device State Subscriptions",
101  .support_level = AST_MODULE_SUPPORT_CORE,
102  .load = load_module,
103  .unload = unload_module,
104  .load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
105 );
Asterisk main include file. File version handling, generic pbx functions.
Device state management.
struct stasis_cache * ast_mwi_state_cache(void)
Backend cache for ast_mwi_topic_cached().
Definition: mwi.c:90
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
static int load_module(void)
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
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 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
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define stasis_subscribe(topic, callback, data)
Definition: stasis.h:652
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition: stasis.c:973
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)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static int unload_module(void)
static void mwi_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
int new_msgs
Definition: mwi.h:461
const ast_string_field uniqueid
Definition: mwi.h:460
Asterisk MWI API.
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
struct stasis_forward * sub
Definition: res_corosync.c:240
Generic container type.
The structure that contains MWI state.
Definition: mwi.h:457
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
static struct stasis_subscription * mwi_sub