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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 14 17:51:48 CDT 2010


Author: dvossel
Date: Tue Sep 14 17:51:45 2010
New Revision: 286867

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286867
Log:
awesomehook code update. includes creation of alloc and destroy functions.

Modified:
    team/dvossel/awesomehooks/include/asterisk/awesomehook.h
    team/dvossel/awesomehooks/main/awesomehook.c

Modified: team/dvossel/awesomehooks/include/asterisk/awesomehook.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/include/asterisk/awesomehook.h?view=diff&rev=286867&r1=286866&r2=286867
==============================================================================
--- team/dvossel/awesomehooks/include/asterisk/awesomehook.h (original)
+++ team/dvossel/awesomehooks/include/asterisk/awesomehook.h Tue Sep 14 17:51:45 2010
@@ -30,6 +30,7 @@
 };
 
 enum ast_awesomehook_event {
+	AST_AWESOMEHOOK_NO_EVENTS,
 	AST_AWESOMEHOOK_EVENT_READ, /*!< frame is intercepted in the read direction on the channel. */
 	AST_AWESOMEHOOK_EVENT_WRITE, /*!< frame is intercepted on the write direction on the channel. */
 	AST_AWESOMEHOOK_EVENT_ATTACHED, /*!< the awesomehook is attached and running on the channel. */
@@ -41,7 +42,7 @@
 /*!
  * \brief This callback is called every time an event occurs on the awesomehook.
  *
- * \description Two events are guaranteed to occur once the ast_awesomehook_attach()
+ * \details Two events are guaranteed to occur once the ast_awesomehook_attach()
  * function is called. These events are AST_AWESOMEHOOK_EVENT_ATTACHED, which occurs
  * immediately after the awesomehook is attached to a channel, and
  * AST_AWESOMEHOOK_EVENT_DETACHED, which occurs right after the awesomehook is 
@@ -67,7 +68,8 @@
  * \param destroy_cb is option.  This function is called immediately before the
  * awesomehook is destroyed so cleanup can occur.
  *
- * \retval pointer to allocated awesomehook on Success, NULL on failure.
+ * \retval pointer to allocated awesomehook on Success.
+ * \retval NULL on failure.
  */
 struct ast_awesomehook *ast_awesomehook_alloc(
 	ast_awesomehook_event_callback event_cb,
@@ -76,10 +78,12 @@
 /*!
  * \brief Attach an awesomehook onto a channel for frame interception.
  *
+ * \param ast_awesomehook to attach
  * \param ast_channel to attached the awesomehook onto.
- * \retval 0 success, -1 failure
+ * \retval 0 success
+ * \retval -1 failure
  */
-int ast_awesomehook_attach(struct ast_channel *chan);
+int ast_awesomehook_attach(struct ast_awesomehook *awesomehook, struct ast_channel *chan);
 
 /*!
  * \brief Mark awesomehook for channel detachment and destruction.
@@ -93,7 +97,8 @@
  * is effectively done.  It can never be re-attached to another channel.
  *
  * \param awesomehook to mark for detachment.
- * \retval 0 success, -1 failure
+ * \retval 0 success
+ * \retval -1 failure
  */
 int ast_awesomehook_signal_cleanup(struct ast_awesomehook *awesomehook);
 
@@ -110,7 +115,8 @@
  * freeing it.
  *
  * \param awesomehook to mark for detachment.
- * \retval 0 success, -1 failure
+ * \retval 0 success
+ * \retval -1 failure
  */
 int ast_awesomehook_destroy(struct ast_awesomehook *awesomehoook);
 
@@ -130,6 +136,8 @@
 
 /*!
  * \brief Return the awesomehook's custom data storage pointer.
+ *
+ * \return A pointer to the awesomehook's datastore data.
  */
 void *ast_awesomehook_get_datastore(struct ast_awesomehook *awesomehook);
 

Modified: team/dvossel/awesomehooks/main/awesomehook.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/main/awesomehook.c?view=diff&rev=286867&r1=286866&r2=286867
==============================================================================
--- team/dvossel/awesomehooks/main/awesomehook.c (original)
+++ team/dvossel/awesomehooks/main/awesomehook.c Tue Sep 14 17:51:45 2010
@@ -33,6 +33,8 @@
 #include "asterisk/awesomehook.h"
 #include "asterisk/frame.h"
 
+#define ast_awesomehook_lock(ah) ast_mutex_lock(&(ah)->lock)
+#define ast_awesomehook_unlock(ah) ast_mutex_unlock(&(ah)->lock)
 
 struct ast_awesomehook {
 	ast_mutex_t lock;
@@ -50,29 +52,49 @@
 	ast_awesomehook_destroy_callback destroy_cb;
 };
 
-struct ast_awesomehook *ast_awesomehook_alloc(
-	ast_awesomehook_event_callback event_cb,
-	ast_awesomehook_destroy_callback destroy_cb)
+static void awesomehook_update_status(struct ast_awesomehook *awesomehook, enum ast_awesomehook_status status)
 {
-
-	return NULL;
+	ast_awesomehook_lock(awesomehook);
+	awesomehook->status = status;
+	ast_awesomehook_unlock(awesomehook);
 }
 
-int ast_awesomehook_attach(struct ast_channel *chan)
+struct ast_awesomehook *ast_awesomehook_alloc(ast_awesomehook_event_callback event_cb, ast_awesomehook_destroy_callback destroy_cb)
 {
+	struct ast_awesomehook *awesomehook;
+	if (!event_cb || !(awesomehook = ast_calloc(1, sizeof(*awesomehook)))) {
+		return NULL;
+	}
+	awesomehook->event_cb = event_cb;
+	awesomehook->destroy_cb = destroy_cb;
+	awesomehook->status = AST_AWESOMEHOOK_STATUS_INIT;
+	awesomehook->last_event = AST_AWESOMEHOOK_NO_EVENTS;
+	ast_mutex_init(&awesomehook->lock);
+	return awesomehook;
+}
 
+int ast_awesomehook_attach(struct ast_awesomehook *awesomehook, struct ast_channel *chan)
+{
+//todohere attach it to the channel.
+
+	awesomehook_update_status(awesomehook, AST_AWESOMEHOOK_STATUS_ATTACHED);
 	return 0;
 }
 
 int ast_awesomehook_signal_cleanup(struct ast_awesomehook *awesomehook)
 {
-
+	awesomehook_update_status(awesomehook, AST_AWESOMEHOOK_STATUS_DETACHED);
 	return 0;
 }
 
 int ast_awesomehook_destroy(struct ast_awesomehook *awesomehook)
 {
+	ast_awesomehook_lock(awesomehook);
+	awesomehook->destroy_cb(awesomehook);
+	ast_awesomehook_unlock(awesomehook);
 
+	ast_mutex_destroy(&awesomehook->lock);
+	ast_free(awesomehook);
 	return 0;
 }
 




More information about the asterisk-commits mailing list