[asterisk-commits] mmichelson: branch group/manager2 r104032 - in /team/group/manager2: apps/ in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 21 19:07:04 CST 2008


Author: mmichelson
Date: Thu Feb 21 19:07:04 2008
New Revision: 104032

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104032
Log:
1. convert the rest of app_queue's manager events to use the event API
2. Instead of using just an "info" type event for all queue events, explicitly define
   each one as its own event type.
3. Changed the event types to be defined in decimal instead of hex as a means of preventing
   potential errors when defining event types.

Right now this doesn't compile because res_manager2.c still assumes there's an AST_EVENT_INFO type.
I need to code a graceful way for it to subscribe to a large amount of event types.


Modified:
    team/group/manager2/apps/app_queue.c
    team/group/manager2/include/asterisk/event_defs.h

Modified: team/group/manager2/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/apps/app_queue.c?view=diff&rev=104032&r1=104031&r2=104032
==============================================================================
--- team/group/manager2/apps/app_queue.c (original)
+++ team/group/manager2/apps/app_queue.c Thu Feb 21 19:07:04 2008
@@ -730,7 +730,7 @@
 					continue;
 				}
 
-				event = ast_event_new(AST_EVENT_INFO,
+				event = ast_event_new(AST_EVENT_QUEUE_MEMBER_STATUS,
 						AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
 						AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, cur->interface,
 						AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, cur->membername,
@@ -1696,7 +1696,7 @@
 		q->count++;
 		res = 0;
 
-		event = ast_event_new(AST_EVENT_INFO,
+		event = ast_event_new(AST_EVENT_QUEUE_JOIN,
 				AST_EVENT_IE_INFO_QUEUE_SOURCE_CHANNEL, AST_EVENT_IE_PLTYPE_STR, qe->chan->name,
 				AST_EVENT_IE_INFO_QUEUE_CALLERIDNUM, AST_EVENT_IE_PLTYPE_STR, qe->chan->cid.cid_num,
 				AST_EVENT_IE_INFO_QUEUE_CALLERIDNAME, AST_EVENT_IE_PLTYPE_STR, qe->chan->cid.cid_name,
@@ -1916,7 +1916,7 @@
 		if (cur == qe) {
 			q->count--;
 
-			event = ast_event_new(AST_EVENT_INFO,
+			event = ast_event_new(AST_EVENT_QUEUE_LEAVE,
 					AST_EVENT_IE_INFO_QUEUE_SOURCE_CHANNEL, AST_EVENT_IE_PLTYPE_STR, qe->chan->name,
 					AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
 					AST_EVENT_IE_INFO_QUEUE_COUNT, AST_EVENT_IE_PLTYPE_UINT, q->count,
@@ -1998,7 +1998,7 @@
 
 		cur->status = status;
 		if (!q->maskmemberstatus) {
-			event = ast_event_new(AST_EVENT_INFO,
+			event = ast_event_new(AST_EVENT_QUEUE_MEMBER_STATUS,
 					AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
 					AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, cur->interface,
 					AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, cur->membername,
@@ -2090,7 +2090,8 @@
 	ast_hangup(o->chan);
 	o->chan = NULL;
 }
-
+/*temporarily comment this out since we're not using it but may need it for later */
+#if 0
 static char *vars2manager(struct ast_channel *chan, char *vars, size_t len)
 {
 	struct ast_str *buf = ast_str_alloca(len + 1);
@@ -2127,7 +2128,7 @@
 	}
 	return vars;
 }
-
+#endif
 /*! \brief Part 2 of ring_one
  *
  * Does error checking before attempting to request a channel and call a member. This
@@ -2242,7 +2243,7 @@
 		/*char vars[2048];*/
 		struct ast_event *event = NULL;
 
-		event = ast_event_new(AST_EVENT_INFO,
+		event = ast_event_new(AST_EVENT_QUEUE_MEMBER_CALLED,
 				AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, qe->parent->name,
 				AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, tmp->interface,
 				AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, tmp->member->membername,
@@ -2436,8 +2437,21 @@
 
 static void record_abandoned(struct queue_ent *qe)
 {
+	struct ast_event *event = NULL;
 	ao2_lock(qe->parent);
 	set_queue_variables(qe);
+	
+	event = ast_event_new(AST_EVENT_QUEUE_CALLER_ABANDON,
+			AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, qe->parent->name,
+			AST_EVENT_IE_INFO_QUEUE_SOURCE_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, qe->chan->uniqueid,
+			AST_EVENT_IE_INFO_QUEUE_POSITION, AST_EVENT_IE_PLTYPE_UINT, qe->pos,
+			AST_EVENT_IE_INFO_QUEUE_ORIGINAL_POSITION, AST_EVENT_IE_PLTYPE_UINT, qe->opos,
+			AST_EVENT_IE_INFO_QUEUE_HOLDTIME, AST_EVENT_IE_PLTYPE_UINT, (time(NULL) - qe->start),
+			AST_EVENT_IE_END);
+
+	ast_event_queue(event);
+
+#if 0
 	manager_event(EVENT_FLAG_AGENT, "QueueCallerAbandon",
 		"Queue: %s\r\n"
 		"Uniqueid: %s\r\n"
@@ -2445,7 +2459,7 @@
 		"OriginalPosition: %d\r\n"
 		"HoldTime: %d\r\n",
 		qe->parent->name, qe->chan->uniqueid, qe->pos, qe->opos, (int)(time(NULL) - qe->start));
-
+#endif
 	qe->parent->callsabandoned++;
 	ao2_unlock(qe->parent);
 }
@@ -3004,6 +3018,7 @@
 	char *vars, size_t vars_len, enum agent_complete_reason rsn)
 {
 	const char *reason = NULL;	/* silence dumb compilers */
+	struct ast_event *event = NULL;
 
 	if (!qe->parent->eventwhencalled)
 		return;
@@ -3019,6 +3034,20 @@
 		reason = "transfer";
 		break;
 	}
+
+	event = ast_event_new(AST_EVENT_QUEUE_MEMBER_COMPLETE,
+			AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, queuename,
+			AST_EVENT_IE_INFO_QUEUE_SOURCE_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, qe->chan->uniqueid,
+			AST_EVENT_IE_INFO_QUEUE_DESTINATION_CHANNEL, AST_EVENT_IE_PLTYPE_STR, peer->name,
+			AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, member->interface,
+			AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, member->membername,
+			AST_EVENT_IE_INFO_QUEUE_HOLDTIME, AST_EVENT_IE_PLTYPE_UINT, callstart - qe->start,
+			AST_EVENT_IE_INFO_QUEUE_TALKTIME, AST_EVENT_IE_PLTYPE_UINT, time(NULL) - callstart,
+			AST_EVENT_IE_INFO_QUEUE_REASON, AST_EVENT_IE_PLTYPE_STR, reason,
+			AST_EVENT_IE_END);
+
+	ast_event_queue(event);
+#if 0
 
 	manager_event(EVENT_FLAG_AGENT, "AgentComplete",
 		"Queue: %s\r\n"
@@ -3033,7 +3062,10 @@
 		queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
 		(long)(callstart - qe->start), (long)(time(NULL) - callstart), reason,
 		qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, vars_len) : "");
-}
+#endif
+
+}
+
 /*! \brief A large function which calls members, updates statistics, and bridges the caller and a member
  * 
  * Here is the process of this function
@@ -3101,6 +3133,7 @@
 	int callcompletedinsl;
 	struct ao2_iterator memi;
 	struct ast_datastore *datastore;
+	struct ast_event *event = NULL;
 
 	ast_channel_lock(qe->chan);
 	datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
@@ -3361,7 +3394,17 @@
 				ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", peer->name);
 				ast_queue_log(queuename, qe->chan->uniqueid, member->membername, "AGENTDUMP", "%s", "");
 				record_abandoned(qe);
-				if (qe->parent->eventwhencalled)
+				if (qe->parent->eventwhencalled) {
+					event = ast_event_new(AST_EVENT_QUEUE_MEMBER_DUMP,
+							AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, queuename,
+							AST_EVENT_IE_INFO_QUEUE_SOURCE_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, qe->chan->uniqueid,
+							AST_EVENT_IE_INFO_QUEUE_DESTINATION_CHANNEL, AST_EVENT_IE_PLTYPE_STR, peer->name,
+							AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, member->interface,
+							AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, member->membername,
+							AST_EVENT_IE_END);
+
+					ast_event_queue(event);
+#if 0
 					manager_event(EVENT_FLAG_AGENT, "AgentDump",
 							"Queue: %s\r\n"
 							"Uniqueid: %s\r\n"
@@ -3371,6 +3414,8 @@
 							"%s",
 							queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
 							qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : "");
+#endif
+				}
 				ast_hangup(peer);
 				ao2_ref(member, -1);
 				goto out;
@@ -3644,7 +3689,21 @@
 													(long)(orig - to > 0 ? (orig - to) / 1000 : 0));
 		if (update_cdr && qe->chan->cdr) 
 			ast_copy_string(qe->chan->cdr->dstchannel, member->membername, sizeof(qe->chan->cdr->dstchannel));
-		if (qe->parent->eventwhencalled)
+		if (qe->parent->eventwhencalled) {
+			event = ast_event_new(AST_EVENT_QUEUE_MEMBER_CONNECT,
+					AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, queuename,
+					AST_EVENT_IE_INFO_QUEUE_SOURCE_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, qe->chan->uniqueid,
+					AST_EVENT_IE_INFO_QUEUE_DESTINATION_CHANNEL, AST_EVENT_IE_PLTYPE_STR, peer->name,
+					AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, member->interface,
+					AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, member->membername,
+					AST_EVENT_IE_INFO_QUEUE_HOLDTIME, AST_EVENT_IE_PLTYPE_UINT, time(NULL) - qe->start,
+					AST_EVENT_IE_INFO_QUEUE_DESTINATION_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, peer->uniqueid,
+					AST_EVENT_IE_INFO_QUEUE_RINGTIME, AST_EVENT_IE_PLTYPE_UINT, orig - to > 0 ? (orig - to) / 1000 : 0,
+					AST_EVENT_IE_END);
+
+			ast_event_queue(event);
+
+#if 0
 			manager_event(EVENT_FLAG_AGENT, "AgentConnect",
 					"Queue: %s\r\n"
 					"Uniqueid: %s\r\n"
@@ -3658,6 +3717,8 @@
 					queuename, qe->chan->uniqueid, peer->name, member->interface, member->membername,
 					(long) time(NULL) - qe->start, peer->uniqueid, (long)(orig - to > 0 ? (orig - to) / 1000 : 0),
 					qe->parent->eventwhencalled == QUEUE_EVENT_VARIABLES ? vars2manager(qe->chan, vars, sizeof(vars)) : "");
+#endif
+		}
 		ast_copy_string(oldcontext, qe->chan->context, sizeof(oldcontext));
 		ast_copy_string(oldexten, qe->chan->exten, sizeof(oldexten));
 		time(&callstart);
@@ -3773,6 +3834,7 @@
 		.name = queuename,	
 	};
 	struct member *mem, tmpmem;
+	struct ast_event *event;
 	int res = RES_NOSUCHQUEUE;
 
 	ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
@@ -3786,11 +3848,21 @@
 				return RES_NOT_DYNAMIC;
 			}
 			q->membercount--;
+			event = ast_event_new(AST_EVENT_QUEUE_MEMBER_REMOVED,
+					AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
+					AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, mem->interface,
+					AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, mem->membername,
+					AST_EVENT_IE_END);
+
+			ast_event_queue(event);
+
+#if 0
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved",
 				"Queue: %s\r\n"
 				"Location: %s\r\n"
 				"MemberName: %s\r\n",
 				q->name, mem->interface, mem->membername);
+#endif
 			ao2_unlink(q->members, mem);
 			remove_from_interfaces(mem->state_interface);
 			ao2_ref(mem, -1);
@@ -3815,6 +3887,7 @@
 	struct call_queue *q;
 	struct member *new_member, *old_member;
 	int res = RES_NOSUCHQUEUE;
+	struct ast_event *event = NULL;
 
 	/* \note Ensure the appropriate realtime queue is loaded.  Note that this
 	 * short-circuits if the queue is already in memory. */
@@ -3830,6 +3903,17 @@
 			new_member->dynamic = 1;
 			ao2_link(q->members, new_member);
 			q->membercount++;
+			/*I'm leaving out some of the original manager event stuff because it's just stupid.*/
+			event = ast_event_new(AST_EVENT_QUEUE_MEMBER_ADDED,
+					AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
+					AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, new_member->interface,
+					AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, new_member->membername,
+					AST_EVENT_IE_INFO_QUEUE_MEMBERSHIP, AST_EVENT_IE_PLTYPE_STR, "dynamic",
+					AST_EVENT_IE_INFO_QUEUE_PENALTY, AST_EVENT_IE_PLTYPE_UINT, new_member->penalty,
+					AST_EVENT_IE_END);
+
+			ast_event_queue(event);
+#if 0
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
 				"Queue: %s\r\n"
 				"Location: %s\r\n"
@@ -3844,7 +3928,7 @@
 				"dynamic",
 				new_member->penalty, new_member->calls, (int) new_member->lastcall,
 				new_member->status, new_member->paused);
-			
+#endif		
 			ao2_ref(new_member, -1);
 			new_member = NULL;
 
@@ -3871,6 +3955,7 @@
 	struct call_queue *q;
 	struct member *mem;
 	struct ao2_iterator queue_iter;
+	struct ast_event *event = NULL;
 
 	/* Special event for when all queues are paused - individual events still generated */
 	/* XXX In all other cases, we use the membername, but since this affects all queues, we cannot */
@@ -3897,20 +3982,42 @@
 				ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), "%s", S_OR(reason, ""));
 				
 				if (!ast_strlen_zero(reason)) {
+					event = ast_event_new(AST_EVENT_QUEUE_MEMBER_PAUSED,
+							AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
+							AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, mem->interface,
+							AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, mem->membername,
+							AST_EVENT_IE_INFO_QUEUE_PAUSED, AST_EVENT_IE_PLTYPE_UINT, paused,
+							AST_EVENT_IE_INFO_QUEUE_REASON, AST_EVENT_IE_PLTYPE_STR, reason,
+							AST_EVENT_IE_END);
+
+					ast_event_queue(event);
+#if 0
 					manager_event(EVENT_FLAG_AGENT, "QueueMemberPaused",
 						"Queue: %s\r\n"
 						"Location: %s\r\n"
 						"MemberName: %s\r\n"
 						"Paused: %d\r\n"
 						"Reason: %s\r\n",
-							q->name, mem->interface, mem->membername, paused, reason);
+						q->name, mem->interface, mem->membername, paused, reason);
+#endif
+
 				} else {
+					event = ast_event_new(AST_EVENT_QUEUE_MEMBER_PAUSED,
+							AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
+							AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, mem->interface,
+							AST_EVENT_IE_INFO_QUEUE_MEMBER_NAME, AST_EVENT_IE_PLTYPE_STR, mem->membername,
+							AST_EVENT_IE_INFO_QUEUE_PAUSED, AST_EVENT_IE_PLTYPE_UINT, paused,
+							AST_EVENT_IE_END);
+
+					ast_event_queue(event);
+#if 0
 					manager_event(EVENT_FLAG_AGENT, "QueueMemberPaused",
 						"Queue: %s\r\n"
 						"Location: %s\r\n"
 						"MemberName: %s\r\n"
 						"Paused: %d\r\n",
-							q->name, mem->interface, mem->membername, paused);
+						q->name, mem->interface, mem->membername, paused);
+#endif 
 				}
 				ao2_ref(mem, -1);
 			}
@@ -3929,6 +4036,7 @@
 	struct call_queue *q;
 	struct member *mem;
 	struct ao2_iterator queue_iter;
+	struct ast_event *event = NULL;
 
 	if (penalty < 0) {
 		ast_log(LOG_ERROR, "Invalid penalty (%d)\n", penalty);
@@ -3945,12 +4053,20 @@
 				mem->penalty = penalty;
 				
 				ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty);
+				event = ast_event_new(AST_EVENT_QUEUE_MEMBER_PENALTY,
+						AST_EVENT_IE_INFO_QUEUE_NAME, AST_EVENT_IE_PLTYPE_STR, q->name,
+						AST_EVENT_IE_INFO_QUEUE_INTERFACE, AST_EVENT_IE_PLTYPE_STR, mem->interface,
+						AST_EVENT_IE_INFO_QUEUE_PENALTY, AST_EVENT_IE_PLTYPE_UINT, penalty,
+						AST_EVENT_IE_END);
+
+				ast_event_queue(event);
+#if 0
 				manager_event(EVENT_FLAG_AGENT, "QueueMemberPenalty",
 					"Queue: %s\r\n"
 					"Location: %s\r\n"
 					"Penalty: %d\r\n",
 					q->name, mem->interface, penalty);
-
+#endif
 			}
 		}
 		ao2_unlock(q);

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=104032&r1=104031&r2=104032
==============================================================================
--- team/group/manager2/include/asterisk/event_defs.h (original)
+++ team/group/manager2/include/asterisk/event_defs.h Thu Feb 21 19:07:04 2008
@@ -30,24 +30,35 @@
 enum ast_event_type {
 	/*! Reserved to provide the ability to subscribe to all events.  A specific
 	    event should never have a payload of 0. */
-	AST_EVENT_ALL    = 0x00,
+	AST_EVENT_ALL = 0,    
 	/*! This event type is reserved for use by third-party modules to create
 	    custom events without having to modify this file. 
 	    \note There are no "custom" IE types, because IEs only have to be
 	    unique to the event itself, not necessarily across all events. */
-	AST_EVENT_CUSTOM = 0x01,
+	AST_EVENT_CUSTOM = 1,
 	/*! Voicemail message waiting indication */
-	AST_EVENT_MWI          = 0x02,
+	AST_EVENT_MWI = 2,
 	/*! Someone has subscribed to events */
-	AST_EVENT_SUB          = 0x03,
+	AST_EVENT_SUB = 3,
 	/*! Someone has unsubscribed from events */
-	AST_EVENT_UNSUB        = 0x04,
+	AST_EVENT_UNSUB = 4,
 	/*! The state of a device has changed */
-	AST_EVENT_DEVICE_STATE = 0x05,
-	/*! Informational events */
-	AST_EVENT_INFO         = 0x06,
+	AST_EVENT_DEVICE_STATE = 5,
+	/*! This block of events is for queue shit */
+	AST_EVENT_QUEUE_MEMBER_STATUS = 6,
+	AST_EVENT_QUEUE_JOIN = 7,
+	AST_EVENT_QUEUE_LEAVE = 8,
+	AST_EVENT_QUEUE_MEMBER_CALLED = 9,
+	AST_EVENT_QUEUE_CALLER_ABANDON = 10,
+	AST_EVENT_QUEUE_MEMBER_COMPLETE = 11,
+	AST_EVENT_QUEUE_MEMBER_DUMP = 12,
+	AST_EVENT_QUEUE_MEMBER_CONNECT = 13,
+	AST_EVENT_QUEUE_MEMBER_REMOVED = 14,
+	AST_EVENT_QUEUE_MEMBER_ADDED = 15,
+	AST_EVENT_QUEUE_MEMBER_PAUSED = 16,
+	AST_EVENT_QUEUE_MEMBER_PENALTY = 17,
 	/*! Number of event types.  This should be the last event type + 1 */
-	AST_EVENT_TOTAL        = 0x07,
+	AST_EVENT_TOTAL = 18,
 };
 
 /*! \brief Event Information Element types */




More information about the asterisk-commits mailing list