[asterisk-commits] mmichelson: branch group/manager2 r111948 - /team/group/manager2/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Mar 29 00:50:37 CDT 2008


Author: mmichelson
Date: Sat Mar 29 00:50:36 2008
New Revision: 111948

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111948
Log:
Added a list for the subscriber structure and a callback to be used
for when a manager logs out. This function will probably be split at
some point so that module unloading can also reuse certain pieces to
clean up.

This compiles, but I have not tested the code changes in this commit
in any way whatsoever. Peace.


Modified:
    team/group/manager2/res/res_manager2.c

Modified: team/group/manager2/res/res_manager2.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/res/res_manager2.c?view=diff&rev=111948&r1=111947&r2=111948
==============================================================================
--- team/group/manager2/res/res_manager2.c (original)
+++ team/group/manager2/res/res_manager2.c Sat Mar 29 00:50:36 2008
@@ -16,10 +16,11 @@
 	pthread_t thread;
 	ast_cond_t cond;
 	ast_mutex_t lock;
+	AST_LIST_ENTRY(subscriber) list;
 	AST_LIST_HEAD_NOLOCK(, info_event) info_events;
 };
 
-AST_LIST_HEAD_STATIC(info_events, info_event);
+AST_LIST_HEAD_STATIC(subscribers, subscriber);
 
 #define QUEUE_EVENT_BEGIN AST_EVENT_QUEUE_MEMBER_STATUS
 struct ast_event_sub *login_sub;
@@ -153,9 +154,47 @@
 
 	setup_thread(sub);
 
+	AST_LIST_LOCK(&subscribers);
+	AST_LIST_INSERT_HEAD(&subscribers, sub, list);
+	AST_LIST_UNLOCK(&subscribers);
+
 	/* Just for testing purposes, let's subscribe to queue member device state changes */
 	ast_event_subscribe(AST_EVENT_QUEUE_MEMBER_STATUS, info_cb, sub, AST_EVENT_IE_END);
 	ast_pthread_create_background(&sub->thread, NULL, event_spitter, sub);
+}
+
+static struct subscriber *remove_subscriber(const char *name, const int fd)
+{
+	struct subscriber *sub = NULL;
+	AST_LIST_LOCK(&subscribers);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&subscribers, sub, list) {
+		if (!strcmp(name, sub->name) && sub->fd == fd) {
+			AST_LIST_REMOVE_CURRENT(list);
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+
+	return sub;
+}
+
+/*! \brief The mirror image of subscribe_start. This is called when a manager logs
+ * out. This will stop the subscriber's thread and remove the subscriber from the list
+ * of subscribers
+ *
+ * \note Currently, though this is designed to be a callback from an event as described above
+ * it is not actually implemented.
+ */
+static void subscribe_end(const struct ast_event *event, void *ignore)
+{
+	struct subscriber *sub;
+	const char *name = ast_event_get_ie_str(event, AST_EVENT_IE_USERNAME);
+	int fd = ast_event_get_ie_uint(event, AST_EVENT_IE_FD);
+	
+	if (sub = remove_subscriber(name, fd)) {
+		sub->stop = 1;
+		pthread_join(sub->thread, NULL);
+	}
 }
 
 static int unload_module(void)




More information about the asterisk-commits mailing list