mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-04 18:27:36 +00:00
The difference now, is that this actually works
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9802 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
40fd65e713
commit
886b02710e
@ -128,14 +128,6 @@ ManagedSession::ManagedSession(switch_core_session_t *session):CoreSession(sessi
|
||||
ManagedSession::~ManagedSession()
|
||||
{
|
||||
mono_thread_attach(globals.domain);
|
||||
|
||||
if (dtmfDelegateHandle) {
|
||||
mono_gchandle_free(dtmfDelegateHandle);
|
||||
}
|
||||
|
||||
if (hangupDelegateHandle) {
|
||||
mono_gchandle_free(hangupDelegateHandle);
|
||||
}
|
||||
|
||||
// Do auto-hangup ourselves because CoreSession can't call check_hangup_hook
|
||||
// after ManagedSession destruction (cause at point it's pure virtual)
|
||||
@ -163,46 +155,19 @@ bool ManagedSession::end_allow_threads()
|
||||
void ManagedSession::check_hangup_hook()
|
||||
{
|
||||
mono_thread_attach(globals.domain);
|
||||
if (!hangupDelegateHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
MonoObject * hangupDelegate = mono_gchandle_get_target(hangupDelegateHandle);
|
||||
if (!hangupDelegate) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");
|
||||
return;
|
||||
}
|
||||
|
||||
MonoObject * ex = NULL;
|
||||
mono_runtime_delegate_invoke(hangupDelegate, NULL, &ex);
|
||||
if (ex) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegate threw an exception.");
|
||||
}
|
||||
hangupDelegate();
|
||||
}
|
||||
|
||||
switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype)
|
||||
{
|
||||
mono_thread_attach(globals.domain);
|
||||
if (!dtmfDelegateHandle) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
MonoObject * dtmfDelegate = mono_gchandle_get_target(dtmfDelegateHandle);
|
||||
if (!dtmfDelegate) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void *args[2];
|
||||
args[0] = &input;
|
||||
args[1] = &itype;
|
||||
MonoObject * ex = NULL;
|
||||
MonoObject * res = mono_runtime_delegate_invoke(dtmfDelegate, args, &ex);
|
||||
if (ex) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegate threw an exception.");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
char *resPtr = mono_string_to_utf8((MonoString *) res);
|
||||
char *resPtr = dtmfDelegate(input, itype);
|
||||
switch_status_t status = process_callback_result(resPtr);
|
||||
g_free(resPtr);
|
||||
return status;
|
||||
|
@ -38,6 +38,9 @@ SWITCH_BEGIN_EXTERN_C
|
||||
#include <switch.h>
|
||||
#include <switch_cpp.h>
|
||||
|
||||
typedef void (*hangupFunction)(void);
|
||||
typedef char* (*inputFunction)(void*, switch_input_type_t);
|
||||
|
||||
#ifndef _MANAGED
|
||||
// this section remove linker error LNK4248 for these opaque structures
|
||||
struct switch_core_session {char foo[];};
|
||||
@ -99,9 +102,6 @@ using namespace System;
|
||||
using namespace System::Reflection;
|
||||
using namespace System::Runtime::InteropServices;
|
||||
|
||||
typedef void (*hangupFunction)(void);
|
||||
typedef char* (*inputFunction)(void*, switch_input_type_t);
|
||||
|
||||
public ref class FreeSwitchManaged
|
||||
{
|
||||
public:
|
||||
@ -129,15 +129,9 @@ public:
|
||||
|
||||
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
|
||||
|
||||
#ifdef _MANAGED
|
||||
// P/Invoke function pointer to delegates
|
||||
inputFunction dtmfDelegate;
|
||||
hangupFunction hangupDelegate;
|
||||
#else
|
||||
guint32 dtmfDelegateHandle; // GCHandle to the input delegate
|
||||
guint32 hangupDelegateHandle; // GCHandle to the hangup delegate
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -32,16 +32,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FreeSWITCH.Native
|
||||
{
|
||||
// switch_status_t ManagedSession::run_dtmf_callback(void *input, switch_input_type_t itype)
|
||||
// But, process_callback_result is used to turn a string into a switch_status_t
|
||||
using DtmfCallback = Func<IntPtr, Native.switch_input_type_t, string>;
|
||||
//using DtmfCallback = Func<IntPtr, Native.switch_input_type_t, string>;
|
||||
delegate string DtmfCallback(IntPtr input, Native.switch_input_type_t itype);
|
||||
public partial class ManagedSession
|
||||
{
|
||||
// SWITCH_DECLARE(void) InitManagedSession(ManagedSession *session, MonoObject *dtmfDelegate, MonoObject *hangupDelegate)
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
|
||||
[DllImport("mod_managed.dll", CharSet = CharSet.Ansi)]
|
||||
static extern void InitManagedSession(IntPtr sessionPtr, DtmfCallback dtmfDelegate, Action hangupDelegate);
|
||||
|
||||
/// <summary>Initializes the native ManagedSession. Must be called after Originate.</summary>
|
||||
|
@ -80,7 +80,7 @@ mod_mono_globals globals =
|
||||
|
||||
// Sets up delegates (and anything else needed) on the ManagedSession object
|
||||
// Called via internalcall
|
||||
SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, MonoObject * dtmfDelegate, MonoObject * hangupDelegate)
|
||||
SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, inputFunction dtmfDelegate, hangupFunction hangupDelegate)
|
||||
{
|
||||
switch_assert(session);
|
||||
if (!session) {
|
||||
@ -88,8 +88,8 @@ SWITCH_MOD_DECLARE(void) InitManagedSession(ManagedSession * session, MonoObject
|
||||
}
|
||||
session->setDTMFCallback(NULL, "");
|
||||
session->setHangupHook(NULL);
|
||||
session->dtmfDelegateHandle = mono_gchandle_new(dtmfDelegate, FALSE);
|
||||
session->hangupDelegateHandle = mono_gchandle_new(hangupDelegate, FALSE);
|
||||
session->dtmfDelegate = dtmfDelegate;
|
||||
session->hangupDelegate = hangupDelegate;
|
||||
}
|
||||
|
||||
switch_status_t setMonoDirs()
|
||||
@ -283,8 +283,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_managed_load)
|
||||
/* Not sure if this is necesary on the loading thread */
|
||||
mono_thread_attach(globals.domain);
|
||||
|
||||
mono_add_internal_call("FreeSWITCH.Native.ManagedSession::InitManagedSession", (void *)InitManagedSession);
|
||||
|
||||
/* Run loader */
|
||||
MonoObject * objResult;
|
||||
MonoObject * exception = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user