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
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
#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
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
\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
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
\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
}\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
/* 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