]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_managed: managedlist command must return value to api stream instead of log
authorArtur Kraev <ravenox@gmail.com>
Sun, 2 Nov 2014 21:17:57 +0000 (00:17 +0300)
committerArtur Kraev <ravenox@gmail.com>
Sun, 2 Nov 2014 21:17:57 +0000 (00:17 +0300)
src/mod/languages/mod_managed/managed/Loader.cs
src/mod/languages/mod_managed/mod_managed.cpp

index 19ab3a52dbdf29a7a62bfa952a73c6d2d9ef0b83..c655c9c8672d5b6edb9232563dddb3ab71536252 100644 (file)
@@ -26,6 +26,7 @@
  * Michael Giagnocavo <mgg@giagnocavo.net>\r
  * David Brazier <David.Brazier@360crm.co.uk>\r
  * Jeff Lenk <jeff@jefflenk.com>\r
+ * Artur Kraev <ravenox@gmail.com>\r
  * \r
  * Loader.cs -- mod_managed loader\r
  *\r
@@ -33,7 +34,6 @@
 \r
 using System;\r
 using System.Collections.Generic;\r
-using System.Text;\r
 using System.IO;\r
 using System.Linq;\r
 using System.Reflection;\r
@@ -46,16 +46,15 @@ namespace FreeSWITCH {
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ExecuteDelegate(string cmd, IntPtr streamH, IntPtr eventH);\r
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ExecuteBackgroundDelegate(string cmd);\r
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool RunDelegate(string cmd, IntPtr session);\r
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ReloadDelegate(string cmd);\r
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ListDelegate(string cmd);\r
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate bool ReloadDelegate(string cmd);        \r
         static readonly ExecuteDelegate _execute = Execute;\r
         static readonly ExecuteBackgroundDelegate _executeBackground = ExecuteBackground;\r
         static readonly RunDelegate _run = Run;\r
         static readonly ReloadDelegate _reload = Reload;\r
-        static readonly ListDelegate _list = List;\r
+        static readonly ExecuteDelegate _list = List;\r
         \r
         [DllImport("mod_managed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]\r
-        static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload, ListDelegate list);\r
+        static extern void InitManagedDelegates(RunDelegate run, ExecuteDelegate execute, ExecuteBackgroundDelegate executeBackground, ReloadDelegate reload, ExecuteDelegate list);\r
 \r
         static readonly object loaderLock = new object();\r
 \r
@@ -408,18 +407,33 @@ namespace FreeSWITCH {
             }\r
         }\r
 \r
-        public static bool List(string command) {\r
-            try {\r
-                               Log.WriteLine(LogLevel.Info, "Available APIs:");\r
-                getApiExecs().Values.ForEach(x => {\r
-                                       Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray()));\r
-                               });\r
-                               Log.WriteLine(LogLevel.Info, "Available Apps:");\r
-                               getAppExecs().Values.ForEach(x => {\r
-                                       Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray()));\r
-                               });\r
+        public static bool List(string command, IntPtr streamHandle, IntPtr eventHandle)\r
+        {\r
+            try\r
+            {\r
+                if (streamHandle != IntPtr.Zero)\r
+                {\r
+                    using (var stream = new Native.Stream(new Native.switch_stream_handle(streamHandle, false)))\r
+                    {\r
+                        stream.Write("Available APIs:\n");\r
+\r
+                        getApiExecs().Values.ForEach(x => stream.Write(string.Format("{0}: {1}\n", x.Name, String.Join(",", x.Aliases.ToArray()))));\r
+\r
+                        stream.Write("Available Apps:\n");\r
+                        getAppExecs().Values.ForEach(x => stream.Write(string.Format("{0}: {1}\n", x.Name, String.Join(",", x.Aliases.ToArray()))));\r
+                    }\r
+                }\r
+                else\r
+                {\r
+                    Log.WriteLine(LogLevel.Info, "Available APIs:");\r
+                    getApiExecs().Values.ForEach(x => Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray())));\r
+                    Log.WriteLine(LogLevel.Info, "Available Apps:");\r
+                    getAppExecs().Values.ForEach(x => Log.WriteLine(LogLevel.Info, "{0}: {1}", x.Name, String.Join(",", x.Aliases.ToArray())));\r
+                }\r
                 return true;\r
-            } catch (Exception ex) {\r
+            }\r
+            catch (Exception ex)\r
+            {\r
                 Log.WriteLine(LogLevel.Error, "Exception listing managed modules: {0}", ex.ToString());\r
                 return false;\r
             }\r
index 215a98336bf9f79aea392e262c6315ea562fe031..6718265d538745aa204e8e51f4b1a4f57d644360 100644 (file)
@@ -26,6 +26,7 @@
  * Michael Giagnocavo <mgg@giagnocavo.net>
  * David Brazier <David.Brazier@360crm.co.uk>
  * Jeff Lenk <jlenk@frontiernet.net> 
+ * Artur Kraev <ravenox@gmail.com>
  *
  * mod_mono.cpp -- FreeSWITCH mod_mono main class
  *
@@ -73,14 +74,13 @@ 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;
+static executeFunction listDelegate;
 
-SWITCH_MOD_DECLARE_NONSTD(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, reloadFunction reload, listFunction list) 
+SWITCH_MOD_DECLARE_NONSTD(void) InitManagedDelegates(runFunction run, executeFunction execute, executeBackgroundFunction executeBackground, reloadFunction reload, executeFunction list)
 {
        runDelegate = run;
        executeDelegate = execute;
@@ -451,7 +451,7 @@ SWITCH_STANDARD_API(managedlist_api_function)
 #ifndef _MANAGED
        mono_thread_attach(globals.domain);
 #endif
-       listDelegate(cmd);
+       listDelegate(cmd, stream, stream->param_event);
 #ifndef _MANAGED
        mono_thread_detach(mono_thread_current());
 #endif