[asterisk-commits] dvossel: branch dvossel/awesomehooks r287381 - /team/dvossel/awesomehooks/funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 17 09:52:46 CDT 2010


Author: dvossel
Date: Fri Sep 17 09:52:42 2010
New Revision: 287381

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=287381
Log:
func_awesome_trace update.  Includes more functionality

Modified:
    team/dvossel/awesomehooks/funcs/func_awesome_trace.c

Modified: team/dvossel/awesomehooks/funcs/func_awesome_trace.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/funcs/func_awesome_trace.c?view=diff&rev=287381&r1=287380&r2=287381
==============================================================================
--- team/dvossel/awesomehooks/funcs/func_awesome_trace.c (original)
+++ team/dvossel/awesomehooks/funcs/func_awesome_trace.c Fri Sep 17 09:52:42 2010
@@ -43,7 +43,8 @@
 			<parameter name="filter list type" required="true">
 				<para>A filter can be applied to the trace to limit what frames are viewed.  This
 				filter can either be a <literal>white</literal> or <literal>black</literal> list
-				of frame types.  When the filter type is not present, all frame types will be output.
+				of frame types.  When no filter type is present, <literal>white</literal> is
+				used.  If no arguments are provided at all, all frames will be output.
 				</para>
 
 				<para>Below are the different types of frames that can be filtered.</para>
@@ -66,15 +67,55 @@
 		<description>
 			<para>Examples:</para>
 			<para>exten => 1,1,Set(AWESOME_TRACE(white)=DTMF_BEGIN,DTMF_END); view only DTMF frames. </para>
+			<para>exten => 1,1,Set(AWESOME_TRACE()=DTMF_BEGIN,DTMF_END); view only DTMF frames. </para>
 			<para>exten => 1,1,Set(AWESOME_TRACE(black)=DTMF_BEGIN,DTMF_END); view everything except DTMF frames. </para>
 		</description>
 	</function>
  ***/
 
 static void print_frame(struct ast_frame *frame);
-
-static struct ast_frame *awesome_trace_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_awesomehook_event event, void *datastore)
-{
+static struct {
+	enum ast_frame_type type;
+	const char *str;
+} frametype2str[] = {
+	{ AST_FRAME_DTMF_BEGIN,   "DTMF_BEGIN" },
+	{ AST_FRAME_DTMF_END,   "DTMF_END" },
+	{ AST_FRAME_VOICE,   "VOICE" },
+	{ AST_FRAME_VIDEO,   "VIDEO" },
+	{ AST_FRAME_CONTROL,   "CONTROL" },
+	{ AST_FRAME_NULL,   "NULL" },
+	{ AST_FRAME_IAX,   "IAX" },
+	{ AST_FRAME_TEXT,   "TEXT" },
+	{ AST_FRAME_IMAGE,   "IMAGE" },
+	{ AST_FRAME_HTML,   "HTML" },
+	{ AST_FRAME_CNG,   "CNG" },
+	{ AST_FRAME_MODEM,   "MODEM" },
+};
+
+struct awesome_trace_data {
+	int list_type; /* 0 = white, 1 = black */
+	int values[ARRAY_LEN(frametype2str)];
+};
+
+static void datastore_destroy_cb(void *data) {
+	ast_free(data);
+}
+
+static const struct ast_datastore_info awesome_trace_datastore = {
+	.type = "awesometrace",
+	.destroy = datastore_destroy_cb
+};
+
+static void hook_destroy_cb(void *awesomedata)
+{
+	ast_free(awesomedata);
+}
+
+static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_awesomehook_event event, void *datastore)
+{
+	int i;
+	int show_frame = 0;
+	struct awesome_trace_data *awesomedata = datastore;
 	if (!frame) {
 		return frame;
 	}
@@ -83,15 +124,70 @@
 		return frame;
 	}
 
-	ast_verbose("%s on Channel %s\n", event == AST_AWESOMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
-	print_frame(frame);
+	for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
+		if (frame->frametype == frametype2str[i].type) {
+			if ((awesomedata->list_type == 0) && (awesomedata->values[i])) { /* white list */
+				show_frame = 1;
+			} else if ((awesomedata->list_type == 1) && (!awesomedata->values[i])){ /* black list */
+				show_frame = 1;
+			}
+			break;
+		}
+	}
+
+	if (show_frame) {
+		ast_verbose("%s on Channel %s\n", event == AST_AWESOMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
+		print_frame(frame);
+	}
 	return frame;
 }
 
 static int awesome_trace_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
+	struct awesome_trace_data *awesomedata;
+	struct ast_datastore *datastore = NULL;
+	int i = 0;
+
+	if (!(awesomedata = ast_calloc(1, sizeof(*awesomedata)))) {
+		return 0;
+	}
+
+	if (!strcasecmp(data, "black")) {
+		awesomedata->list_type = 1;
+	}
+	for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
+		if (strcasestr(value, frametype2str[i].str)) {
+			awesomedata->values[i] = 1;
+		}
+	}
+
 	ast_channel_lock(chan);
-	ast_awesomehook_attach(chan, awesome_trace_event_cb, NULL, NULL);
+	i = ast_awesomehook_attach(chan, hook_event_cb, hook_destroy_cb, awesomedata);
+	if (i >= 0) {
+		int *id;
+		if ((datastore = ast_channel_datastore_find(chan, &awesome_trace_datastore, NULL))) {
+			id = datastore->data;
+			ast_awesomehook_detach(chan, *id);
+			ast_channel_datastore_remove(chan, datastore);
+		}
+
+		if (!(datastore = ast_datastore_alloc(&awesome_trace_datastore, NULL))) {
+			ast_awesomehook_detach(chan, i);
+			ast_channel_unlock(chan);
+			return 0;
+		}
+
+		if (!(id = ast_calloc(1, sizeof(int)))) {
+			ast_datastore_free(datastore);
+			ast_awesomehook_detach(chan, i);
+			ast_channel_unlock(chan);
+			return 0;
+		}
+
+		*id = i; /* store off the id */
+		datastore->data = id;
+		ast_channel_datastore_add(chan, datastore);
+	}
 	ast_channel_unlock(chan);
 
 	return 0;
@@ -101,6 +197,7 @@
 	switch (frame->frametype) {
 	case AST_FRAME_DTMF_END:
 		ast_verbose("FrameType: DTMF END\n");
+		ast_verbose("Digit: %d\n", frame->subclass.integer);
 		break;
 	case AST_FRAME_VOICE:
 		ast_verbose("FrameType: VOICE\n");
@@ -231,15 +328,15 @@
 		break;
 	case AST_FRAME_DTMF_BEGIN:
 		ast_verbose("FrameType: DTMF BEGIN\n");
+		ast_verbose("Digit: %d\n", frame->subclass.integer);
 		break;
 	default:
-		ast_verbose("FrameType: Unknown\n");
+		ast_verbose("FrameType: Unknown %d\n", frame->frametype);
 	}
 
 	ast_verbose("Src: %s\n", ast_strlen_zero(frame->src) ? "NOT PRESENT" : frame->src);
 	ast_verbose("\n");
 }
-
 
 static struct ast_custom_function awesome_trace_function = {
 	.name = "AWESOME_TRACE",




More information about the asterisk-commits mailing list