From b32e3e611c74899a6a4a4d1bf9f1dc5f002b4439 Mon Sep 17 00:00:00 2001 From: Michael Giagnocavo Date: Sat, 4 Oct 2008 04:14:11 +0000 Subject: [PATCH] Unified Mono and CLR in freeswitch_managed git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9819 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/languages/mod_managed/freeswitch.i | 6 +- .../mod_managed/freeswitch_managed.cpp | 102 +++++------------- 2 files changed, 27 insertions(+), 81 deletions(-) diff --git a/src/mod/languages/mod_managed/freeswitch.i b/src/mod/languages/mod_managed/freeswitch.i index e9d9ed65a2..5c021d78e0 100644 --- a/src/mod/languages/mod_managed/freeswitch.i +++ b/src/mod/languages/mod_managed/freeswitch.i @@ -39,11 +39,10 @@ %typemap(csclassmodifiers) switch_xml_flag_t "[System.Flags] public enum" %typemap(csclassmodifiers) switch_xml_section_enum_t "[System.Flags] public enum" - // Some things we dont want exposed to managed users directly, since // we're gonna handle them with our own internalcall methods -%ignore dtmfDelegateHandle; -%ignore hangupDelegateHandle; +%ignore dtmfDelegate; +%ignore hangupDelegate; %ignore setHangupHook; %ignore beginAllowThreads; %ignore endAllowThreads; @@ -114,6 +113,7 @@ %include switch.h %include switch_types.h +//%include switch_apr.h %include switch_core_db.h %include switch_regex.h diff --git a/src/mod/languages/mod_managed/freeswitch_managed.cpp b/src/mod/languages/mod_managed/freeswitch_managed.cpp index da3b601d0a..8485def149 100644 --- a/src/mod/languages/mod_managed/freeswitch_managed.cpp +++ b/src/mod/languages/mod_managed/freeswitch_managed.cpp @@ -45,6 +45,10 @@ #include "freeswitch_managed.h" #ifdef _MANAGED +#define ATTACH_THREADS +#else +#define ATTACH_THREADS mono_thread_attach(globals.domain); +#endif ManagedSession::ManagedSession():CoreSession() { @@ -61,8 +65,20 @@ ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(sessi } +bool ManagedSession::begin_allow_threads() +{ + return true; +} + +bool ManagedSession::end_allow_threads() +{ + return true; +} + + ManagedSession::~ManagedSession() { + ATTACH_THREADS // Do auto-hangup ourselves because CoreSession can't call check_hangup_hook // after ManagedSession destruction (cause at point it's pure virtual) if (session) { @@ -76,20 +92,11 @@ ManagedSession::~ManagedSession() } } -bool ManagedSession::begin_allow_threads() -{ - return true; -} - -bool ManagedSession::end_allow_threads() -{ - return true; -} - void ManagedSession::check_hangup_hook() { + ATTACH_THREADS if (!hangupDelegate) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object."); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hangupDelegate is null."); return; } hangupDelegate(); @@ -97,80 +104,19 @@ void ManagedSession::check_hangup_hook() switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) { + ATTACH_THREADS if (!dtmfDelegate) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object."); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "dtmfDelegate is null."); return SWITCH_STATUS_FALSE;; } char *result = dtmfDelegate(input, itype); - switch_status_t status = process_callback_result(result); - Marshal::FreeCoTaskMem(IntPtr(result)); // I think this is right - return status; -} +#if WIN32 + CoTaskMemFree(result); #else - -ManagedSession::ManagedSession():CoreSession() -{ - -} - -ManagedSession::ManagedSession(char *uuid):CoreSession(uuid) -{ - -} - -ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(session) -{ - -} - -ManagedSession::~ManagedSession() -{ - mono_thread_attach(globals.domain); - - // Do auto-hangup ourselves because CoreSession can't call check_hangup_hook - // after ManagedSession destruction (cause at point it's pure virtual) - if (session) { - channel = switch_core_session_get_channel(session); - if (switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) { - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - setAutoHangup(0); - } - // Don't let any callbacks use this CoreSession anymore - switch_channel_set_private(channel, "CoreSession", NULL); - } -} - -bool ManagedSession::begin_allow_threads() -{ - return true; -} - -bool ManagedSession::end_allow_threads() -{ - return true; -} - -void ManagedSession::check_hangup_hook() -{ - mono_thread_attach(globals.domain); - if (!hangupDelegate) { - return; - } - hangupDelegate(); -} - -switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) -{ - mono_thread_attach(globals.domain); - if (!dtmfDelegate) { - return SWITCH_STATUS_SUCCESS; - } - char *resPtr = dtmfDelegate(input, itype); - switch_status_t status = process_callback_result(resPtr); - g_free(resPtr); + g_free(result) +#endif return status; } -#endif