]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
The difference now, is that this actually works
authorMichael Giagnocavo <mgg@giagnocavo.net>
Thu, 2 Oct 2008 20:02:31 +0000 (20:02 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Thu, 2 Oct 2008 20:02:31 +0000 (20:02 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9802 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_managed/freeswitch_managed.cpp
src/mod/languages/mod_managed/freeswitch_managed.h
src/mod/languages/mod_managed/managed/ManagedSession.cs
src/mod/languages/mod_managed/mod_managed.cpp

index 583051cf1c8c7bd593aa2e3205200a855e012306..da3b601d0a823a1b3db7ce72ae82eec35f692d0c 100644 (file)
@@ -128,14 +128,6 @@ ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(sessi
 ManagedSession::~ManagedSession() \r
 {\r
        mono_thread_attach(globals.domain);\r
-               \r
-       if (dtmfDelegateHandle) {\r
-               mono_gchandle_free(dtmfDelegateHandle);\r
-       }\r
-               \r
-       if (hangupDelegateHandle) {\r
-               mono_gchandle_free(hangupDelegateHandle);\r
-       }\r
 \r
        // Do auto-hangup ourselves because CoreSession can't call check_hangup_hook \r
        // after ManagedSession destruction (cause at point it's pure virtual)\r
@@ -163,46 +155,19 @@ bool ManagedSession::end_allow_threads()
 void ManagedSession::check_hangup_hook() \r
 {\r
        mono_thread_attach(globals.domain);\r
-       if (!hangupDelegateHandle) {\r
-               return;\r
-       }\r
-               \r
-       MonoObject * hangupDelegate = mono_gchandle_get_target(hangupDelegateHandle);\r
        if (!hangupDelegate) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");\r
                return;\r
        }\r
-               \r
-       MonoObject * ex = NULL;\r
-       mono_runtime_delegate_invoke(hangupDelegate, NULL, &ex);\r
-       if (ex) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegate threw an exception.");\r
-       }\r
+       hangupDelegate();\r
 }\r
 \r
 switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) \r
 {\r
        mono_thread_attach(globals.domain);\r
-       if (!dtmfDelegateHandle) {\r
-               return SWITCH_STATUS_SUCCESS;\r
-       }\r
-       MonoObject * dtmfDelegate = mono_gchandle_get_target(dtmfDelegateHandle);\r
        if (!dtmfDelegate) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");\r
                return SWITCH_STATUS_SUCCESS;\r
        }\r
-       \r
-       void *args[2];\r
-       args[0] = &input;\r
-       args[1] = &itype;\r
-       MonoObject * ex = NULL;\r
-       MonoObject * res = mono_runtime_delegate_invoke(dtmfDelegate, args, &ex);\r
-       if (ex) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegate threw an exception.");\r
-               return SWITCH_STATUS_FALSE;\r
-       }\r
-\r
-       char *resPtr = mono_string_to_utf8((MonoString *) res);\r
+       char *resPtr = dtmfDelegate(input, itype);\r
        switch_status_t status = process_callback_result(resPtr);\r
        g_free(resPtr);\r
        return status;\r
index b5f64c8d5f29506d38458f69c718ce1426d1a272..331a50a9e9e5affff1fabbe94c4b9f1fbe569fd2 100644 (file)
@@ -38,6 +38,9 @@ SWITCH_BEGIN_EXTERN_C
 #include <switch.h>\r
 #include <switch_cpp.h>\r
 \r
+typedef void (*hangupFunction)(void);\r
+typedef char* (*inputFunction)(void*, switch_input_type_t);\r
+\r
 #ifndef _MANAGED\r
 // this section remove linker error LNK4248 for these opaque structures\r
        struct switch_core_session {char foo[];};\r
@@ -99,9 +102,6 @@ using namespace System;
 using namespace System::Reflection;\r
 using namespace System::Runtime::InteropServices;\r
 \r
-typedef void (*hangupFunction)(void);\r
-typedef char* (*inputFunction)(void*, switch_input_type_t);\r
-\r
 public ref class FreeSwitchManaged\r
 {\r
 public:\r
@@ -129,15 +129,9 @@ public:
 \r
        virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);\r
 \r
-#ifdef _MANAGED\r
        // P/Invoke function pointer to delegates\r
        inputFunction dtmfDelegate; \r
        hangupFunction hangupDelegate; \r
-#else\r
-       guint32 dtmfDelegateHandle; // GCHandle to the input delegate \r
-       guint32 hangupDelegateHandle; // GCHandle to the hangup delegate\r
-#endif\r
-\r
 };\r
 \r
 #endif
\ No newline at end of file
index 5561673aefc156d217f35e3c77beab4fed892e1b..a55772822053128489c62df00f2185a2f3fe00f0 100644 (file)
@@ -32,16 +32,18 @@ using System;
 using System.Collections.Generic;\r
 using System.Linq;\r
 using System.Text;\r
+using System.Runtime.InteropServices;\r
 \r
 namespace FreeSWITCH.Native\r
 {\r
     // switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype)\r
     // But, process_callback_result is used to turn a string into a switch_status_t\r
-    using DtmfCallback = Func<IntPtr, Native.switch_input_type_t, string>;\r
+    //using DtmfCallback = Func<IntPtr, Native.switch_input_type_t, string>;\r
+    delegate string DtmfCallback(IntPtr input, Native.switch_input_type_t itype);\r
     public partial class ManagedSession\r
     {\r
         // SWITCH_DECLARE(void) InitManagedSession(ManagedSession *session, MonoObject *dtmfDelegate, MonoObject *hangupDelegate)\r
-        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]\r
+        [DllImport("mod_managed.dll", CharSet = CharSet.Ansi)]\r
         static extern void InitManagedSession(IntPtr sessionPtr, DtmfCallback dtmfDelegate, Action hangupDelegate);\r
 \r
         /// <summary>Initializes the native ManagedSession. Must be called after Originate.</summary>\r
index 1f19e4a10542068df5c0f755f3e92a40465581b5..8425d3db70bf3308e9a4370248261951ea2490b3 100644 (file)
@@ -80,7 +80,7 @@ mod_mono_globals globals =
 \r
 // Sets up delegates (and anything else needed) on the ManagedSession object\r
 // Called via internalcall\r
-SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, MonoObject * dtmfDelegate, MonoObject * hangupDelegate) \r
+SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, inputFunction dtmfDelegate, hangupFunction hangupDelegate) \r
 {\r
        switch_assert(session);\r
        if (!session) {\r
@@ -88,8 +88,8 @@ SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, MonoObject
        }\r
        session->setDTMFCallback(NULL, "");\r
        session->setHangupHook(NULL);\r
-       session->dtmfDelegateHandle = mono_gchandle_new(dtmfDelegate, FALSE);\r
-       session->hangupDelegateHandle = mono_gchandle_new(hangupDelegate, FALSE);\r
+       session->dtmfDelegate = dtmfDelegate;\r
+       session->hangupDelegate = hangupDelegate;\r
 }\r
 \r
 switch_status_t setMonoDirs() \r
@@ -283,8 +283,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_managed_load)
        /* Not sure if this is necesary on the loading thread */ \r
        mono_thread_attach(globals.domain);\r
 \r
-       mono_add_internal_call("FreeSWITCH.Native.ManagedSession::InitManagedSession", (void *)InitManagedSession);\r
-\r
        /* Run loader */ \r
        MonoObject * objResult;\r
        MonoObject * exception = NULL;\r