Unified Mono and CLR in freeswitch_managed

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9819 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Giagnocavo 2008-10-04 04:14:11 +00:00
parent 20336f5862
commit b32e3e611c
2 changed files with 27 additions and 81 deletions

View File

@ -39,11 +39,10 @@
%typemap(csclassmodifiers) switch_xml_flag_t "[System.Flags] public enum" %typemap(csclassmodifiers) switch_xml_flag_t "[System.Flags] public enum"
%typemap(csclassmodifiers) switch_xml_section_enum_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 // Some things we dont want exposed to managed users directly, since
// we're gonna handle them with our own internalcall methods // we're gonna handle them with our own internalcall methods
%ignore dtmfDelegateHandle; %ignore dtmfDelegate;
%ignore hangupDelegateHandle; %ignore hangupDelegate;
%ignore setHangupHook; %ignore setHangupHook;
%ignore beginAllowThreads; %ignore beginAllowThreads;
%ignore endAllowThreads; %ignore endAllowThreads;
@ -114,6 +113,7 @@
%include switch.h %include switch.h
%include switch_types.h %include switch_types.h
//%include switch_apr.h
%include switch_core_db.h %include switch_core_db.h
%include switch_regex.h %include switch_regex.h

View File

@ -45,6 +45,10 @@
#include "freeswitch_managed.h" #include "freeswitch_managed.h"
#ifdef _MANAGED #ifdef _MANAGED
#define ATTACH_THREADS
#else
#define ATTACH_THREADS mono_thread_attach(globals.domain);
#endif
ManagedSession::ManagedSession():CoreSession() 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() ManagedSession::~ManagedSession()
{ {
ATTACH_THREADS
// Do auto-hangup ourselves because CoreSession can't call check_hangup_hook // Do auto-hangup ourselves because CoreSession can't call check_hangup_hook
// after ManagedSession destruction (cause at point it's pure virtual) // after ManagedSession destruction (cause at point it's pure virtual)
if (session) { 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() void ManagedSession::check_hangup_hook()
{ {
ATTACH_THREADS
if (!hangupDelegate) { 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; return;
} }
hangupDelegate(); hangupDelegate();
@ -97,80 +104,19 @@ void ManagedSession::check_hangup_hook()
switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype) switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype)
{ {
ATTACH_THREADS
if (!dtmfDelegate) { 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;; return SWITCH_STATUS_FALSE;;
} }
char *result = dtmfDelegate(input, itype); char *result = dtmfDelegate(input, itype);
switch_status_t status = process_callback_result(result); switch_status_t status = process_callback_result(result);
Marshal::FreeCoTaskMem(IntPtr(result)); // I think this is right
return status;
}
#if WIN32
CoTaskMemFree(result);
#else #else
g_free(result)
ManagedSession::ManagedSession():CoreSession() #endif
{
}
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);
return status; return status;
} }
#endif