[asterisk-commits] file: branch file/bridging r90992 - in /team/file/bridging: apps/ include/ast...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Dec 4 15:44:46 CST 2007
Author: file
Date: Tue Dec 4 15:44:45 2007
New Revision: 90992
URL: http://svn.digium.com/view/asterisk?view=rev&rev=90992
Log:
Finalize the API calls for bridge features.
Modified:
team/file/bridging/apps/app_bridgetest.c
team/file/bridging/apps/app_confbridge.c
team/file/bridging/include/asterisk/bridging.h
team/file/bridging/main/bridging.c
Modified: team/file/bridging/apps/app_bridgetest.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_bridgetest.c?view=diff&rev=90992&r1=90991&r2=90992
==============================================================================
--- team/file/bridging/apps/app_bridgetest.c (original)
+++ team/file/bridging/apps/app_bridgetest.c Tue Dec 4 15:44:45 2007
@@ -85,7 +85,7 @@
}
/* Create a new bridge to bring the two channels into */
- if (!(bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_DISSOLVE, NULL))) {
+ if (!(bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_DISSOLVE))) {
ast_log(LOG_WARNING, "Failed to create bridge ;(\n");
ast_dial_destroy(dial);
return -1;
Modified: team/file/bridging/apps/app_confbridge.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_confbridge.c?view=diff&rev=90992&r1=90991&r2=90992
==============================================================================
--- team/file/bridging/apps/app_confbridge.c (original)
+++ team/file/bridging/apps/app_confbridge.c Tue Dec 4 15:44:45 2007
@@ -88,7 +88,7 @@
if (!conference_bridge && dynamic && (conference_bridge = ast_calloc(1, sizeof(*conference_bridge)))) {
conference_bridge->dynamic = 1;
conference_bridge->name = name;
- if (!(conference_bridge->bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_SMART, NULL))) {
+ if (!(conference_bridge->bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_SMART))) {
free(conference_bridge);
conference_bridge = NULL;
} else
@@ -147,7 +147,7 @@
/* If the menu option is enabled provide a user or admin menu as a custom feature hook */
if (ast_test_flag(&flags, OPTION_MENU))
- ast_bridge_features_hook(&features, "#", (ast_test_flag(&flags, OPTION_ADMIN) ? menu_callback_admin : menu_callback_user));
+ ast_bridge_features_hook(&features, "#", (ast_test_flag(&flags, OPTION_ADMIN) ? menu_callback_admin : menu_callback_user), NULL);
/* Actually join the bridge */
ast_bridge_join(conference_bridge->bridge, chan, NULL, &features);
@@ -164,6 +164,10 @@
ast_free(conference_bridge);
}
AST_LIST_UNLOCK(&conference_bridges);
+
+ /* Can't forget to clean up the features structure, or else we risk a memory leak */
+ if (ast_test_flag(&flags, OPTION_MENU))
+ ast_bridge_features_cleanup(&features);
return res;
}
Modified: team/file/bridging/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/file/bridging/include/asterisk/bridging.h?view=diff&rev=90992&r1=90991&r2=90992
==============================================================================
--- team/file/bridging/include/asterisk/bridging.h (original)
+++ team/file/bridging/include/asterisk/bridging.h Tue Dec 4 15:44:45 2007
@@ -98,8 +98,9 @@
typedef int (*ast_bridge_features_hook_callback)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
struct ast_bridge_features_hook {
- char *dtmf;
+ char dtmf[8];
ast_bridge_features_hook_callback callback;
+ void *hook_pvt;
AST_LIST_ENTRY(ast_bridge_features_hook) list;
};
@@ -130,7 +131,7 @@
struct ast_bridge_technology *technology; /*! Technology in use on the bridge */
void *bridge_pvt; /*! Private information unique to the bridge technology (not always needed) */
pthread_t thread; /*! Thread running the bridge */
- struct ast_bridge_features *features; /*! Enabled features information */
+ struct ast_bridge_features features; /*! Enabled features information */
AST_LIST_HEAD_NOLOCK(, ast_bridge_channel) channels; /*! Channels participating in this bridge */
};
@@ -150,7 +151,7 @@
* \param capabilities The capabilities that we require to be used on the bridge
* \return Returns bridge on success, NULL on failure
*/
-struct ast_bridge *ast_bridge_new(int capabilities, int flags, struct ast_bridge_features *features);
+struct ast_bridge *ast_bridge_new(int capabilities, int flags);
/*! \brief Destroy a bridge
* \param bridge Bridge to destroy
@@ -210,9 +211,11 @@
/*! \brief Attach a custom hook to a bridge features structure
* \param features Bridge features structure
* \param dtmf DTMF string to be activated upon
- * \return Returns 0 on success, -1 on failure
- */
-int ast_bridge_features_hook(struct ast_bridge_features *features, const char *dtmf, ast_bridge_features_hook_callback callback);
+ * \param callback Function to execute upon activation
+ * \param hook_pvt Unique data
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_features_hook(struct ast_bridge_features *features, const char *dtmf, ast_bridge_features_hook_callback callback, void *hook_pvt);
/*! \brief Enable a built in feature on a bridge features structure
* \param features Bridge features structure
@@ -221,11 +224,11 @@
*/
int ast_bridge_features_enable(struct ast_bridge_features *features, enum ast_bridge_builtin_feature feature);
-/*! \brief Destroy the contents of a bridge features structure
- * \param features Bridge features structure
- * \return Returns 0 on success, -1 on failure
- */
-int ast_bridge_features_destroy(struct ast_bridge_features *features);
+/*! \brief Clean up the contents of a bridge features structure
+ * \param features Bridge features structure
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_features_cleanup(struct ast_bridge_features *features);
#if defined(__cplusplus) || defined(c_plusplus)
}
Modified: team/file/bridging/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/main/bridging.c?view=diff&rev=90992&r1=90991&r2=90992
==============================================================================
--- team/file/bridging/main/bridging.c (original)
+++ team/file/bridging/main/bridging.c Tue Dec 4 15:44:45 2007
@@ -272,7 +272,7 @@
* \param capabilities The capabilities that we require to be used on the bridge
* \return Returns bridge on success, NULL on failure
*/
-struct ast_bridge *ast_bridge_new(int capabilities, int flags, struct ast_bridge_features *features)
+struct ast_bridge *ast_bridge_new(int capabilities, int flags)
{
struct ast_bridge *bridge = NULL;
struct ast_bridge_technology *bridge_technology = NULL;
@@ -296,8 +296,6 @@
bridge->technology = bridge_technology;
bridge->thread = AST_PTHREADT_NULL;
-
- bridge->features = features;
ast_set_flag(&bridge->feature_flags, flags);
@@ -365,6 +363,9 @@
/* Destroy the mutex that protects the bridge */
ast_mutex_destroy(&bridge->lock);
+
+ /* Before we free the entire bridge we need to pass off our features structure in case hooks were added */
+ ast_bridge_features_cleanup(&bridge->features);
/* Deallocate the bridge */
free(bridge);
@@ -1014,16 +1015,24 @@
/*! \brief Attach a custom hook to a bridge features structure
* \param features Bridge features structure
* \param dtmf DTMF string to be activated upon
+ * \param callback Function to execute upon activation
+ * \param hook_pvt Unique data
* \return Returns 0 on success, -1 on failure
*/
-int ast_bridge_features_hook(struct ast_bridge_features *features, const char *dtmf, ast_bridge_features_hook_callback callback)
+int ast_bridge_features_hook(struct ast_bridge_features *features, const char *dtmf, ast_bridge_features_hook_callback callback, void *hook_pvt)
{
struct ast_bridge_features_hook *hook = NULL;
+ /* Allocate new memory and setup it's various variables */
if (!(hook = ast_calloc(1, sizeof(*hook))))
return -1;
+ ast_copy_string(hook->dtmf, dtmf, sizeof(hook->dtmf));
hook->callback = callback;
+ hook->hook_pvt = hook_pvt;
+
+ /* Once done we add it onto the list. Now it will be picked up when DTMF is used */
+ AST_LIST_INSERT_TAIL(&features->hooks, hook, list);
return 0;
}
@@ -1044,11 +1053,17 @@
return 0;
}
-/*! \brief Destroy the contents of a bridge features structure
+/*! \brief Clean up the contents of a bridge features structure
* \param features Bridge features structure
* \return Returns 0 on success, -1 on failure
*/
-int ast_bridge_features_destroy(struct ast_bridge_features *features)
-{
- return -1;
-}
+int ast_bridge_features_cleanup(struct ast_bridge_features *features)
+{
+ struct ast_bridge_features_hook *hook = NULL;
+
+ /* This is relatively simple, hooks are kept as a list on the features structure so we just pop them off and free them */
+ while ((hook = AST_LIST_REMOVE_HEAD(&features->hooks, list)))
+ free(hook);
+
+ return 0;
+}
More information about the asterisk-commits
mailing list