]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
(LBAPR-1) load mod_lua with global symbols space so that sub modules are able to...
authorMichael Jerris <mike@jerris.com>
Sat, 8 Nov 2008 11:21:54 +0000 (11:21 +0000)
committerMichael Jerris <mike@jerris.com>
Sat, 8 Nov 2008 11:21:54 +0000 (11:21 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10306 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/mod/asr_tts/mod_cepstral/mod_cepstral.c
src/mod/languages/mod_lua/mod_lua.cpp
src/switch_loadable_module.c

index 4fd03d387ca1205246a0baabd455dc611e86cf0e..77da217f04f50cf3e1c430024ce0ab9515212c13 100644 (file)
@@ -1355,7 +1355,7 @@ struct switch_network_list;
 typedef struct switch_network_list switch_network_list_t;
 
 
-#define SWITCH_API_VERSION 1
+#define SWITCH_API_VERSION 2
 #define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
 #define SWITCH_MODULE_RUNTIME_ARGS (void)
 #define SWITCH_MODULE_SHUTDOWN_ARGS (void)
@@ -1366,22 +1366,32 @@ typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS;
 #define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
 #define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
 
+typedef enum {
+       SMODF_NONE = 0,
+       SMODF_GLOBAL_SYMBOLS = (1 << 0)
+} switch_module_flag_enum_t;
+typedef uint32_t switch_module_flag_t;
+
 typedef struct switch_loadable_module_function_table {
        int switch_api_version;
        switch_module_load_t load;
        switch_module_shutdown_t shutdown;
        switch_module_runtime_t runtime;
+       switch_module_flag_t flags;
 } switch_loadable_module_function_table_t;
 
-#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)                                                                \
+#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags)                                      \
 static const char modname[] =  #name ;                                                                                                         \
 SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = {    \
        SWITCH_API_VERSION,                                                                                                                                             \
        load,                                                                                                                                                                   \
        shutdown,                                                                                                                                                               \
-       runtime                                                                                                                                                                 \
+       runtime,                                                                                                                                                                \
+       flags                                                                                                                                                                   \
 }
 
+#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)                                                                \
+               SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE)
 
 /* things we don't deserve to know about */
 /*! \brief A channel */
index 5d914a04f11596f5612312dc2e5eec111689b6d3..c91c2746fd6674fd982f08e040ce09064c1fa51b 100644 (file)
@@ -52,7 +52,7 @@
 #define SWIFT_FAILED(r) ((void *)(r) < (void *)0)
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_cepstral_load);
-SWITCH_MODULE_DEFINITION(mod_cepstral, mod_cepstral_load, NULL, NULL);
+SWITCH_MODULE_DEFINITION_EX(mod_cepstral, mod_cepstral_load, NULL, NULL, SMODF_GLOBAL_SYMBOLS);
 
 static swift_engine *engine;
 
index 04b17f75df5635123f59cf15d68208abe18aadc0..37af26e23a97db2021ad962bcb0d5b4c9fa29a74 100644 (file)
@@ -40,8 +40,7 @@ SWITCH_BEGIN_EXTERN_C
 SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lua_shutdown);
 
-SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, mod_lua_shutdown, NULL);
-
+SWITCH_MODULE_DEFINITION_EX(mod_lua, mod_lua_load, mod_lua_shutdown, NULL, SMODF_GLOBAL_SYMBOLS);
 static struct {
        switch_memory_pool_t *pool;
        char *xml_handler;
index 42d7bd1cc8290cb8b244551878db0f89dbddab31..e65e3e6db221d22910a33e3c40a6c8bc6ae087f8 100644 (file)
@@ -691,6 +691,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
        char *derr = NULL;
        const char *err = NULL;
        switch_memory_pool_t *pool;
+       switch_bool_t load_global = global;
 
        switch_assert(path != NULL);
 
@@ -700,11 +701,11 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
        struct_name = switch_core_sprintf(pool, "%s_module_interface", filename);
 
 #ifdef WIN32
-       dso = switch_dso_open("FreeSwitch.dll", global, &derr);
+       dso = switch_dso_open("FreeSwitch.dll", load_global, &derr);
 #elif defined (MACOSX) || defined(DARWIN)
-       dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", global, &derr);
+       dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", load_global, &derr);
 #else
-       dso = switch_dso_open(NULL, global, &derr);
+       dso = switch_dso_open(NULL, load_global, &derr);
 #endif
        if (!derr && dso) {
                interface_struct_handle = switch_dso_data_sym(dso, struct_name, &derr);
@@ -713,7 +714,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
        switch_safe_free(derr)
 
        if (!interface_struct_handle) {
-               dso = switch_dso_open(path, global, &derr);
+               dso = switch_dso_open(path, load_global, &derr);
        }
 
        while (loading) {
@@ -731,6 +732,20 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
                        break;
                }
 
+               if (interface_struct_handle && interface_struct_handle->switch_api_version != SWITCH_API_VERSION) {
+                       err = "Trying to load an out of date module, please rebuild the module.";
+                       break;  
+               }
+
+               if (!load_global && interface_struct_handle && switch_test_flag(interface_struct_handle, SMODF_GLOBAL_SYMBOLS)) {
+                       load_global = SWITCH_TRUE;
+                       switch_dso_destroy(&dso);
+                       interface_struct_handle = NULL;
+                       dso = switch_dso_open(path, load_global, &derr);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading module with global namespace at request of module\n");
+                       continue;
+               }
+
                if (interface_struct_handle) {
                        mod_interface_functions = interface_struct_handle;
                        load_func_ptr = mod_interface_functions->load;