[svn-commits] mmichelson: branch group/manager2 r104040 - in /team/group/manager2: include/...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 22 17:10:47 CST 2008


Author: mmichelson
Date: Fri Feb 22 17:10:46 2008
New Revision: 104040

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104040
Log:
1. Offload manager subscription into a separate thread from the event dispatcher in event.c
2. Create a lookup table for queue events so it is easy to subscribe to all of them.
3. Expose the definition of ast_event_dup



Modified:
    team/group/manager2/include/asterisk/event.h
    team/group/manager2/include/asterisk/event_defs.h
    team/group/manager2/include/asterisk/manager2.h
    team/group/manager2/main/event.c
    team/group/manager2/res/res_manager2.c

Modified: team/group/manager2/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/group/manager2/include/asterisk/event.h?view=diff&rev=104040&r1=104039&r2=104040
==============================================================================
--- team/group/manager2/include/asterisk/event.h (original)
+++ team/group/manager2/include/asterisk/event.h Fri Feb 22 17:10:46 2008
@@ -478,6 +478,15 @@
  */
 void *ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator);
 
+/*!
+ * \brief make a copy of an ast_event structure
+ *
+ * \param event the event to copy
+ * 
+ * \return Returns a copy of the event allocated on the heap
+ */
+struct ast_event *ast_event_dup(const struct ast_event* event);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/group/manager2/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/group/manager2/include/asterisk/event_defs.h?view=diff&rev=104040&r1=104039&r2=104040
==============================================================================
--- team/group/manager2/include/asterisk/event_defs.h (original)
+++ team/group/manager2/include/asterisk/event_defs.h Fri Feb 22 17:10:46 2008
@@ -60,6 +60,7 @@
 	/*! Number of event types.  This should be the last event type + 1 */
 	AST_EVENT_TOTAL = 18,
 };
+
 
 /*! \brief Event Information Element types */
 enum ast_event_ie_type {

Modified: team/group/manager2/include/asterisk/manager2.h
URL: http://svn.digium.com/view/asterisk/team/group/manager2/include/asterisk/manager2.h?view=diff&rev=104040&r1=104039&r2=104040
==============================================================================
--- team/group/manager2/include/asterisk/manager2.h (original)
+++ team/group/manager2/include/asterisk/manager2.h Fri Feb 22 17:10:46 2008
@@ -1,3 +1,6 @@
+#ifndef MANAGER2H
+#define MANAGER2H
+
 enum ast_event_info_ie_type {
 
 /* app_queue informational IE's */
@@ -84,3 +87,5 @@
 	{AST_EVENT_IE_INFO_QUEUE_RINGTIME,				AST_EVENT_IE_PLTYPE_UINT,	"RingTime"},
 	{AST_EVENT_IE_INFO_QUEUE_DESTINATION_UNIQUEID,	AST_EVENT_IE_PLTYPE_STR,	"DestinationUniqueID"},
 };
+
+#endif

Modified: team/group/manager2/main/event.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/main/event.c?view=diff&rev=104040&r1=104039&r2=104040
==============================================================================
--- team/group/manager2/main/event.c (original)
+++ team/group/manager2/main/event.c Fri Feb 22 17:10:46 2008
@@ -530,7 +530,7 @@
 	ast_free(event_ref);
 }
 
-static struct ast_event *ast_event_dup(const struct ast_event *event)
+struct ast_event *ast_event_dup(const struct ast_event *event)
 {
 	struct ast_event *dup_event;
 	uint16_t event_len;

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=104040&r1=104039&r2=104040
==============================================================================
--- team/group/manager2/res/res_manager2.c (original)
+++ team/group/manager2/res/res_manager2.c Fri Feb 22 17:10:46 2008
@@ -2,42 +2,128 @@
 #include "asterisk/module.h"
 #include "asterisk/event.h"
 #include "asterisk/manager2.h"
+#include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
 
-struct ast_event_sub *manager_sub;
+struct event_map {
+	const enum ast_event_type type;
+	const char *name;
+} queue_map [] = { /*Queue events*/
+	{AST_EVENT_QUEUE_MEMBER_STATUS, "QueueMemberStatus"},
+	{AST_EVENT_QUEUE_JOIN, "QueueJoin"},
+	{AST_EVENT_QUEUE_LEAVE, "QueueLeave"},
+	{AST_EVENT_QUEUE_MEMBER_CALLED, "QueueMemberCalled"},
+	{AST_EVENT_QUEUE_CALLER_ABANDON, "QueueCallerAbandon"},
+	{AST_EVENT_QUEUE_MEMBER_COMPLETE, "QueueMemberComplete"},
+	{AST_EVENT_QUEUE_MEMBER_DUMP, "QueueMemberDump"},
+	{AST_EVENT_QUEUE_MEMBER_CONNECT, "QueueMemberConnect"},
+	{AST_EVENT_QUEUE_MEMBER_REMOVED, "QueueMemberRemoved"},
+	{AST_EVENT_QUEUE_MEMBER_ADDED, "QueueMemberAdded"},
+	{AST_EVENT_QUEUE_MEMBER_PAUSED, "QueueMemberPaused"},
+	{AST_EVENT_QUEUE_MEMBER_PENALTY, "QueueMemberPenalty"},
+};
+
+struct info_event {
+	AST_LIST_ENTRY(info_event) list;
+	struct ast_event *event;
+};
+
+static struct {
+	pthread_t thread;
+	ast_cond_t cond;
+	ast_mutex_t lock;
+	AST_LIST_HEAD_NOLOCK(, info_event) info_events;
+} info_thread = {
+	.thread = AST_PTHREADT_NULL,
+};
+
+
+AST_LIST_HEAD_STATIC(info_events, info_event);
+
+#define QUEUE_EVENT_BEGIN AST_EVENT_QUEUE_MEMBER_STATUS
+/*Right now size this as the number of event types which exist
+ * Will probably modify this later
+ */
+struct ast_event_sub *manager_sub[AST_EVENT_TOTAL];
+
+/*! \brief Take our event and put it into our own queue
+ * to ease the load of the main event queue
+ *
+ * \param[in] event the event we have subscribed to
+ * \param[in] ignore unused parameter
+ */
+static void info_cb(const struct ast_event *event, void *ignore)
+{
+	struct info_event *new_event = ast_calloc(1, sizeof(*new_event));
+	if (!new_event)
+		/* OH CRAP! */
+		return;
+
+	if(!(new_event->event = ast_event_dup(event)))
+		/* OH CRAP! */
+		return;
+
+	ast_mutex_lock(&info_thread.lock);
+	AST_LIST_INSERT_TAIL(&info_thread.info_events, new_event, list); 
+	ast_cond_signal(&info_thread.cond);
+	ast_mutex_unlock(&info_thread.lock);
+}
 
 /*! \brief The handler for manager subscriptions
  * In its rudimentary stage here, all this does is iterate
  * through the IEs in the event and print them as debug messages
- *
- * \param event the event we have subscribed to
- * \param ignore unused parameter, I suspect it will one day become a filter pointer
  */
-static void info_cb(const struct ast_event *event, void *ignore)
+static void *event_spitter(void *thisvariableissoimportantiamafraidtoactuallyuseit)
 {
-	struct ast_event_iterator iter;
-	int res = 0;
+	for (;;) {
+		struct ast_event_iterator iter;
+		int res = 0;
+		struct info_event *event = NULL;
+		ast_mutex_lock(&info_thread.lock);
+		if (!(event = AST_LIST_REMOVE_HEAD(&info_thread.info_events, list))) {
+			ast_cond_wait(&info_thread.cond, &info_thread.lock);
+			event = AST_LIST_REMOVE_HEAD(&info_thread.info_events, list);
+		}
+		ast_mutex_unlock(&info_thread.lock);
 
-	for(ast_event_iterator_init(&iter, event); !res; res = ast_event_iterator_next(&iter)) {
-		enum ast_event_ie_type ie_type = ast_event_iterator_get_ie_type(&iter);
-		if (ie_type == AST_EVENT_IE_END)
-			break;
-		if (info_map[ie_type].pltype == AST_EVENT_IE_PLTYPE_STR)
-			ast_log(LOG_DEBUG, "%s: %s\r\n", info_map[ie_type].name, ast_event_iterator_get_ie_str(&iter));
-		else if (info_map[ie_type].pltype == AST_EVENT_IE_PLTYPE_UINT)
-			ast_log(LOG_DEBUG, "%s: %u\r\n", info_map[ie_type].name, ast_event_iterator_get_ie_uint(&iter));
+		ast_log(LOG_DEBUG, "NEW EVENT: %s\n", queue_map[ast_event_get_type(event->event) - QUEUE_EVENT_BEGIN].name);
+
+		for (ast_event_iterator_init(&iter, event->event); !res; res = ast_event_iterator_next(&iter)) {
+			enum ast_event_ie_type ie_type = ast_event_iterator_get_ie_type(&iter);
+			if (ie_type == AST_EVENT_IE_END)
+				break;
+			if (info_map[ie_type].pltype == AST_EVENT_IE_PLTYPE_STR)
+				ast_log(LOG_DEBUG, "%s: %s\r\n", info_map[ie_type].name, ast_event_iterator_get_ie_str(&iter));
+			else if (info_map[ie_type].pltype == AST_EVENT_IE_PLTYPE_UINT)
+				ast_log(LOG_DEBUG, "%s: %u\r\n", info_map[ie_type].name, ast_event_iterator_get_ie_uint(&iter));
+		}
+		printf("\r\n");
+		fflush(stdout);
+		ast_event_destroy(event->event);
+		ast_free(event);
+		event = NULL;
 	}
+
+	return NULL;
 }
 
 static int unload_module(void)
 {
-	if (manager_sub)
-		ast_event_unsubscribe(manager_sub);
+	int i;
+	for (i = 0; manager_sub[i]; i++)
+		ast_event_unsubscribe(manager_sub[i]);
 	return 0;
 }
 
 static int load_module(void)
 {
-	manager_sub = ast_event_subscribe(AST_EVENT_INFO, info_cb, NULL, AST_EVENT_IE_END);
+	int i;
+	for (i = 0; i < (sizeof(queue_map) / sizeof(queue_map[0])); i++) {
+		manager_sub[i] = ast_event_subscribe(queue_map[i].type, info_cb, NULL, AST_EVENT_IE_END);
+	}
+	ast_mutex_init(&info_thread.lock);
+	ast_cond_init(&info_thread.cond, NULL);
+	ast_pthread_create_background(&info_thread.thread, NULL, event_spitter, NULL);
 	return AST_MODULE_LOAD_SUCCESS; 
 }
 




More information about the svn-commits mailing list