[asterisk-commits] dvossel: branch dvossel/awesomehooks r286899 - in /team/dvossel/awesomehooks:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 15 11:27:40 CDT 2010
Author: dvossel
Date: Wed Sep 15 11:27:36 2010
New Revision: 286899
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286899
Log:
awesomehook branch update. includes channel attach and detach functions
Modified:
team/dvossel/awesomehooks/include/asterisk/awesomehook.h
team/dvossel/awesomehooks/include/asterisk/channel.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=286899&r1=286898&r2=286899
==============================================================================
--- team/dvossel/awesomehooks/include/asterisk/awesomehook.h (original)
+++ team/dvossel/awesomehooks/include/asterisk/awesomehook.h Wed Sep 15 11:27:36 2010
@@ -22,6 +22,13 @@
#ifndef _AST_AWESOMEHOOK_H_
#define _AST_AWESOMEHOOK_H_
+#include "asterisk/linkedlists.h"
+#include "asterisk/frame.h"
+#include "asterisk/channel.h"
+
+struct ast_awesomehook_list {
+ AST_LIST_HEAD_NOLOCK(, ast_awesomehook) list;
+};
enum ast_awesomehook_status {
AST_AWESOMEHOOK_STATUS_INIT,
@@ -95,30 +102,27 @@
*
* \note After this function is used on a awesomehook, that awesomehook
* is effectively done. It can never be re-attached to another channel.
+ * The applications using the awesomehook will be still be notified via
+ * the destroy_cb function once the actual destruction takes place.
*
* \param awesomehook to mark for detachment.
* \retval 0 success
* \retval -1 failure
*/
-int ast_awesomehook_signal_cleanup(struct ast_awesomehook *awesomehook);
+int ast_awesomehook_signal_destroy(struct ast_awesomehook *awesomehook);
/*!
- * \brief free an awesomehook structure
+ * \brief This is used by the channel API to detach and destroy all
+ * awesomehooks on a channel during channel destruction.
*
* \note XXX READ THIS! This function should only be used by the
- * Channel API after a awesomehook is detached from a channel. Any
- * application using awesomehooks on a channel should use the
- * ast_awesomehook_signal_cleanup() function to remove and free the
- * awesomehook.
+ * Channel API. Do not call this outside the channel API.
*
- * \note This function invokes the awesomehook's destruction callback before
- * freeing it.
- *
- * \param awesomehook to mark for detachment.
+ * \param awesomehook list to destroy
* \retval 0 success
* \retval -1 failure
*/
-int ast_awesomehook_destroy(struct ast_awesomehook *awesomehoook);
+int ast_awesomehook_list_destroy(struct ast_awesomehook_list *awesomehooks);
/*!
* \brief Return the status of an awesomehook.
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=286899&r1=286898&r2=286899
==============================================================================
--- team/dvossel/awesomehooks/include/asterisk/channel.h (original)
+++ team/dvossel/awesomehooks/include/asterisk/channel.h Wed Sep 15 11:27:36 2010
@@ -151,6 +151,7 @@
#include "asterisk/data.h"
#include "asterisk/channelstate.h"
#include "asterisk/ccss.h"
+#include "asterisk/awesomehook.h"
#define DATASTORE_INHERIT_FOREVER INT_MAX
@@ -752,6 +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_awesomehook_list awesomehooks;
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/main/awesomehook.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/main/awesomehook.c?view=diff&rev=286899&r1=286898&r2=286899
==============================================================================
--- team/dvossel/awesomehooks/main/awesomehook.c (original)
+++ team/dvossel/awesomehooks/main/awesomehook.c Wed Sep 15 11:27:36 2010
@@ -45,18 +45,34 @@
/*! This pointer holds any stateful data an application wishes to store. */
void *datastore;
/*! This pointer to ast_channel the awesomehook is attached to. */
- struct ast_channel chan;
+ struct ast_channel *chan;
/*! Pointer to the registered event callback function. */
ast_awesomehook_event_callback event_cb;
/*! Pointer to the registered destruction callback function. */
ast_awesomehook_destroy_callback destroy_cb;
+ /*! list entry for ast_awesomehook_list object */
+ AST_LIST_ENTRY(ast_awesomehook) list;
};
static void awesomehook_update_status(struct ast_awesomehook *awesomehook, enum ast_awesomehook_status status)
{
+ /* once the status is set as DETACHED, it is forever detached and ready for destruction */
+ if (awesomehook->status == AST_AWESOMEHOOK_STATUS_DETACHED) {
+ return;
+ }
ast_awesomehook_lock(awesomehook);
awesomehook->status = status;
ast_awesomehook_unlock(awesomehook);
+}
+
+static int awesomehook_destroy(struct ast_awesomehook *awesomehook)
+{
+ if (awesomehook->destroy_cb) {
+ awesomehook->destroy_cb(awesomehook);
+ }
+ ast_mutex_destroy(&awesomehook->lock);
+ ast_free(awesomehook);
+ return 0;
}
struct ast_awesomehook *ast_awesomehook_alloc(ast_awesomehook_event_callback event_cb, ast_awesomehook_destroy_callback destroy_cb)
@@ -75,43 +91,54 @@
int ast_awesomehook_attach(struct ast_awesomehook *awesomehook, struct ast_channel *chan)
{
-//todohere attach it to the channel.
+ ast_channel_lock(chan);
+ AST_LIST_INSERT_TAIL(&chan->awesomehooks.list, awesomehook, list);
+ awesomehook->chan = chan;
+ ast_channel_unlock(chan);
awesomehook_update_status(awesomehook, AST_AWESOMEHOOK_STATUS_ATTACHED);
+
+ /* tell the event callback we're live and rocking */
+ awesomehook->event_cb(awesomehook, awesomehook->chan, NULL, AST_AWESOMEHOOK_EVENT_ATTACHED);
+
return 0;
}
-int ast_awesomehook_signal_cleanup(struct ast_awesomehook *awesomehook)
+int ast_awesomehook_signal_destroy(struct ast_awesomehook *awesomehook)
{
+ /* This signals to the channel to detach and destroy the hook on the next read or write */
awesomehook_update_status(awesomehook, AST_AWESOMEHOOK_STATUS_DETACHED);
return 0;
}
-int ast_awesomehook_destroy(struct ast_awesomehook *awesomehook)
+int ast_awesomehook_list_destroy(struct ast_awesomehook_list *awesomehooks)
{
- ast_awesomehook_lock(awesomehook);
- awesomehook->destroy_cb(awesomehook);
- ast_awesomehook_unlock(awesomehook);
+ struct ast_awesomehook *awesomehook;
- ast_mutex_destroy(&awesomehook->lock);
- ast_free(awesomehook);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&awesomehooks->list, awesomehook, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ awesomehook_update_status(awesomehook, AST_AWESOMEHOOK_STATUS_DETACHED);
+ awesomehook->event_cb(awesomehook, awesomehook->chan, NULL, AST_AWESOMEHOOK_EVENT_DETACHED);
+ awesomehook->chan = NULL;
+ awesomehook_destroy(awesomehook);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
return 0;
}
enum ast_awesomehook_status ast_awesomehook_get_status(struct ast_awesomehook *awesomehook)
{
-
- return 0;
+ return awesomehook->status;
}
int ast_awesomehook_set_datastore(struct ast_awesomehook *awesomehook, void *data)
{
-
+ awesomehook->datastore = data;
return 0;
}
void *ast_awesomehook_get_datastore(struct ast_awesomehook *awesomehook)
{
-
- return NULL;
+ return awesomehook->datastore;
}
More information about the asterisk-commits
mailing list