[asterisk-commits] dvossel: branch dvossel/awesomehooks r287553 - in /team/dvossel/awesomehooks:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 20 10:40:22 CDT 2010


Author: dvossel
Date: Mon Sep 20 10:40:18 2010
New Revision: 287553

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=287553
Log:
takes care of initial reviewboard comments

Modified:
    team/dvossel/awesomehooks/funcs/func_frame_trace.c
    team/dvossel/awesomehooks/include/asterisk/channel.h
    team/dvossel/awesomehooks/include/asterisk/framehook.h
    team/dvossel/awesomehooks/main/channel.c
    team/dvossel/awesomehooks/main/framehook.c

Modified: team/dvossel/awesomehooks/funcs/func_frame_trace.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/funcs/func_frame_trace.c?view=diff&rev=287553&r1=287552&r2=287553
==============================================================================
--- team/dvossel/awesomehooks/funcs/func_frame_trace.c (original)
+++ team/dvossel/awesomehooks/funcs/func_frame_trace.c Mon Sep 20 10:40:18 2010
@@ -200,7 +200,8 @@
 	return 0;
 }
 
-static void print_frame(struct ast_frame *frame) {
+static void print_frame(struct ast_frame *frame)
+{
 	switch (frame->frametype) {
 	case AST_FRAME_DTMF_END:
 		ast_verbose("FrameType: DTMF END\n");
@@ -308,7 +309,7 @@
 			ast_verbose("SubClass: AOC\n");
 		break;
 		default:
-			ast_verbose("SubClass: Unknown\n");
+			ast_verbose("SubClass: Unknown %d\n", frame->subclass.integer);
 		}
 		ast_verbose("Bytes: %d\n", frame->datalen);
 		break;

Modified: team/dvossel/awesomehooks/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/include/asterisk/channel.h?view=diff&rev=287553&r1=287552&r2=287553
==============================================================================
--- team/dvossel/awesomehooks/include/asterisk/channel.h (original)
+++ team/dvossel/awesomehooks/include/asterisk/channel.h Mon Sep 20 10:40:18 2010
@@ -753,7 +753,7 @@
 	struct ast_trans_pvt *writetrans;		/*!< Write translation path */
 	struct ast_trans_pvt *readtrans;		/*!< Read translation path */
 	struct ast_audiohook_list *audiohooks;
-	struct ast_framehook_list framehooks;
+	struct ast_framehook_list *framehooks;
 	struct ast_cdr *cdr;				/*!< Call Detail Record */
 	struct ast_tone_zone *zone;			/*!< Tone zone as set in indications.conf or
 							 *   in the CHANNEL dialplan function */

Modified: team/dvossel/awesomehooks/include/asterisk/framehook.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/include/asterisk/framehook.h?view=diff&rev=287553&r1=287552&r2=287553
==============================================================================
--- team/dvossel/awesomehooks/include/asterisk/framehook.h (original)
+++ team/dvossel/awesomehooks/include/asterisk/framehook.h Mon Sep 20 10:40:18 2010
@@ -141,14 +141,11 @@
 #include "asterisk/frame.h"
 
 struct ast_framehook;
-
-struct ast_framehook_list {
-	unsigned int id_count;
-	AST_LIST_HEAD_NOLOCK(, ast_framehook) list;
-};
+struct ast_framehook_list;
 
 /*!
  * \brief These are the types of events that the framehook's event callback can receive
+ * \since 1.8
  */
 enum ast_framehook_event {
 	AST_FRAMEHOOK_EVENT_READ, /*!< frame is intercepted in the read direction on the channel. */
@@ -159,6 +156,7 @@
 
 /*!
  * \brief This callback is called every time an event occurs on the framehook.
+ * \since 1.8
  *
  * \details Two events are guaranteed to occur once the ast_framehook_attach()
  * function is called. These events are AST_FRAMEHOOK_EVENT_ATTACHED, which occurs
@@ -190,6 +188,7 @@
 
 /*!
  * \brief This callback is called immediately before the framehook is destroyed.
+ * \since 1.8
  * \note  This function should be used to clean up any pointers pointing to the
  * framehook structure as the framehook will be freed immediately afterwards.
  *
@@ -217,11 +216,12 @@
 
 /*!
  * \brief Attach an framehook onto a channel for frame interception.
+ * \since 1.8
  *
  * \param ast_channel, The channel to attach the hook on to.
  * \param framehook interface, The framehook's callback functions and stored data.
 *
- * \note XXX The Channel must be locked during this function all.
+ * \pre XXX The Channel must be locked during this function all.
  *
  * \note The data pointer is never touched by the framehook API except to
  * provide it during the event and destruction callbacks.  It is entirely up to the
@@ -234,8 +234,9 @@
 
 /*!
  * \brief Detach an framehook from a channel.
+ * \since 1.8
  * 
- * \note XXX The Channel must be locked during this function all.
+ * \pre XXX The Channel must be locked during this function all.
  * If this function is never called after attaching an framehook,
  * the framehook will be detached and destroyed during channel
  * destruction.
@@ -252,23 +253,25 @@
 /*!
  * \brief This is used by the channel API to detach and destroy all
  * framehooks on a channel during channel destruction.
- *
- * \note XXX The Channel must be locked during this function all.
+ * \since 1.8
+ *
+ * \pre XXX The Channel must be locked during this function all.
  * 
- * \param framehook list to destroy 
+ * \param channel containing the framehook list to destroy.
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_framehook_list_destroy(struct ast_framehook_list *framehooks);
+int ast_framehook_list_destroy(struct ast_channel *chan);
 
 /*!
  * \brief This is used by the channel API push a frame read event to a channel's framehook list.
+ * \since 1.8
  *
  * \details After this function completes, the resulting frame that is returned could be anything,
  * even NULL.  There is nothing to keep up with after this function. If the frame is modified, the
  * framehook callback is in charge of any memory management associated with that modification.
  *
- * \note XXX The Channel must be locked during this function all.
+ * \pre XXX The Channel must be locked during this function all.
  *
  * \param framehook list to push event to.
  * \param frame being pushed to the framehook list.
@@ -279,12 +282,13 @@
 
 /*!
  * \brief This is used by the channel API push a frame write event to a channel's framehook list.
+ * \since 1.8
  *
  * \details After this function completes, the resulting frame that is returned could be anything,
  * even NULL.  There is nothing to keep up with after this function. If the frame is modified, the
  * framehook callback is in charge of any memory management associated with that modification.
  *
- * \note XXX The Channel must be locked during this function all.
+ * \pre XXX The Channel must be locked during this function all.
  *
  * \param framehook list to push event to.
  * \param frame being pushed to the framehook list.
@@ -295,8 +299,8 @@
 
 /*!
  * \brief Determine if an framehook list is empty or not
- *
- * \note XXX The Channel must be locked during this function all.
+ * \since 1.8
+ * \pre XXX The Channel must be locked during this function all.
  *
  * \param the framehook list
  * \retval 0, not empty

Modified: team/dvossel/awesomehooks/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/main/channel.c?view=diff&rev=287553&r1=287552&r2=287553
==============================================================================
--- team/dvossel/awesomehooks/main/channel.c (original)
+++ team/dvossel/awesomehooks/main/channel.c Mon Sep 20 10:40:18 2010
@@ -2634,7 +2634,7 @@
 		chan->audiohooks = NULL;
 	}
 
-	ast_framehook_list_destroy(&chan->framehooks);
+	ast_framehook_list_destroy(chan);
 
 	ast_autoservice_stop(chan);
 
@@ -3755,7 +3755,7 @@
 
 	/* Perform the framehook read event here. After the frame enters the framehook list
 	 * there is no telling what will happen, <insert mad scientist laugh here>!!! */
-	f = ast_framehook_list_read_event(&chan->framehooks, f);
+	f = ast_framehook_list_read_event(chan->framehooks, f);
 
 	if (f) {
 		struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq);
@@ -4162,7 +4162,7 @@
 		goto indicate_cleanup;
 	}
 
-	if (!ast_framehook_list_is_empty(&chan->framehooks)) {
+	if (!ast_framehook_list_is_empty(chan->framehooks)) {
 		/* Do framehooks now, do it, go, go now */
 		struct ast_frame frame = {
 			.frametype = AST_FRAME_CONTROL,
@@ -4175,7 +4175,7 @@
 		awesome_frame = ast_frdup(&frame);
 
 		/* who knows what we will get back! the anticipation is killing me. */
-		if (!(awesome_frame = ast_framehook_list_read_event(&chan->framehooks, &frame))) {
+		if (!(awesome_frame = ast_framehook_list_read_event(chan->framehooks, &frame))) {
 			ast_channel_unlock(chan);
 			res = 0;
 			goto indicate_cleanup;
@@ -4618,7 +4618,7 @@
 
 	/* Perform the framehook write event here. After the frame enters the framehook list
 	 * there is no telling what will happen, how awesome is that!!! */
-	if (!(fr = ast_framehook_list_write_event(&chan->framehooks, fr))) {
+	if (!(fr = ast_framehook_list_write_event(chan->framehooks, fr))) {
 		res = 0;
 		goto done;
 	}

Modified: team/dvossel/awesomehooks/main/framehook.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/main/framehook.c?view=diff&rev=287553&r1=287552&r2=287553
==============================================================================
--- team/dvossel/awesomehooks/main/framehook.c (original)
+++ team/dvossel/awesomehooks/main/framehook.c Mon Sep 20 10:40:18 2010
@@ -40,7 +40,7 @@
 	struct ast_channel *chan;
 	/*! the id representing this framehook on a channel */
 	unsigned int id;
-	/* when set, this signals the read and write function to detach the hook */
+	/*! when set, this signals the read and write function to detach the hook */
 	int detach_and_destroy_me;
 	/*! Pointer to the registered event callback function. */
 	ast_framehook_event_callback event_cb;
@@ -48,6 +48,11 @@
 	ast_framehook_destroy_callback destroy_cb;
 	/*! list entry for ast_framehook_list object */
 	AST_LIST_ENTRY(ast_framehook) list;
+};
+
+struct ast_framehook_list {
+	unsigned int id_count;
+	AST_LIST_HEAD_NOLOCK(, ast_framehook) list;
 };
 
 static void framehook_detach_and_destroy(struct ast_framehook *framehook)
@@ -70,6 +75,11 @@
 static struct ast_frame *framehook_list_push_event(struct ast_framehook_list *framehooks, struct ast_frame *frame, enum ast_framehook_event event)
 {
 	struct ast_framehook *framehook;
+
+	if (!framehooks) {
+		return frame;
+	}
+
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&framehooks->list, framehook, list) {
 		if (framehook->detach_and_destroy_me) {
 			/* this guy is signaled for destruction */
@@ -95,9 +105,15 @@
 	framehook->destroy_cb = i->destroy_cb;
 	framehook->data = i->data;
 	framehook->chan = chan;
-	framehook->id = ++chan->framehooks.id_count;
 
-	AST_LIST_INSERT_TAIL(&chan->framehooks.list, framehook, list);
+	/* create the framehook list if it didn't already exist */
+	if (!chan->framehooks && !(chan->framehooks = ast_calloc(1, sizeof(*chan->framehooks)))) {
+		ast_free(framehook);
+		return -1;
+	}
+
+	framehook->id = ++chan->framehooks->id_count;
+	AST_LIST_INSERT_TAIL(&chan->framehooks->list, framehook, list);
 
 	/* Tell the event callback we're live and rocking */
 	frame = framehook->event_cb(framehook->chan, NULL, AST_FRAMEHOOK_EVENT_ATTACHED, framehook->data);
@@ -116,7 +132,11 @@
 	struct ast_framehook *framehook;
 	int res = -1;
 
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->framehooks.list, framehook, list) {
+	if (!chan->framehooks) {
+		return res;
+	}
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->framehooks->list, framehook, list) {
 		if (framehook->id == id) {
 			/* we mark for detachment rather than doing explicitly here because
 			 * it needs to be safe for this function to be called within the
@@ -132,21 +152,28 @@
 	return res;
 }
 
-int ast_framehook_list_destroy(struct ast_framehook_list *framehooks)
+int ast_framehook_list_destroy(struct ast_channel *chan)
 {
 	struct ast_framehook *framehook;
 
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&framehooks->list, framehook, list) {
+	if (!chan->framehooks) {
+		return 0;
+	}
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->framehooks->list, framehook, list) {
 		AST_LIST_REMOVE_CURRENT(list);
 		framehook_detach_and_destroy(framehook);
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
-
+	ast_free(chan->framehooks);
+	chan->framehooks = NULL;
 	return 0;
 }
 
 int ast_framehook_list_is_empty(struct ast_framehook_list *framehooks)
 {
+	if (!framehooks) {
+		return 1;
+	}
 	return AST_LIST_EMPTY(&framehooks->list) ? 1 : 0;
 }
 




More information about the asterisk-commits mailing list