]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more ref checking
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 13 Nov 2008 17:40:25 +0000 (17:40 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 13 Nov 2008 17:40:25 +0000 (17:40 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10375 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_loadable_module.h
src/include/switch_module_interfaces.h
src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_core_codec.c
src/switch_core_session.c
src/switch_ivr.c
src/switch_ivr_menu.c
src/switch_ivr_originate.c

index 542899f3cf43ee4745a511c075bca79e218fe9d3..3cc1e9ff66962e90a8d51d264614cc006bab7b48 100644 (file)
@@ -94,7 +94,7 @@ typedef enum {
 struct switch_core_session {
        switch_memory_pool_t *pool;
        switch_thread_t *thread;
-       const switch_endpoint_interface_t *endpoint_interface;
+       switch_endpoint_interface_t *endpoint_interface;
        switch_size_t id;
        switch_session_flag_t flags;
        int thread_running;
index d2bd2c819fff4ecaa3944a79793b8c6b5dfbc170..64e49d3b3e4e59911dfd5571bc5417a7937232bb 100644 (file)
@@ -508,7 +508,7 @@ SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(_In_ switch_
   \param pool the pool to use for the allocation (a new one will be used if NULL)
   \return the newly created session
 */
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ const switch_endpoint_interface_t *endpoint_interface,
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ switch_endpoint_interface_t *endpoint_interface,
                                                                                                                                                 _Inout_opt_ switch_memory_pool_t **pool, _In_opt_z_ const char *use_uuid);
 #define switch_core_session_request(_ep, _p) switch_core_session_request_uuid(_ep, _p, NULL)
 
index 42a34d654107aae926ef0e180eeeff18230bddca..724bb72d939012bdb9f994361564fa23a459bd20 100644 (file)
@@ -81,6 +81,7 @@ SWITCH_BEGIN_EXTERN_C
        /*! the table of management interfaces the module has implmented */
        switch_management_interface_t *management_interface;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_memory_pool_t *pool;
 };
 
index adfce928ebf4e1f1c7a3528e2b43be74f2a9949e..e615f8403afb430d406d69da1309a6ba746f042a 100644 (file)
@@ -172,6 +172,7 @@ struct switch_endpoint_interface {
        void *private_info;
 
        switch_thread_rwlock_t *rwlock;
+       int refs;
 
        /* parent */
        switch_loadable_module_interface_t *parent;
@@ -226,6 +227,7 @@ struct switch_timer_interface {
        /*! function to deallocate the timer */
        switch_status_t (*timer_destroy) (switch_timer_t *);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_timer_interface *next;
 };
@@ -237,6 +239,7 @@ struct switch_dialplan_interface {
        /*! the function to read an extension and set a channels dialpan */
        switch_dialplan_hunt_function_t hunt_function;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_dialplan_interface *next;
 };
@@ -262,6 +265,7 @@ struct switch_file_interface {
        /*! list of supported file extensions */
        char **extens;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_file_interface *next;
 };
@@ -269,7 +273,7 @@ struct switch_file_interface {
 /*! an abstract representation of a file handle (some parameters based on compat with libsndfile) */
 struct switch_file_handle {
        /*! the interface of the module that implemented the current file type */
-       const switch_file_interface_t *file_interface;
+       switch_file_interface_t *file_interface;
        /*! flags to control behaviour */
        uint32_t flags;
        /*! a file descriptor if neceessary */
@@ -340,6 +344,7 @@ struct switch_asr_interface {
        /*! function to read results from the ASR */
        switch_status_t (*asr_get_results) (switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_asr_interface *next;
 };
@@ -347,7 +352,7 @@ struct switch_asr_interface {
 /*! an abstract representation of an asr speech interface. */
 struct switch_asr_handle {
        /*! the interface of the module that implemented the current speech interface */
-       const switch_asr_interface_t *asr_interface;
+       switch_asr_interface_t *asr_interface;
        /*! flags to control behaviour */
        uint32_t flags;
        /*! The Name */
@@ -382,6 +387,7 @@ struct switch_speech_interface {
        void (*speech_numeric_param_tts) (switch_speech_handle_t *sh, char *param, int val);
        void (*speech_float_param_tts) (switch_speech_handle_t *sh, char *param, double val);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_speech_interface *next;
 };
@@ -390,7 +396,7 @@ struct switch_speech_interface {
 /*! an abstract representation of a asr/tts speech interface. */
 struct switch_speech_handle {
        /*! the interface of the module that implemented the current speech interface */
-       const switch_speech_interface_t *speech_interface;
+       switch_speech_interface_t *speech_interface;
        /*! flags to control behaviour */
        uint32_t flags;
        /*! The Name */
@@ -416,6 +422,7 @@ struct switch_say_interface {
        /*! function to pass down to the module */
        switch_say_callback_t say_function;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_say_interface *next;
 };
@@ -427,6 +434,7 @@ struct switch_chat_interface {
        /*! function to open the directory interface */
        switch_status_t (*chat_send) (char *proto, char *from, char *to, char *subject, char *body, char *hint);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_chat_interface *next;
 };
@@ -438,6 +446,7 @@ struct switch_management_interface {
        /*! function to open the directory interface */
        switch_status_t (*management_function) (char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_management_interface *next;
 };
@@ -457,6 +466,7 @@ struct switch_directory_interface {
        /*! function to advance to the next name/value pair in the current record */
        switch_status_t (*directory_next_pair) (switch_directory_handle_t *dh, char **var, char **val);
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_directory_interface *next;
 };
@@ -464,7 +474,7 @@ struct switch_directory_interface {
 /*! an abstract representation of a directory interface. */
 struct switch_directory_handle {
        /*! the interface of the module that implemented the current directory interface */
-       const switch_directory_interface_t *directory_interface;
+       switch_directory_interface_t *directory_interface;
        /*! flags to control behaviour */
        uint32_t flags;
 
@@ -515,7 +525,7 @@ struct switch_codec_settings {
 /*! an abstract handle to a codec module */
 struct switch_codec {
        /*! the codec interface table this handle uses */
-       const switch_codec_interface_t *codec_interface;
+       switch_codec_interface_t *codec_interface;
        /*! the specific implementation of the above codec */
        const switch_codec_implementation_t *implementation;
        /*! fmtp line from remote sdp */
@@ -582,6 +592,7 @@ struct switch_codec_interface {
        switch_codec_implementation_t *implementations;
        uint32_t codec_id;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_codec_interface *next;
 };
@@ -601,6 +612,7 @@ struct switch_application_interface {
        /*! flags to control behaviour */
        uint32_t flags;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_application_interface *next;
 };
@@ -616,12 +628,13 @@ struct switch_api_interface {
        /*! an example of the api syntax */
        const char *syntax;
        switch_thread_rwlock_t *rwlock;
+       int refs;
        switch_loadable_module_interface_t *parent;
        struct switch_api_interface *next;
 };
 
-#define PROTECT_INTERFACE(_it) switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock)
-#define UNPROTECT_INTERFACE(_it) switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it = NULL
+#define PROTECT_INTERFACE(_it) if (!_it->refs) {switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++;}
+#define UNPROTECT_INTERFACE(_it) if (_it->refs) {switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; _it = NULL;}
 
 SWITCH_END_EXTERN_C
 #endif
index 84d9aa4c873324204391d1c0327feb3fed079537..3092001c64c0ffdd3e2a0c577d1135261986a127 100644 (file)
@@ -38,7 +38,7 @@ SWITCH_MODULE_DEFINITION(mod_dialplan_asterisk, mod_dialplan_asterisk_load, NULL
 
 static switch_status_t exec_app(switch_core_session_t *session, char *app, char *arg)
 {
-       const switch_application_interface_t *application_interface;
+       switch_application_interface_t *application_interface;
        switch_status_t status = SWITCH_STATUS_FALSE;
 
        if ((application_interface = switch_loadable_module_get_application_interface(app))) {
index edf050c8efc2b04fa786dcf9a6398e815f562949..6a2911263b108a70b55350a5051f41505e0bbde2 100644 (file)
@@ -2199,7 +2199,7 @@ static JSBool session_execute(JSContext * cx, JSObject * obj, uintN argc, jsval
        /* you can execute some apps before you answer  CHANNEL_SANITY_CHECK(); */
 
        if (argc > 0) {
-               const switch_application_interface_t *application_interface;
+               switch_application_interface_t *application_interface;
                char *app_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
                char *app_arg = NULL;
                jsrefcount saveDepth;
index 637d85517030115ed1d6ff1afdd35fce2755d5ad..236f86b5c85d07549631ef024097197b149e497b 100644 (file)
@@ -378,7 +378,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, co
                                                                                                           uint32_t rate, int ms, int channels, uint32_t flags,
                                                                                                           const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 {
-       const switch_codec_interface_t *codec_interface;
+       switch_codec_interface_t *codec_interface;
        const switch_codec_implementation_t *iptr, *implementation = NULL;
        const char *mode = fmtp;
 
index 5888ed2c6639bf17245d120e97a0fbd71829bb2a..ad359ca34bee583e4dae8fcc6d3687a407a0531f 100644 (file)
@@ -789,7 +789,7 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
 {
        switch_memory_pool_t *pool;
        switch_event_t *event;
-       const switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
+       switch_endpoint_interface_t *endpoint_interface = (*session)->endpoint_interface;
 
 
        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n",
@@ -998,7 +998,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session
        return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(const switch_endpoint_interface_t
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_endpoint_interface_t
                                                                                                                                                 *endpoint_interface, switch_memory_pool_t **pool, const char *use_uuid)
 {
        switch_memory_pool_t *usepool;
@@ -1110,14 +1110,13 @@ SWITCH_DECLARE(switch_size_t) switch_core_session_id(void)
 
 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(const char *endpoint_name, switch_memory_pool_t **pool)
 {
-       const switch_endpoint_interface_t *endpoint_interface, *e;
+       switch_endpoint_interface_t *endpoint_interface;
 
        if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
                return NULL;
        }
-       e = endpoint_interface;
-       UNPROTECT_INTERFACE(e);
+
        return switch_core_session_request(endpoint_interface, pool);
 
 }
@@ -1187,7 +1186,7 @@ SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(switch_core_s
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_core_session_t *session, const char *app, const char *arg)
 {
-       const switch_application_interface_t *application_interface;
+       switch_application_interface_t *application_interface;
        char *expanded = NULL;
        const char *var;
 
index c52c50daf2ca9233bdb0c2cb2af835d990eb6a76..9484813adb99aa78841b30ee66f11777c908b22e 100644 (file)
@@ -344,7 +344,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
        }
 
        if (cmd_hash == CMD_EXECUTE) {
-               const switch_application_interface_t *application_interface;
+               switch_application_interface_t *application_interface;
                char *app_name = switch_event_get_header(event, "execute-app-name");
                char *app_arg = switch_event_get_header(event, "execute-app-arg");
                char *loop_h = switch_event_get_header(event, "loops");
index f72257f641e19075424520f1f5c11bafbfc9c125..c50f16077446995fab230d3c6889b4a5c3ec1127 100644 (file)
@@ -463,7 +463,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
                                                break;
                                        case SWITCH_IVR_ACTION_EXECAPP:
                                                {
-                                                       const switch_application_interface_t *application_interface;
+                                                       switch_application_interface_t *application_interface;
                                                        char *app_name;
                                                        char *app_arg = NULL;
 
index 328c9eed4913db2b104ebae362105dad798137fd..45fcfae055f19b39b49a9f0a99a4344fe14cdb50 100644 (file)
@@ -99,7 +99,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void
        
        if (!strcasecmp(collect->key, "exec")) {
                char *data;
-               const switch_application_interface_t *application_interface;
+               switch_application_interface_t *application_interface;
                char *app_name, *app_data;
 
                if (!(data = collect->file)) {