#endif \r
}\r
\r
-switch_status_t loadModMonoManaged() \r
+switch_status_t loadRuntime() \r
{\r
/* Find and load mod_mono_managed.exe */ \r
char filename[256];\r
\r
+ if (setMonoDirs() != SWITCH_STATUS_SUCCESS) {\r
+ return SWITCH_STATUS_FALSE;\r
+ }\r
+\r
switch_snprintf(filename, 256, "%s%s%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_PATH_SEPARATOR, MOD_MANAGED_DLL);\r
globals.domain = mono_jit_init(filename);\r
\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found all loader functions.\n");\r
return SWITCH_STATUS_SUCCESS;\r
}\r
-\r
-SWITCH_MODULE_LOAD_FUNCTION(mod_managed_load) \r
-{\r
- /* connect my internal structure to the blank pointer passed to me */ \r
- *module_interface = switch_loadable_module_create_module_interface(pool, modname);\r
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loading mod_managed (Common Language Infrastructure), Mono Version\n");\r
- globals.pool = pool;\r
-\r
- if (setMonoDirs() != SWITCH_STATUS_SUCCESS) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
- if (loadModMonoManaged() != SWITCH_STATUS_SUCCESS) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
- if (findLoader() != SWITCH_STATUS_SUCCESS) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
- /* Not sure if this is necesary on the loading thread */ \r
- mono_thread_attach(globals.domain);\r
-\r
- /* Run loader */ \r
- MonoObject * objResult;\r
- MonoObject * exception = NULL;\r
-\r
- objResult = mono_runtime_invoke(globals.loadMethod, NULL, NULL, &exception);\r
-\r
- if (exception) {\r
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load threw an exception.\n");\r
- mono_print_unhandled_exception(exception);\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
- if (*(int *) mono_object_unbox(objResult)) {\r
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");\r
- } else {\r
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load did not return true.\n");\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
- /* We're good to register */ \r
- switch_api_interface_t *api_interface;\r
- switch_application_interface_t *app_interface;\r
-\r
- SWITCH_ADD_API(api_interface, "managedrun", "Run a module (ExecuteBackground)", managedrun_api_function, "<module> [<args>]");\r
- SWITCH_ADD_API(api_interface, "managed", "Run a module as an API function (Execute)", managed_api_function, "<module> [<args>]");\r
- SWITCH_ADD_APP(app_interface, "managed", "Run Mono IVR", "Run a Mono IVR on a channel", managed_app_function, "<modulename> [<args>]", SAF_NONE);\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
#endif\r
\r
/**********************************************************\r
session->hangupDelegate = hangupDelegate;\r
}\r
\r
-switch_status_t loadModDotnetManaged() \r
+switch_status_t loadRuntime() \r
{\r
/* Find and load mod_dotnet_managed.dll */ \r
char filename[256];\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found all FreeSWITCH.Loader functions.\n");\r
return SWITCH_STATUS_SUCCESS;\r
}\r
+#endif\r
\r
SWITCH_MODULE_LOAD_FUNCTION(mod_managed_load) \r
{\r
+ int success;\r
/* connect my internal structure to the blank pointer passed to me */ \r
*module_interface = switch_loadable_module_create_module_interface(pool, modname);\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loading mod_managed (Common Language Infrastructure), Microsoft CLR Version\n");\r
\r
globals.pool = pool;\r
\r
- if (loadModDotnetManaged() != SWITCH_STATUS_SUCCESS) { \r
+ if (loadRuntime() != SWITCH_STATUS_SUCCESS) { \r
return SWITCH_STATUS_FALSE;\r
}\r
\r
if (findLoader() != SWITCH_STATUS_SUCCESS) { \r
return SWITCH_STATUS_FALSE;\r
}\r
-\r
+#ifdef _MANAGED\r
Object ^objResult;\r
try {\r
objResult = FreeSwitchManaged::loadMethod->Invoke(nullptr, nullptr);\r
+ success = *reinterpret_cast<bool^>(objResult);\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");\r
}\r
catch(Exception^ ex) {\r
Marshal::FreeHGlobal(msg);\r
return SWITCH_STATUS_FALSE;\r
}\r
+#else\r
+ /* Not sure if this is necesary on the loading thread */ \r
+ mono_thread_attach(globals.domain);\r
+\r
+ /* Run loader */ \r
+ MonoObject * objResult;\r
+ MonoObject * exception = NULL;\r
+\r
+ objResult = mono_runtime_invoke(globals.loadMethod, NULL, NULL, &exception);\r
+ success = *(int *) mono_object_unbox(objResult);\r
\r
- if (*reinterpret_cast<bool^>(objResult)) {\r
+ if (exception) {\r
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load threw an exception.\n");\r
+ mono_print_unhandled_exception(exception);\r
+ return SWITCH_STATUS_FALSE;\r
+ }\r
+#endif\r
+ if (success) {\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");\r
} else { \r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load did not return true.\n");\r
SWITCH_ADD_APP(app_interface, "managed", "Run CLI App", "Run an App on a channel", managed_app_function, "<modulename> [<args>]", SAF_NONE);\r
return SWITCH_STATUS_SUCCESS;\r
}\r
-#endif\r
\r
SWITCH_STANDARD_API(managedrun_api_function) \r
{\r
Object ^objResult;\r
try {\r
objResult = FreeSwitchManaged::executeBackgroundMethod->Invoke(nullptr, gcnew array<Object^> { gcnew String(cmd) } );\r
+ success = *reinterpret_cast<bool^>(objResult);\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");\r
} catch(Exception^ ex) {\r
IntPtr msg = Marshal::StringToHGlobalAnsi(ex->ToString());\r
Marshal::FreeHGlobal(msg);\r
return SWITCH_STATUS_FALSE;\r
}\r
- success = *reinterpret_cast<bool^>(objResult);\r
#else\r
mono_thread_attach(globals.domain);\r
void *args[1];\r
args[0] = mono_string_new(globals.domain, cmd);\r
MonoObject * exception = NULL;\r
MonoObject * objResult = mono_runtime_invoke(globals.executeBackgroundMethod, NULL, args, &exception);\r
+ success = *(int *) mono_object_unbox(objResult);\r
\r
if (exception) {\r
stream->write_function(stream, "-ERR FreeSWITCH.Loader.ExecuteBackground threw an exception.\n");\r
mono_print_unhandled_exception(exception);\r
return SWITCH_STATUS_SUCCESS;\r
}\r
- success = *(int *) mono_object_unbox(objResult);\r
#endif\r
if (success) {\r
stream->write_function(stream, "+OK\n");\r
try {\r
objResult = FreeSwitchManaged::executeMethod->Invoke(nullptr, gcnew array<Object^>{gcnew String(cmd),gcnew IntPtr(stream), gcnew IntPtr(stream->param_event)});\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute completed successfully.\n");\r
+ success = *reinterpret_cast<bool^>(objResult);\r
} catch(Exception ^ex) {\r
IntPtr msg = Marshal::StringToHGlobalAnsi(ex->ToString());\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute cli %s: %s\n", cmd, static_cast<const char*>(msg.ToPointer()));\r
Marshal::FreeHGlobal(msg);\r
return SWITCH_STATUS_FALSE;\r
}\r
- success = *reinterpret_cast<bool^>(objResult);\r
#else\r
mono_thread_attach(globals.domain);\r
void *args[3];\r
\r
MonoObject * exception = NULL;\r
MonoObject * objResult = mono_runtime_invoke(globals.executeMethod, NULL, args, &exception);\r
+ success = *(int *) mono_object_unbox(objResult);\r
\r
if (exception) {\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute mono %s.\n", cmd);\r
mono_print_unhandled_exception(exception);\r
}\r
- success = *(int *) mono_object_unbox(objResult);\r
#endif\r
if (!success) {\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Execute failed for %s (unknown module?).\n", cmd);\r
try {\r
objResult = FreeSwitchManaged::runMethod->Invoke(nullptr, gcnew array<Object^>{gcnew String(data),gcnew IntPtr(session)});\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RunMethod completed successfully.\n");\r
+ success = *reinterpret_cast<bool^>(objResult);\r
}\r
catch(Exception ^ex) {\r
IntPtr msg = Marshal::StringToHGlobalAnsi(ex->ToString());\r
Marshal::FreeHGlobal(msg);\r
return;\r
}\r
- success = *reinterpret_cast<bool^>(objResult);\r
#else\r
mono_thread_attach(globals.domain);\r
void *args[2];\r
\r
MonoObject * exception = NULL;\r
MonoObject * objResult = mono_runtime_invoke(globals.runMethod, NULL, args, &exception);\r
+ success = *(int *) mono_object_unbox(objResult);\r
\r
if (exception) {\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute application mono %s.\n", data);\r
mono_print_unhandled_exception(exception);\r
}\r
- success = *(int *) mono_object_unbox(objResult);\r
#endif\r
if (!success) {\r
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Application run failed for %s (unknown module?).\n", data);\r