]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Unified Mono and CLR in freeswitch_managed
authorMichael Giagnocavo <mgg@giagnocavo.net>
Sat, 4 Oct 2008 04:14:11 +0000 (04:14 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Sat, 4 Oct 2008 04:14:11 +0000 (04:14 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9819 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_managed/freeswitch.i
src/mod/languages/mod_managed/freeswitch_managed.cpp

index e9d9ed65a2a1ad6402a6f19441fea8318f2cf834..5c021d78e060f0dec94e6ed924617eca257b4a69 100644 (file)
 %typemap(csclassmodifiers) switch_xml_flag_t  "[System.Flags] public enum"\r
 %typemap(csclassmodifiers) switch_xml_section_enum_t  "[System.Flags] public enum"\r
 \r
-\r
 // Some things we dont want exposed to managed users directly, since \r
 // we're gonna handle them with our own internalcall methods\r
-%ignore dtmfDelegateHandle;\r
-%ignore hangupDelegateHandle;\r
+%ignore dtmfDelegate;\r
+%ignore hangupDelegate;\r
 %ignore setHangupHook;\r
 %ignore beginAllowThreads;\r
 %ignore endAllowThreads;\r
 \r
 %include switch.h\r
 %include switch_types.h\r
+//%include switch_apr.h\r
 \r
 %include switch_core_db.h\r
 %include switch_regex.h\r
index da3b601d0a823a1b3db7ce72ae82eec35f692d0c..8485def149b475f65b0d798ff3426bf32513d92e 100644 (file)
 #include "freeswitch_managed.h"\r
 \r
 #ifdef _MANAGED\r
+#define ATTACH_THREADS\r
+#else\r
+#define ATTACH_THREADS mono_thread_attach(globals.domain);\r
+#endif\r
 \r
 ManagedSession::ManagedSession():CoreSession() \r
 {\r
@@ -61,21 +65,6 @@ ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(sessi
 \r
 } \r
 \r
-ManagedSession::~ManagedSession() \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
-       if (session) {\r
-               channel = switch_core_session_get_channel(session);\r
-               if (switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) {\r
-                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);\r
-                       setAutoHangup(0);\r
-               }\r
-               // Don't let any callbacks use this CoreSession anymore\r
-               switch_channel_set_private(channel, "CoreSession", NULL);\r
-       }\r
-}\r
-\r
 bool ManagedSession::begin_allow_threads() \r
 {\r
        return true;\r
@@ -86,49 +75,10 @@ bool ManagedSession::end_allow_threads()
        return true;\r
 }\r
 \r
-void ManagedSession::check_hangup_hook() \r
-{\r
-       if (!hangupDelegate) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");\r
-               return;\r
-       }\r
-       hangupDelegate();\r
-}\r
-\r
-switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) \r
-{\r
-       if (!dtmfDelegate) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");\r
-               return SWITCH_STATUS_FALSE;;\r
-       }\r
-       char *result = dtmfDelegate(input, itype);\r
-\r
-       switch_status_t status = process_callback_result(result);\r
-       Marshal::FreeCoTaskMem(IntPtr(result)); // I think this is right\r
-       return status;\r
-}\r
-\r
-#else\r
-\r
-ManagedSession::ManagedSession():CoreSession() \r
-{\r
-\r
-} \r
-\r
-ManagedSession::ManagedSession(char *uuid):CoreSession(uuid) \r
-{\r
-\r
-} \r
-\r
-ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(session) \r
-{\r
-\r
-} \r
 \r
 ManagedSession::~ManagedSession() \r
 {\r
-       mono_thread_attach(globals.domain);\r
-\r
+       ATTACH_THREADS\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
        if (session) {\r
@@ -142,20 +92,11 @@ ManagedSession::~ManagedSession()
        }\r
 }\r
 \r
-bool ManagedSession::begin_allow_threads() \r
-{\r
-       return true;\r
-}\r
-\r
-bool ManagedSession::end_allow_threads() \r
-{\r
-       return true;\r
-}\r
-\r
 void ManagedSession::check_hangup_hook() \r
 {\r
-       mono_thread_attach(globals.domain);\r
+       ATTACH_THREADS\r
        if (!hangupDelegate) {\r
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hangupDelegate is null.");\r
                return;\r
        }\r
        hangupDelegate();\r
@@ -163,14 +104,19 @@ void ManagedSession::check_hangup_hook()
 \r
 switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) \r
 {\r
-       mono_thread_attach(globals.domain);\r
+       ATTACH_THREADS\r
        if (!dtmfDelegate) {\r
-               return SWITCH_STATUS_SUCCESS;\r
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "dtmfDelegate is null.");\r
+               return SWITCH_STATUS_FALSE;;\r
        }\r
-       char *resPtr = dtmfDelegate(input, itype);\r
-       switch_status_t status = process_callback_result(resPtr);\r
-       g_free(resPtr);\r
+       char *result = dtmfDelegate(input, itype);\r
+       switch_status_t status = process_callback_result(result);\r
+\r
+#if WIN32\r
+       CoTaskMemFree(result); \r
+#else\r
+       g_free(result)\r
+#endif\r
        return status;\r
 }\r
 \r
-#endif\r