[asterisk-commits] nadi: branch group/trunk-cm-csel-hash r47413 - /team/group/trunk-cm-csel-hash...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 10 03:32:32 MST 2006


Author: nadi
Date: Fri Nov 10 04:32:30 2006
New Revision: 47413

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47413
Log:
new advanced event logging

Modified:
    team/group/trunk-cm-csel-hash/channels/chan_misdn.c

Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?view=diff&rev=47413&r1=47412&r2=47413
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Fri Nov 10 04:32:30 2006
@@ -133,6 +133,33 @@
 	MISDN_HOLDED, 				/*!< if this chan is holded */
 	MISDN_HOLD_DISCONNECT, 		/*!< if this chan is holded */
 	MISDN_FIXUP 				/*!< if this chan is holded */
+};
+
+enum event_log_elements {
+	L_CHANNEL     = 1 << 0,
+	L_OAD         = 1 << 1,
+	L_DAD         = 1 << 2,
+	L_CAD         = 1 << 3,
+	L_RAD         = 1 << 4,
+	L_PID         = 1 << 5,
+	L_MODE        = 1 << 6,
+	L_CAUSE       = 1 << 7,
+	L_OCAUSE      = 1 << 8,
+	L_DNUMPLAN    = 1 << 9,
+	L_RNUMPLAN    = 1 << 10,
+	L_CPNNUMPLAN  = 1 << 11,
+	L_INFODAD     = 1 << 12,
+	L_PRES        = 1 << 13,
+	L_SCREEN      = 1 << 14,
+	L_STATE       = 1 << 15,
+	L_BCSTATE     = 1 << 16,
+	L_CONTEXT     = 1 << 17,
+};
+
+struct event_log_info {
+	char *name;
+	enum event_log_elements elements;
+	enum event_log_elements additional;
 };
 
 struct chan_list {
@@ -619,7 +646,7 @@
 		level = -1;
 	}
 
-	sprintf(port_buf, "P[%2d] ", port);
+	sprintf(port_buf, "P(%2d) ", port);
 
 	va_start(ap, tmpl);
 	vsnprintf(buf, sizeof(buf) - 1, tmpl, ap);
@@ -825,79 +852,79 @@
 	{ STATE_ANY,                  EVENT_STATUS,               STATE_KEEP,                  EVENT_NONE,                  NULL},
 };
 
-static const char * event2str (int event)
-{
-	static char *mevents[] = {
-		"NOTHING",
-		"TONE_GENERATE",
-		"BCHAN_DATA",
-		"BCHAN_ACTIVATED",
-		"BCHAN_ERROR",
-		"CLEANUP",
-		"PROCEEDING",
-		"PROGRESS",
-		"SETUP",
-		"ALERTING",
-		"CONNECT",
-		"SETUP_ACKNOWLEDGE",
-		"CONNECT_ACKNOWLEDGE ",
-		"USER_INFORMATION",
-		"SUSPEND_REJECT",
-		"RESUME_REJECT",
-		"HOLD",
-		"SUSPEND",
-		"RESUME",
-		"HOLD_ACKNOWLEDGE",
-		"SUSPEND_ACKNOWLEDGE",
-		"RESUME_ACKNOWLEDGE",
-		"HOLD_REJECT",
-		"RETRIEVE",
-		"RETRIEVE_ACKNOWLEDGE",
-		"RETRIEVE_REJECT",
-		"DISCONNECT",
-		"RESTART",
-		"RELEASE",
-		"RELEASE_COMPLETE",
-		"FACILITY",
-		"NOTIFY",
-		"STATUS_ENQUIRY",
-		"INFORMATION",
-		"STATUS",
-		"TIMEOUT",
-		"DTMF_TONE",
-		"NEW_L3ID",
-		"NEW_BC",
-		"PORT_ALARM",
-		"NEW_CHANNEL",
-		"UNKNOWN"
+static const struct event_log_info * geteventinfo (int event)
+{
+	static struct event_log_info mevents[] = {
+		{ "NOTHING", L_PID, 0 },
+		{ "TONE_GENERATE", L_PID, 0 },
+		{ "BCHAN_DATA", L_PID, 0 },
+		{ "BCHAN_ACTIVATED", L_PID, 0 },
+		{ "BCHAN_ERROR", L_PID, 0 },
+		{ "CLEANUP", L_PID, 0 },
+		{ "PROCEEDING", L_PID, 0 },
+		{ "PROGRESS", L_PID, 0 },
+		{ "SETUP", L_PID | L_MODE | L_CHANNEL, L_SCREEN | L_CONTEXT },
+		{ "ALERTING", L_PID, 0 },
+		{ "CONNECT", L_PID, 0 },
+		{ "SETUP_ACKNOWLEDGE", L_PID, 0 },
+		{ "CONNECT_ACKNOWLEDGE ", L_PID, 0 },
+		{ "USER_INFORMATION", L_PID, 0 },
+		{ "SUSPEND_REJECT", L_PID, 0 },
+		{ "RESUME_REJECT", L_PID, 0 },
+		{ "HOLD", L_PID, 0 },
+		{ "SUSPEND", L_PID, 0 },
+		{ "RESUME", L_PID, 0 },
+		{ "HOLD_ACKNOWLEDGE", L_PID, 0 },
+		{ "SUSPEND_ACKNOWLEDGE", L_PID, 0 },
+		{ "RESUME_ACKNOWLEDGE", L_PID, 0 },
+		{ "HOLD_REJECT", L_PID, 0 },
+		{ "RETRIEVE", L_PID, 0 },
+		{ "RETRIEVE_ACKNOWLEDGE", L_PID, 0 },
+		{ "RETRIEVE_REJECT", L_PID, 0 },
+		{ "DISCONNECT", L_PID, 0 },
+		{ "RESTART", L_PID, 0 },
+		{ "RELEASE", L_PID, 0 },
+		{ "RELEASE_COMPLETE", L_PID, 0 },
+		{ "FACILITY", L_PID, 0 },
+		{ "NOTIFY", L_PID, 0 },
+		{ "STATUS_ENQUIRY", L_PID, 0 },
+		{ "INFORMATION", L_PID, 0 },
+		{ "STATUS", L_PID, 0 },
+		{ "TIMEOUT", L_PID, 0 },
+		{ "DTMF_TONE", L_PID, 0 },
+		{ "NEW_L3ID", L_PID, 0 },
+		{ "NEW_BC", L_PID, 0 },
+		{ "PORT_ALARM", L_PID, 0 },
+		{ "NEW_CHANNEL", L_PID, 0 },
+		{ "UNKNOWN", L_PID, 0 },
 	};
 
-	static char *aevents[] = {
-		"NOTHING",
-		"CALL",
-		"HANGUP",
-		"ANSWER",
-		"CONTROL_BUSY",
-		"CONTROL_RING",
-		"CONTROL_RINGING",
-		"CONTROL_ANSWER",
-		"CONTROL_TAKEOFFHOOK",
-		"CONTROL_OFFHOOK",
-		"CONTROL_FLASH",
-		"CONTROL_PROGRESS",
-		"CONTROL_PROCEEDING",
-		"CONTROL_CONGESTION",
-		"CONTROL_HOLD",
-		"CONTROL_UNHOLD",
-		"UNKNOWN",
+	static struct event_log_info aevents[] = {
+		{ "NOTHING", L_PID, 0 },
+		{ "CALL", L_PID, 0 },
+		{ "HANGUP", L_PID, 0 },
+		{ "ANSWER", L_PID, 0 },
+		{ "CONTROL_BUSY", L_PID, 0 },
+		{ "CONTROL_RING", L_PID, 0 },
+		{ "CONTROL_RINGING", L_PID, 0 },
+		{ "CONTROL_ANSWER", L_PID, 0 },
+		{ "CONTROL_TAKEOFFHOOK", L_PID, 0 },
+		{ "CONTROL_OFFHOOK", L_PID, 0 },
+		{ "CONTROL_FLASH", L_PID, 0 },
+		{ "CONTROL_PROGRESS", L_PID, 0 },
+		{ "CONTROL_PROCEEDING", L_PID, 0 },
+		{ "CONTROL_CONGESTION", L_PID, 0 },
+		{ "CONTROL_HOLD", L_PID, 0 },
+		{ "CONTROL_UNHOLD", L_PID, 0 },
+		{ "UNKNOWN", L_PID, 0 },
 	};
 
 	if (event >= EVENT_NOTHING && event <= EVENT_UNKNOWN)
-		return mevents[event];
+		return &mevents[event];
 	else if (event >= AEVENT_NOTHING && event <= AEVENT_UNKNOWN)
-		return aevents[event - AEVENT_NOTHING];
+		return &aevents[event - AEVENT_NOTHING];
 	else
-		return mevents[EVENT_UNKNOWN];
+		return &mevents[EVENT_UNKNOWN];
 }
 
 static int send_event (void *p, int event)
@@ -930,14 +957,75 @@
 	return re;
 }
 
+#if 0
+enum event_log_elements {
+	L_CHANNEL     = 1 << 0,
+	L_OAD         = 1 << 1,
+	L_DAD         = 1 << 2,
+	L_CAD         = 1 << 3,
+	L_RAD         = 1 << 4,
+	L_PID         = 1 << 5,
+	L_MODE        = 1 << 6,
+	L_CAUSE       = 1 << 7,
+	L_OCAUSE      = 1 << 8,
+	L_DNUMPLAN    = 1 << 9,
+	L_RNUMPLAN    = 1 << 10,
+	L_CPNNUMPLAN  = 1 << 11,
+	L_INFODAD     = 1 << 12,
+	L_PRES        = 1 << 13,
+	L_SCREEN      = 1 << 14,
+	L_STATE       = 1 << 15,
+	L_BCSTATE     = 1 << 16,
+	L_CONTEXT     = 1 << 17,
+};
+#endif
+
+static inline void event_info_string (char *buf, int bufsize, struct chan_list *ch, int *elems, int num)
+{
+	int first = 0;
+	char tmpbuf[256];
+
+#define IF_INFO(i,fmt,parm) \
+	if (*elems & (i) && num) { \
+		*elems &= ~(i); \
+		--num; \
+		snprintf(tmpbuf, sizeof(tmpbuf), "%s" fmt, !(first--) ? "" : " ", parm); \
+		strncat(buf, tmpbuf, bufsize); \
+		buf[bufsize - 1] = 0; \
+	}
+
+	IF_INFO(L_CHANNEL, "ch:%d", ch->bc->channel);
+	IF_INFO(L_OAD, "oad:%s", ch->bc->oad);
+	IF_INFO(L_PID, "pid:%d", ch->bc->pid);
+	IF_INFO(L_MODE, "mode:%s", ch->bc->nt ? "nt" : "te");
+	IF_INFO(L_SCREEN, "screen:%d", ch->bc->screen);
+	IF_INFO(L_CONTEXT, "ctx:%s", ch->context);
+}
+
 static void log_event (void *p, int direction, int state, int event)
 {
 	struct chan_list *ch = p;
-
-	chan_misdn_log(1, ch->bc->port, "%c%s %s\n",
+	const struct event_log_info *info = geteventinfo(event);
+	int elems;
+	char buf[1024] = "";
+
+	elems = info->elements;
+	if (elems)
+		event_info_string(buf, sizeof(buf), ch, &elems, 7);
+	chan_misdn_log(1, ch->bc->port, "%c%s %s%s%s%s",
 				   event > EVENT_NOTHING && event < EVENT_UNKNOWN ? 'I' : '*',
 				   direction == LOG_RECEIVE ? "->" : "<-",
-				   event2str(event));
+				   info->name,
+				   info->elements ? " (" : "",
+				   info->elements ? buf : "",
+				   info->elements ? ")\n" : "\n");
+
+	elems = info->additional;
+	while (elems) {
+		*buf = 0;
+		event_info_string(buf, sizeof(buf), ch, &elems, 3);
+		chan_misdn_log(1, ch->bc->port, "      %s\n", buf);
+	}
 }
 
 /* Channel Selection */



More information about the asterisk-commits mailing list