[asterisk-commits] mmichelson: branch mmichelson/pub_sub r384599 - in /team/mmichelson/pub_sub: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 2 16:44:36 CDT 2013


Author: mmichelson
Date: Tue Apr  2 16:44:34 2013
New Revision: 384599

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384599
Log:
Add methods for registering and unregistering subscription handlers.


Modified:
    team/mmichelson/pub_sub/include/asterisk/res_sip_pubsub.h
    team/mmichelson/pub_sub/res/res_sip_pubsub.c

Modified: team/mmichelson/pub_sub/include/asterisk/res_sip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/include/asterisk/res_sip_pubsub.h?view=diff&rev=384599&r1=384598&r2=384599
==============================================================================
--- team/mmichelson/pub_sub/include/asterisk/res_sip_pubsub.h (original)
+++ team/mmichelson/pub_sub/include/asterisk/res_sip_pubsub.h Tue Apr  2 16:44:34 2013
@@ -18,6 +18,8 @@
 
 #ifndef _RES_SIP_PUBSUB_H
 #define _RES_SIP_PUBSUB_H
+
+#include "asterisk/linkedlists.h"
 
 /* Forward declarations */
 struct pjsip_rx_data;
@@ -164,6 +166,7 @@
      * \retval non-zero Failure
      */
     int (*refresh_subscription)(struct ast_sip_subscription *sub);
+	AST_LIST_ENTRY(ast_sip_subscription_handler) next;
 };
 
 /*!
@@ -310,11 +313,11 @@
  * \retval 0 Handler was registered successfully
  * \retval non-zero Handler was not registered successfully
  */
-int ast_sip_register_subscription_handler(const struct ast_sip_subscription_handler *handler);
+int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler);
  
 /*!
  * \brief Unregister a subscription handler
  */
-void ast_sip_unregister_subscription_handler(const struct ast_sip_subscription_handler *handler);
+void ast_sip_unregister_subscription_handler(struct ast_sip_subscription_handler *handler);
 
 #endif /* RES_SIP_PUBSUB_H */

Modified: team/mmichelson/pub_sub/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_pubsub.c?view=diff&rev=384599&r1=384598&r2=384599
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_pubsub.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_pubsub.c Tue Apr  2 16:44:34 2013
@@ -27,6 +27,7 @@
 
 #include "asterisk/res_sip_pubsub.h"
 #include "asterisk/module.h"
+#include "asterisk/linkedlists.h"
  
 struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
         enum ast_sip_subscription_role role, struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
@@ -81,26 +82,38 @@
 	/* XXX STUB */
 }
 
-int ast_sip_register_subscription_handler(const struct ast_sip_subscription_handler *handler)
+AST_RWLIST_HEAD_STATIC(subscription_handlers, ast_sip_subscription_handler);
+
+int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler)
 {
-	/* XXX STUB */
+	/* TODO Ensure duplicate events can't get registered */
+	SCOPED_LOCK(lock, &subscription_handlers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+	AST_RWLIST_INSERT_TAIL(&subscription_handlers, handler, next);
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
  
-void ast_sip_unregister_subscription_handler(const struct ast_sip_subscription_handler *handler)
+void ast_sip_unregister_subscription_handler(struct ast_sip_subscription_handler *handler)
 {
-	/* XXX STUB */
+	struct ast_sip_subscription_handler *iter;
+	SCOPED_LOCK(lock, &subscription_handlers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&subscription_handlers, iter, next) {
+		if (handler == iter) {
+			AST_RWLIST_REMOVE_CURRENT(next);
+			ast_module_unref(ast_module_info->self);
+			break;
+		}
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END;
 }
 
 static int load_module(void)
 {
-	/* XXX STUB */
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)
 {
-	/* XXX STUB */
 	return 0;
 }
 




More information about the asterisk-commits mailing list