Make stasis unsubscription functions return NULL
authorKinsey Moore <kmoore@digium.com>
Fri, 15 Mar 2013 12:58:23 +0000 (12:58 +0000)
committerKinsey Moore <kmoore@digium.com>
Fri, 15 Mar 2013 12:58:23 +0000 (12:58 +0000)
Unsubscribing things in Asterisk seems to very commonly follow with
NULLing out the variable that was unsubscribed. This change makes that
a bit simpler.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383168 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/stasis.h
main/stasis.c
main/stasis_cache.c

index 1d35bf8..9a5f753 100644 (file)
@@ -306,9 +306,10 @@ struct stasis_subscription *stasis_subscribe(struct stasis_topic *topic,
  * delivery of the final message.
  *
  * \param subscription Subscription to cancel.
  * delivery of the final message.
  *
  * \param subscription Subscription to cancel.
+ * \retval NULL for convenience
  * \since 12
  */
  * \since 12
  */
-void stasis_unsubscribe(struct stasis_subscription *subscription);
+struct stasis_subscription *stasis_unsubscribe(struct stasis_subscription *subscription);
 
 /*!
  * \brief Create a subscription which forwards all messages from one topic to
 
 /*!
  * \brief Create a subscription which forwards all messages from one topic to
@@ -450,9 +451,10 @@ struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *or
 /*!
  * Unsubscribes a caching topic from its upstream topic.
  * \param caching_topic Caching topic to unsubscribe
 /*!
  * Unsubscribes a caching topic from its upstream topic.
  * \param caching_topic Caching topic to unsubscribe
+ * \retval NULL for convenience
  * \since 12
  */
  * \since 12
  */
-void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic);
+struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic);
 
 /*!
  * \brief Returns the topic of cached events from a caching topics.
 
 /*!
  * \brief Returns the topic of cached events from a caching topics.
index d1f1153..7f18bf5 100644 (file)
@@ -172,7 +172,7 @@ struct stasis_subscription *stasis_subscribe(struct stasis_topic *topic, stasis_
        return __stasis_subscribe(topic, callback, data, 1);
 }
 
        return __stasis_subscribe(topic, callback, data, 1);
 }
 
-void stasis_unsubscribe(struct stasis_subscription *sub)
+struct stasis_subscription *stasis_unsubscribe(struct stasis_subscription *sub)
 {
        if (sub) {
                size_t i;
 {
        if (sub) {
                size_t i;
@@ -186,12 +186,13 @@ void stasis_unsubscribe(struct stasis_subscription *sub)
                                topic->subscribers[i] = topic->subscribers[--topic->num_subscribers_current];
                                /* Unsubscribing unrefs the subscription */
                                ao2_cleanup(sub);
                                topic->subscribers[i] = topic->subscribers[--topic->num_subscribers_current];
                                /* Unsubscribing unrefs the subscription */
                                ao2_cleanup(sub);
-                               return;
+                               return NULL;
                        }
                }
 
                ast_log(LOG_ERROR, "Internal error: subscription has invalid topic\n");
        }
                        }
                }
 
                ast_log(LOG_ERROR, "Internal error: subscription has invalid topic\n");
        }
+       return NULL;
 }
 
 int stasis_subscription_is_subscribed(const struct stasis_subscription *sub)
 }
 
 int stasis_subscription_is_subscribed(const struct stasis_subscription *sub)
index f8518ce..a824928 100644 (file)
@@ -65,7 +65,7 @@ struct stasis_topic *stasis_caching_get_topic(struct stasis_caching_topic *cachi
        return caching_topic->topic;
 }
 
        return caching_topic->topic;
 }
 
-void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
+struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
 {
        if (caching_topic) {
                if (stasis_subscription_is_subscribed(caching_topic->sub)) {
 {
        if (caching_topic) {
                if (stasis_subscription_is_subscribed(caching_topic->sub)) {
@@ -74,6 +74,7 @@ void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
                        ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
                }
        }
                        ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
                }
        }
+       return NULL;
 }
 
 struct cache_entry {
 }
 
 struct cache_entry {