[asterisk-commits] kmoore: branch kmoore/parking_unload r396721 - in /team/kmoore/parking_unload...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 14 21:04:47 CDT 2013
Author: kmoore
Date: Wed Aug 14 21:04:44 2013
New Revision: 396721
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396721
Log:
Tests pass and parking can be unloaded and reloaded without issue
Modified:
team/kmoore/parking_unload/include/asterisk/parking.h
team/kmoore/parking_unload/main/parking.c
team/kmoore/parking_unload/res/parking/parking_applications.c
team/kmoore/parking_unload/res/parking/parking_bridge_features.c
team/kmoore/parking_unload/res/parking/res_parking.h
team/kmoore/parking_unload/res/res_parking.c
Modified: team/kmoore/parking_unload/include/asterisk/parking.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/include/asterisk/parking.h?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/include/asterisk/parking.h (original)
+++ team/kmoore/parking_unload/include/asterisk/parking.h Wed Aug 14 21:04:44 2013
@@ -188,6 +188,16 @@
* \retval non-zero on error
*/
int (* parking_park_bridge_channel)(struct ast_bridge_channel *parkee, const char *parkee_uuid, const char *parker_uuid, const char *app_data);
+
+ /*!
+ * \brief Let the parking provider know it is being used.
+ */
+ void (* parking_ref)(void);
+
+ /*!
+ * \brief Let the parking provider know it is done being used.
+ */
+ void (* parking_unref)(void);
};
/*!
Modified: team/kmoore/parking_unload/main/parking.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/main/parking.c?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/main/parking.c (original)
+++ team/kmoore/parking_unload/main/parking.c Wed Aug 14 21:04:44 2013
@@ -124,19 +124,46 @@
return payload;
}
+struct parking_provider_wrapper {
+ /*! \brief The actual table that gets accessed */
+ struct ast_parking_bridge_feature_fn_table fn_table;
+ /*! \brief The pointer to the global object from which this table was created */
+ struct ast_parking_bridge_feature_fn_table *global;
+};
+
+static void provider_wrapper_dtor(void *obj)
+{
+ struct parking_provider_wrapper *wrapper = obj;
+ if (wrapper->fn_table.parking_unref) {
+ wrapper->fn_table.parking_unref();
+ }
+ ao2_cleanup(wrapper->global);
+ wrapper->global = NULL;
+}
+
struct ast_parking_bridge_feature_fn_table *ast_parking_get_bridge_features(void)
{
- return (struct ast_parking_bridge_feature_fn_table*)ao2_global_obj_ref(parking_provider);
-}
-
-/*! \brief A wrapper around the fn_table to ao2-ify it */
-struct parking_provider_wrapper {
- struct ast_parking_bridge_feature_fn_table fn_table;
-};
+ RAII_VAR(struct parking_provider_wrapper *, wrapper, ao2_alloc(sizeof(*wrapper), provider_wrapper_dtor), ao2_cleanup);
+ if (!wrapper) {
+ return NULL;
+ }
+
+ wrapper->global = ao2_global_obj_ref(parking_provider);
+ if (!wrapper->global) {
+ return NULL;
+ }
+
+ wrapper->fn_table = *wrapper->global;
+ if (wrapper->fn_table.parking_ref) {
+ wrapper->fn_table.parking_unref();
+ }
+ ao2_ref(wrapper, +1);
+ return (struct ast_parking_bridge_feature_fn_table *)wrapper;
+}
int ast_parking_register_bridge_features(struct ast_parking_bridge_feature_fn_table *fn_table)
{
- RAII_VAR(struct parking_provider_wrapper *, wrapper,
+ RAII_VAR(struct ast_parking_bridge_feature_fn_table *, wrapper,
ao2_global_obj_ref(parking_provider), ao2_cleanup);
if (fn_table->module_version != PARKING_MODULE_VERSION) {
@@ -147,7 +174,7 @@
if (wrapper) {
ast_log(AST_LOG_WARNING, "Parking provider already registered by %s!\n",
- wrapper->fn_table.module_name);
+ wrapper->module_name);
return -1;
}
@@ -155,7 +182,7 @@
if (!wrapper) {
return -1;
}
- wrapper->fn_table = *fn_table;
+ *wrapper = *fn_table;
ao2_global_obj_replace(parking_provider, wrapper);
return 0;
@@ -163,7 +190,7 @@
int ast_parking_unregister_bridge_features(const char *module_name)
{
- RAII_VAR(struct parking_provider_wrapper *, wrapper,
+ RAII_VAR(struct ast_parking_bridge_feature_fn_table *, wrapper,
ao2_global_obj_ref(parking_provider), ao2_cleanup);
if (!wrapper) {
@@ -171,7 +198,7 @@
return -1;
}
- if (strcmp(wrapper->fn_table.module_name, module_name)) {
+ if (strcmp(wrapper->module_name, module_name)) {
ast_log(AST_LOG_WARNING, "%s has not registered the parking provider\n", module_name);
return -1;
}
Modified: team/kmoore/parking_unload/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/res/parking/parking_applications.c?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/res/parking/parking_applications.c (original)
+++ team/kmoore/parking_unload/res/parking/parking_applications.c Wed Aug 14 21:04:44 2013
@@ -195,6 +195,8 @@
</application>
***/
+#define PARK_AND_ANNOUNCE_APPLICATION "ParkAndAnnounce"
+
/* Park a call */
enum park_args {
@@ -489,7 +491,7 @@
}
-int park_app_exec(struct ast_channel *chan, const char *data)
+static int park_app_exec(struct ast_channel *chan, const char *data)
{
RAII_VAR(struct ast_bridge *, parking_bridge, NULL, ao2_cleanup);
@@ -548,7 +550,7 @@
/* Retrieve a parked call */
-int parked_call_app_exec(struct ast_channel *chan, const char *data)
+static int parked_call_app_exec(struct ast_channel *chan, const char *data)
{
RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
RAII_VAR(struct parked_user *, pu, NULL, ao2_cleanup); /* Parked user being retrieved */
@@ -766,7 +768,7 @@
*dial_string = '\0'; /* If we observe this dial string on a second pass, we don't want to do anything with it. */
}
-int park_and_announce_app_exec(struct ast_channel *chan, const char *data)
+static int park_and_announce_app_exec(struct ast_channel *chan, const char *data)
{
struct ast_bridge_features chan_features;
char *parse;
@@ -858,3 +860,27 @@
return res;
}
+
+int load_parking_applications(const struct ast_module_info *ast_module_info)
+{
+ if (ast_register_application_xml(PARK_APPLICATION, park_app_exec)) {
+ return -1;
+ }
+
+ if (ast_register_application_xml(PARKED_CALL_APPLICATION, parked_call_app_exec)) {
+ return -1;
+ }
+
+ if (ast_register_application_xml(PARK_AND_ANNOUNCE_APPLICATION, park_and_announce_app_exec)) {
+ return -1;
+ }
+
+ return 0;
+}
+
+void unload_parking_applications(void)
+{
+ ast_unregister_application(PARK_APPLICATION);
+ ast_unregister_application(PARKED_CALL_APPLICATION);
+ ast_unregister_application(PARK_AND_ANNOUNCE_APPLICATION);
+}
Modified: team/kmoore/parking_unload/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/res/parking/parking_bridge_features.c?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/res/parking/parking_bridge_features.c (original)
+++ team/kmoore/parking_unload/res/parking/parking_bridge_features.c Wed Aug 14 21:04:44 2013
@@ -621,6 +621,8 @@
.parking_blind_transfer_park = parking_blind_transfer_park,
.parking_park_bridge_channel = parking_park_bridge_channel,
.parking_park_call = parking_park_call,
+ .parking_ref = parking_ref,
+ .parking_unref = parking_unref,
};
void unload_parking_bridge_features(void)
Modified: team/kmoore/parking_unload/res/parking/res_parking.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/res/parking/res_parking.h?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/res/parking/res_parking.h (original)
+++ team/kmoore/parking_unload/res/parking/res_parking.h Wed Aug 14 21:04:44 2013
@@ -32,6 +32,7 @@
#define DEFAULT_PARKING_EXTEN "700"
#define BASE_REGISTRAR "res_parking"
#define PARK_DIAL_CONTEXT "park-dial"
+#define PARKED_CALL_APPLICATION "ParkedCall"
enum park_call_resolution {
PARK_UNSET = 0, /*! Nothing set a resolution. This should never be observed in practice. */
@@ -461,53 +462,31 @@
*/
int parking_dynamic_lots_enabled(void);
-/*!
- * \since 12.0.0
- * \brief Execution function for the parking application
- *
- * \param chan ast_channel entering the application
- * \param data arguments to the application
- *
- * \retval 0 the application executed in such a way that the channel should proceed in the dial plan
- * \retval -1 the channel should no longer proceed through the dial plan
- *
- * \note this function should only be used to register the parking application and not generally to park calls.
- */
-int park_app_exec(struct ast_channel *chan, const char *data);
-
-/*!
- * \since 12.0.0
- * \brief Execution function for the parked call application
- *
- * \param chan ast_channel entering the application
- * \param data arguments to the application
- *
- * \retval 0 the application executed in such a way that the channel should proceed in the dial plan
- * \retval -1 the channel should no longer proceed through the dial plan
- */
-int parked_call_app_exec(struct ast_channel *chan, const char *data);
-
-/*!
- * \since 12.0.0
- * \brief Execution function for the park and retrieve application
- *
- * \param chan ast_channel entering the application
- * \param data arguments to the application
- *
- * \retval 0 the application executed in such a way that the channel should proceed in the dial plan
- * \retval -1 the channel should no longer proceed through the dial plan
- *
- * \note this function should only be used to register the park and announce application and not generally to park and announce.
- */
-int park_and_announce_app_exec(struct ast_channel *chan, const char *data);
-
-/*!
- * \since 12.0.0
- * \brief Register CLI commands
+struct ast_module_info;
+/*!
+ * \since 12.0.0
+ * \brief Register parking applications
+ *
+ * \param ast_module_info The module's ast_module_info
*
* \retval 0 if successful
* \retval -1 on failure
*/
+int load_parking_applications(const struct ast_module_info *ast_module_info);
+
+/*!
+ * \since 12.0.0
+ * \brief Unregister parking applications
+ */
+void unload_parking_applications(void);
+
+/*!
+ * \since 12.0.0
+ * \brief Register CLI commands
+ *
+ * \retval 0 if successful
+ * \retval -1 on failure
+ */
int load_parking_ui(void);
/*!
@@ -572,3 +551,15 @@
* \retval nonzero on failure
*/
int unload_parking_tests(void);
+
+/*!
+ * \since 12.0.0
+ * \brief Increment res_parking's use count
+ */
+void parking_ref(void);
+
+/*!
+ * \since 12.0.0
+ * \brief Decrement res_parking's use count
+ */
+void parking_unref(void);
Modified: team/kmoore/parking_unload/res/res_parking.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/parking_unload/res/res_parking.c?view=diff&rev=396721&r1=396720&r2=396721
==============================================================================
--- team/kmoore/parking_unload/res/res_parking.c (original)
+++ team/kmoore/parking_unload/res/res_parking.c Wed Aug 14 21:04:44 2013
@@ -193,9 +193,6 @@
#include "asterisk/manager.h"
#include "asterisk/pbx.h"
-#define PARKED_CALL_APPLICATION "ParkedCall"
-#define PARK_AND_ANNOUNCE_APPLICATION "ParkAndAnnounce"
-
/* TODO Add unit tests for parking */
static int parking_lot_sort_fn(const void *obj_left, const void *obj_right, int flags)
@@ -1155,6 +1152,16 @@
disable_marked_lots();
}
+void parking_ref(void)
+{
+ ast_module_ref(ast_module_info->self);
+}
+
+void parking_unref(void)
+{
+ ast_module_unref(ast_module_info->self);
+}
+
static int load_module(void)
{
parking_lot_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX,
@@ -1197,15 +1204,7 @@
goto error;
}
- if (ast_register_application_xml(PARK_APPLICATION, park_app_exec)) {
- goto error;
- }
-
- if (ast_register_application_xml(PARKED_CALL_APPLICATION, parked_call_app_exec)) {
- goto error;
- }
-
- if (ast_register_application_xml(PARK_AND_ANNOUNCE_APPLICATION, park_and_announce_app_exec)) {
+ if (load_parking_applications(ast_module_info)) {
goto error;
}
@@ -1249,21 +1248,18 @@
static int unload_module(void)
{
-
- /*ast_parking_unregister_bridge_features(parking_provider.module_name);*/
-
- /* XXX Parking is currently not unloadable due to the fact that it loads features which could cause
- * significant problems if they disappeared while a channel still had access to them.
- */
- return -1;
-
- /* TODO Things we will need to do here:
- *
- * destroy existing parking lots
- * uninstall parking related bridge features
- * remove extensions owned by the parking registrar
- * unload currently loaded unit tests, CLI/AMI commands, etc.
- */
+ remove_all_configured_parking_lot_extensions();
+ unload_parking_bridge_features();
+ unload_parking_tests();
+ unload_parking_devstate();
+ unload_parking_manager();
+ unload_parking_ui();
+ unload_parking_applications();
+ ao2_cleanup(parking_lot_container);
+ parking_lot_container = NULL;
+ aco_info_destroy(&cfg_info);
+
+ return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Call Parking Resource",
More information about the asterisk-commits
mailing list