[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385806 - /team/mmichelson/pub_sub/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 15 13:29:33 CDT 2013
Author: mmichelson
Date: Mon Apr 15 13:29:30 2013
New Revision: 385806
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385806
Log:
Add reload support.
This makes it so that a new container of unsolicited MWI will replace the old
one when a reload occurs. This way, any changes to endpoints' mailbox settings
can be reflected properly after a reload.
The next step is to do an audit of references since I'm almost certain I've
got things pretty messed up at this point. The intention is for the stasis
subscription to be the driving force behind the destruction of the MWI
subscriptions.
Modified:
team/mmichelson/pub_sub/res/res_sip_mwi.c
Modified: team/mmichelson/pub_sub/res/res_sip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_mwi.c?view=diff&rev=385806&r1=385805&r2=385806
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Mon Apr 15 13:29:30 2013
@@ -73,15 +73,6 @@
char mailbox[1];
};
-static void mwi_stasis_subscription_destructor(void *obj)
-{
- struct mwi_stasis_subscription *mwi_stasis = obj;
-
- if (mwi_stasis->stasis_sub) {
- mwi_stasis->stasis_sub = stasis_unsubscribe(mwi_stasis->stasis_sub);
- }
-}
-
static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
struct stasis_topic *topic, struct stasis_message *msg);
@@ -90,8 +81,7 @@
struct mwi_stasis_subscription *mwi_stasis_sub;
struct stasis_topic *topic;
- mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox),
- mwi_stasis_subscription_destructor);
+ mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox), NULL);
if (!mwi_stasis_sub) {
return NULL;
}
@@ -503,9 +493,27 @@
return 0;
}
+static int unsubscribe_stasis(void *obj, void *arg, int flags)
+{
+ struct mwi_stasis_subscription *mwi_stasis = obj;
+ if (mwi_stasis->stasis_sub) {
+ mwi_stasis->stasis_sub = stasis_unsubscribe(mwi_stasis->stasis_sub);
+ }
+ return CMP_MATCH;
+}
+
+static int unsubscribe(void *obj, void *arg, int flags)
+{
+ struct mwi_subscription *mwi_sub = obj;
+
+ ao2_callback(mwi_sub->stasis_subs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe_stasis, NULL);
+ return CMP_MATCH;
+}
+
static void create_mwi_subscriptions(void)
{
struct ao2_container *mwi_subscriptions = ao2_container_alloc(MWI_BUCKETS, mwi_sub_hash, mwi_sub_cmp);
+ RAII_VAR(struct ao2_container *, old_mwi_subscriptions, ao2_global_obj_ref(unsolicited_mwi), ao2_cleanup);
RAII_VAR(struct ao2_container *, endpoints, ast_sorcery_retrieve_by_fields(
ast_sip_get_sorcery(), "endpoint", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL),
ao2_cleanup);
@@ -514,10 +522,19 @@
return;
}
+ if (old_mwi_subscriptions) {
+ ao2_callback(old_mwi_subscriptions, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
+ }
ao2_callback(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, mwi_subscriptions);
ao2_global_obj_replace_unref(unsolicited_mwi, mwi_subscriptions);
}
+static int reload(void)
+{
+ create_mwi_subscriptions();
+ return 0;
+}
+
static int load_module(void)
{
if (ast_sip_register_subscription_handler(&mwi_handler)) {
@@ -529,6 +546,11 @@
static int unload_module(void)
{
+ RAII_VAR(struct ao2_container *, mwi_subscriptions, ao2_global_obj_ref(unsolicited_mwi), ao2_cleanup);
+ if (mwi_subscriptions) {
+ ao2_callback(mwi_subscriptions, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
+ ao2_global_obj_release(unsolicited_mwi);
+ }
ast_sip_unregister_subscription_handler(&mwi_handler);
return 0;
}
@@ -536,5 +558,6 @@
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP MWI resource",
.load = load_module,
.unload = unload_module,
+ .reload = reload,
.load_pri = AST_MODPRI_CHANNEL_DEPEND,
);
More information about the asterisk-commits
mailing list