Add simple managedlist function to print out loaded APIs/Apps
This commit is contained in:
parent
6cd6a719f5
commit
535e6ece60
|
@ -47,13 +47,15 @@ namespace FreeSWITCH {
|
|||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ExecuteBackgroundDelegate(string cmd);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool RunDelegate(string cmd, IntPtr session);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ReloadDelegate(string cmd);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ListDelegate(string cmd);
|
||||
static readonly ExecuteDelegate _execute = Execute;
|
||||
static readonly ExecuteBackgroundDelegate _executeBackground = ExecuteBackground;
|
||||
static readonly RunDelegate _run = Run;
|
||||
static readonly ReloadDelegate _reload = Reload;
|
||||
//SWITCH_MOD_DECLARE_NONSTD(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, reloadFunction reload)
|
||||
static readonly ListDelegate _list = List;
|
||||
|
||||
[DllImport("mod_managed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload);
|
||||
static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload, ListDelegate list);
|
||||
|
||||
static readonly object loaderLock = new object();
|
||||
|
||||
|
@ -83,7 +85,7 @@ namespace FreeSWITCH {
|
|||
return File.Exists(path) ? Assembly.LoadFile(path) : null;
|
||||
};
|
||||
|
||||
InitManagedDelegates(_run, _execute, _executeBackground, _reload);
|
||||
InitManagedDelegates(_run, _execute, _executeBackground, _reload, _list);
|
||||
|
||||
configureWatcher();
|
||||
|
||||
|
@ -405,7 +407,24 @@ namespace FreeSWITCH {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool List(string command) {
|
||||
try {
|
||||
Log.WriteLine(LogLevel.Info, "Available APIs:");
|
||||
getApiExecs().Values.ForEach(x => {
|
||||
Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray()));
|
||||
});
|
||||
Log.WriteLine(LogLevel.Info, "Available Apps:");
|
||||
getAppExecs().Values.ForEach(x => {
|
||||
Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray()));
|
||||
});
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
Log.WriteLine(LogLevel.Error, "Exception listing managed modules: {0}", ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Michael Giagnocavo <mgg@packetrino.com>
|
||||
* Michael Giagnocavo <mgg@giagnocavo.net>
|
||||
* David Brazier <David.Brazier@360crm.co.uk>
|
||||
* Jeff Lenk <jlenk@frontiernet.net>
|
||||
*
|
||||
|
@ -55,6 +55,7 @@ SWITCH_STANDARD_API(managedrun_api_function); /* ExecuteBackground */
|
|||
SWITCH_STANDARD_API(managed_api_function); /* Execute */
|
||||
SWITCH_STANDARD_APP(managed_app_function); /* Run */
|
||||
SWITCH_STANDARD_API(managedreload_api_function); /* Reload */
|
||||
SWITCH_STANDARD_API(managedlist_api_function); /* List modules */
|
||||
|
||||
#define MOD_MANAGED_ASM_NAME "FreeSWITCH.Managed"
|
||||
#define MOD_MANAGED_ASM_V1 1
|
||||
|
@ -72,19 +73,23 @@ typedef int (*runFunction)(const char *data, void *sessionPtr);
|
|||
typedef int (*executeFunction)(const char *cmd, void *stream, void *Event);
|
||||
typedef int (*executeBackgroundFunction)(const char* cmd);
|
||||
typedef int (*reloadFunction)(const char* cmd);
|
||||
typedef int (*listFunction)(const char* cmd);
|
||||
static runFunction runDelegate;
|
||||
static executeFunction executeDelegate;
|
||||
static executeBackgroundFunction executeBackgroundDelegate;
|
||||
static reloadFunction reloadDelegate;
|
||||
static listFunction listDelegate;
|
||||
|
||||
SWITCH_MOD_DECLARE_NONSTD(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, reloadFunction reload)
|
||||
SWITCH_MOD_DECLARE_NONSTD(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, reloadFunction reload, listFunction list)
|
||||
{
|
||||
runDelegate = run;
|
||||
executeDelegate = execute;
|
||||
executeBackgroundDelegate = executeBackground;
|
||||
reloadDelegate = reload;
|
||||
listDelegate = list;
|
||||
}
|
||||
|
||||
|
||||
// Sets up delegates (and anything else needed) on the ManagedSession object
|
||||
// Called from ManagedSession.Initialize Managed -> this is Unmanaged code so all pointers are marshalled and prevented from GC
|
||||
// Exported method.
|
||||
|
@ -361,6 +366,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_managed_load)
|
|||
SWITCH_ADD_API(api_interface, "managed", "Run a module as an API function (Execute)", managed_api_function, "<module> [<args>]");
|
||||
SWITCH_ADD_APP(app_interface, "managed", "Run CLI App", "Run an App on a channel", managed_app_function, "<modulename> [<args>]", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_API(api_interface, "managedreload", "Force [re]load of a file", managedreload_api_function, "<filename>");
|
||||
SWITCH_ADD_API(api_interface, "managedlist", "Log the list of available APIs and Apps", managedlist_api_function, "");
|
||||
return SWITCH_STATUS_NOUNLOAD;
|
||||
}
|
||||
|
||||
|
@ -440,4 +446,16 @@ SWITCH_STANDARD_API(managedreload_api_function)
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(managedlist_api_function)
|
||||
{
|
||||
#ifndef _MANAGED
|
||||
mono_thread_attach(globals.domain);
|
||||
#endif
|
||||
listDelegate(cmd);
|
||||
#ifndef _MANAGED
|
||||
mono_thread_detach(mono_thread_current());
|
||||
#endif
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
|
|
Loading…
Reference in New Issue