]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Hack patch to avoid hanguphook calling check_hangup_hook purely virtually
authorMichael Giagnocavo <mgg@giagnocavo.net>
Mon, 9 Jun 2008 00:09:42 +0000 (00:09 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Mon, 9 Jun 2008 00:09:42 +0000 (00:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8789 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_mono/freeswitch_mono.cpp

index 91448e831c2f99f6e159750c16acacb3ffea7529..e28fb5ad244c5365920c636da3cf19fd064d9d2a 100644 (file)
 #include <mono/metadata/threads.h>\r
 #include <mono/metadata/metadata.h>\r
 #include "freeswitch_mono.h"\r
-\rMonoSession::MonoSession():CoreSession() \r
-{
-\r\r\rMonoSession::MonoSession(char *uuid):CoreSession(uuid) \r
-{
-\r\r\rMonoSession::MonoSession(switch_core_session_t *session):CoreSession(session) \r
-{
-\r\r\rMonoSession::~MonoSession() \r
-{
-       \rmono_thread_attach(globals.domain);
-       \rif (dtmfDelegateHandle)
-               mono_gchandle_free(dtmfDelegateHandle);
-       \rif (hangupDelegateHandle)
-               mono_gchandle_free(hangupDelegateHandle);
-\r}
-
-\r\rbool MonoSession::begin_allow_threads() \r
-{
-       \rreturn true;
-\r}
-
-\r\rbool MonoSession::end_allow_threads() \r
-{
-       \rreturn true;
-\r}
-\r\rvoid MonoSession::check_hangup_hook() \r
-{
-       \rmono_thread_attach(globals.domain);
-       \rif (!hangupDelegateHandle) {
-               \rreturn;
-       \r}
-       \rMonoObject * hangupDelegate = mono_gchandle_get_target(hangupDelegateHandle);
-       \rif (!hangupDelegate) {
-               \rswitch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");
-               \rreturn;
-       \r}
-       \rMonoObject * ex = NULL;
-       \rmono_runtime_delegate_invoke(hangupDelegate, NULL, &ex);
-       \rif (ex) {
-               \rswitch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegate threw an exception.");
-       \r}
-\r}
-\r\rswitch_status_t MonoSession::run_dtmf_callback(void *input, switch_input_type_t itype) \r
-{
-       \rmono_thread_attach(globals.domain);
-       \rif (!dtmfDelegateHandle) {
-               \rreturn SWITCH_STATUS_SUCCESS;
-       \r}
-       \rMonoObject * dtmfDelegate = mono_gchandle_get_target(dtmfDelegateHandle);
-       \rif (!dtmfDelegate) {
-               \rswitch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");
-               \rreturn SWITCH_STATUS_SUCCESS;
-       \r}
-       \rvoid *args[2];
-       \rargs[0] = &input;
-       \rargs[1] = &itype;
-       \rMonoObject * ex = NULL;
-       \rMonoObject * res = mono_runtime_delegate_invoke(dtmfDelegate, args, &ex);
-       \rif (ex) {
-               \rswitch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegate threw an exception.");
-               \rreturn SWITCH_STATUS_FALSE;
-       \r}
-       \rchar *resPtr = mono_string_to_utf8((MonoString *) res);
-       \rswitch_status_t status = process_callback_result(resPtr);
-       \r\rg_free(resPtr);
-       \rreturn status;
-\r}
-
+\r
+MonoSession::MonoSession():CoreSession() \r
+{\r
+\r
+} \r
+\r
+MonoSession::MonoSession(char *uuid):CoreSession(uuid) \r
+{\r
+\r
+} \r
+\r
+MonoSession::MonoSession(switch_core_session_t *session):CoreSession(session) \r
+{\r
+\r
+} \r
+\r
+MonoSession::~MonoSession() \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 MonoSession 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
+       }\r
+}\r
+\r
+\r
+\r
+bool MonoSession::begin_allow_threads() \r
+{\r
+       return true;\r
+}\r
+\r
+\r
+\r
+bool MonoSession::end_allow_threads() \r
+{\r
+       return true;\r
+}\r
+\r
+\r
+void MonoSession::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
+}\r
+\r
+\r
+switch_status_t MonoSession::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
+       switch_status_t status = process_callback_result(resPtr);\r
+       g_free(resPtr);\r
+       return status;\r
+}\r
+\r
 \r