From ddd1ae14b733151a8134ee734f0876d1dded4788 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 15 Sep 2008 21:44:43 +0000 Subject: [PATCH] add session destroy psuedo method to sort of destroy a session at least for the sake of FS git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9571 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_cpp.h | 2 + .../src/org/freeswitch/swig/CoreSession.java | 4 ++ .../org/freeswitch/swig/freeswitchJNI.java | 1 + .../languages/mod_java/switch_swig_wrap.cpp | 11 ++++++ src/mod/languages/mod_lua/mod_lua_wrap.cpp | 25 ++++++++++++ src/mod/languages/mod_perl/freeswitch.pm | 1 + src/mod/languages/mod_perl/mod_perl_wrap.cpp | 28 ++++++++++++++ src/mod/languages/mod_python/freeswitch.py | 1 + .../languages/mod_python/mod_python_wrap.cpp | 22 +++++++++++ src/switch_cpp.cpp | 38 +++++++++++-------- 10 files changed, 118 insertions(+), 15 deletions(-) diff --git a/src/include/switch_cpp.h b/src/include/switch_cpp.h index 58f46eafaf..f799c57ce0 100644 --- a/src/include/switch_cpp.h +++ b/src/include/switch_cpp.h @@ -254,6 +254,8 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg); SWITCH_DECLARE(int) originate(CoreSession * a_leg_session, char *dest, int timeout = 60); + SWITCH_DECLARE(void) destroy(void); + /** \brief set a DTMF callback function * * The DTMF callback function will be set and persist diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java index 3519d69898..fd2f6f0294 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java @@ -189,6 +189,10 @@ public class CoreSession { return freeswitchJNI.CoreSession_originate__SWIG_1(swigCPtr, this, CoreSession.getCPtr(a_leg_session), a_leg_session, dest); } + public void destroy() { + freeswitchJNI.CoreSession_destroy(swigCPtr, this); + } + public void setDTMFCallback(SWIGTYPE_p_void cbfunc, String funcargs) { freeswitchJNI.CoreSession_setDTMFCallback(swigCPtr, this, SWIGTYPE_p_void.getCPtr(cbfunc), funcargs); } diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java index 9fbb64bb47..20b5dd5913 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java @@ -122,6 +122,7 @@ class freeswitchJNI { public final static native void CoreSession_setCallerData(long jarg1, CoreSession jarg1_, String jarg2, String jarg3); public final static native int CoreSession_originate__SWIG_0(long jarg1, CoreSession jarg1_, long jarg2, CoreSession jarg2_, String jarg3, int jarg4); public final static native int CoreSession_originate__SWIG_1(long jarg1, CoreSession jarg1_, long jarg2, CoreSession jarg2_, String jarg3); + public final static native void CoreSession_destroy(long jarg1, CoreSession jarg1_); public final static native void CoreSession_setDTMFCallback(long jarg1, CoreSession jarg1_, long jarg2, String jarg3); public final static native int CoreSession_speak(long jarg1, CoreSession jarg1_, String jarg2); public final static native void CoreSession_set_tts_parms(long jarg1, CoreSession jarg1_, String jarg2, String jarg3); diff --git a/src/mod/languages/mod_java/switch_swig_wrap.cpp b/src/mod/languages/mod_java/switch_swig_wrap.cpp index 88ffa0af1b..942504dc5d 100644 --- a/src/mod/languages/mod_java/switch_swig_wrap.cpp +++ b/src/mod/languages/mod_java/switch_swig_wrap.cpp @@ -2304,6 +2304,17 @@ SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1orig } +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1destroy(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { + CoreSession *arg1 = (CoreSession *) 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(CoreSession **)&jarg1; + (arg1)->destroy(); +} + + SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1setDTMFCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jstring jarg3) { CoreSession *arg1 = (CoreSession *) 0 ; void *arg2 = (void *) 0 ; diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index c1c864fb79..bbb01e55ad 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -5405,6 +5405,30 @@ static int _wrap_CoreSession_originate(lua_State* L) { } +static int _wrap_CoreSession_destroy(lua_State* L) { + int SWIG_arg = -1; + CoreSession *arg1 = (CoreSession *) 0 ; + + SWIG_check_num_args("destroy",1,1) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("destroy",1,"CoreSession *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ + SWIG_fail_ptr("CoreSession_destroy",1,SWIGTYPE_p_CoreSession); + } + + (arg1)->destroy(); + SWIG_arg=0; + + return SWIG_arg; + + if(0) SWIG_fail; + +fail: + lua_error(L); + return SWIG_arg; +} + + static int _wrap_CoreSession_setDTMFCallback(lua_State* L) { int SWIG_arg = -1; CoreSession *arg1 = (CoreSession *) 0 ; @@ -6674,6 +6698,7 @@ static swig_lua_method swig_CoreSession_methods[] = { {"recordFile", _wrap_CoreSession_recordFile}, {"setCallerData", _wrap_CoreSession_setCallerData}, {"originate", _wrap_CoreSession_originate}, + {"destroy", _wrap_CoreSession_destroy}, {"setDTMFCallback", _wrap_CoreSession_setDTMFCallback}, {"speak", _wrap_CoreSession_speak}, {"set_tts_parms", _wrap_CoreSession_set_tts_parms}, diff --git a/src/mod/languages/mod_perl/freeswitch.pm b/src/mod/languages/mod_perl/freeswitch.pm index 3d1fbb805b..6b92a1ba03 100644 --- a/src/mod/languages/mod_perl/freeswitch.pm +++ b/src/mod/languages/mod_perl/freeswitch.pm @@ -410,6 +410,7 @@ sub DESTROY { *recordFile = *freeswitchc::CoreSession_recordFile; *setCallerData = *freeswitchc::CoreSession_setCallerData; *originate = *freeswitchc::CoreSession_originate; +*destroy = *freeswitchc::CoreSession_destroy; *setDTMFCallback = *freeswitchc::CoreSession_setDTMFCallback; *speak = *freeswitchc::CoreSession_speak; *set_tts_parms = *freeswitchc::CoreSession_set_tts_parms; diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index 0d606dd77a..900b725ae0 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -7030,6 +7030,33 @@ XS(_wrap_CoreSession_originate) { } +XS(_wrap_CoreSession_destroy) { + { + CoreSession *arg1 = (CoreSession *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: CoreSession_destroy(self);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_destroy" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + (arg1)->destroy(); + + + XSRETURN(argvi); + fail: + + SWIG_croak_null(); + } +} + + XS(_wrap_CoreSession_setDTMFCallback) { { CoreSession *arg1 = (CoreSession *) 0 ; @@ -10588,6 +10615,7 @@ static swig_command_info swig_commands[] = { {"freeswitchc::CoreSession_recordFile", _wrap_CoreSession_recordFile}, {"freeswitchc::CoreSession_setCallerData", _wrap_CoreSession_setCallerData}, {"freeswitchc::CoreSession_originate", _wrap_CoreSession_originate}, +{"freeswitchc::CoreSession_destroy", _wrap_CoreSession_destroy}, {"freeswitchc::CoreSession_setDTMFCallback", _wrap_CoreSession_setDTMFCallback}, {"freeswitchc::CoreSession_speak", _wrap_CoreSession_speak}, {"freeswitchc::CoreSession_set_tts_parms", _wrap_CoreSession_set_tts_parms}, diff --git a/src/mod/languages/mod_python/freeswitch.py b/src/mod/languages/mod_python/freeswitch.py index 720be0205b..01d8a88333 100644 --- a/src/mod/languages/mod_python/freeswitch.py +++ b/src/mod/languages/mod_python/freeswitch.py @@ -268,6 +268,7 @@ class CoreSession(_object): def recordFile(*args): return _freeswitch.CoreSession_recordFile(*args) def setCallerData(*args): return _freeswitch.CoreSession_setCallerData(*args) def originate(*args): return _freeswitch.CoreSession_originate(*args) + def destroy(*args): return _freeswitch.CoreSession_destroy(*args) def setDTMFCallback(*args): return _freeswitch.CoreSession_setDTMFCallback(*args) def speak(*args): return _freeswitch.CoreSession_speak(*args) def set_tts_parms(*args): return _freeswitch.CoreSession_set_tts_parms(*args) diff --git a/src/mod/languages/mod_python/mod_python_wrap.cpp b/src/mod/languages/mod_python/mod_python_wrap.cpp index 60155d014b..79a30dcdad 100644 --- a/src/mod/languages/mod_python/mod_python_wrap.cpp +++ b/src/mod/languages/mod_python/mod_python_wrap.cpp @@ -7131,6 +7131,27 @@ fail: } +SWIGINTERN PyObject *_wrap_CoreSession_destroy(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:CoreSession_destroy",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_destroy" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + (arg1)->destroy(); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_CoreSession_setDTMFCallback(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; @@ -9639,6 +9660,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"CoreSession_recordFile", _wrap_CoreSession_recordFile, METH_VARARGS, NULL}, { (char *)"CoreSession_setCallerData", _wrap_CoreSession_setCallerData, METH_VARARGS, NULL}, { (char *)"CoreSession_originate", _wrap_CoreSession_originate, METH_VARARGS, NULL}, + { (char *)"CoreSession_destroy", _wrap_CoreSession_destroy, METH_VARARGS, NULL}, { (char *)"CoreSession_setDTMFCallback", _wrap_CoreSession_setDTMFCallback, METH_VARARGS, NULL}, { (char *)"CoreSession_speak", _wrap_CoreSession_speak, METH_VARARGS, NULL}, { (char *)"CoreSession_set_tts_parms", _wrap_CoreSession_set_tts_parms, METH_VARARGS, NULL}, diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index 7b81769b54..a2aa3d64fe 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -459,22 +459,8 @@ SWITCH_DECLARE_CONSTRUCTOR CoreSession::CoreSession(switch_core_session_t *new_s SWITCH_DECLARE_CONSTRUCTOR CoreSession::~CoreSession() { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CoreSession::~CoreSession desctructor\n"); - switch_channel_t *channel = NULL; - this_check_void(); - switch_safe_free(xml_cdr_text); - switch_safe_free(uuid); - switch_safe_free(tts_name); - switch_safe_free(voice_name); - - 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); - } - switch_core_session_rwunlock(session); - } + destroy(); } SWITCH_DECLARE(char *) CoreSession::getXMLCDR() @@ -850,6 +836,28 @@ SWITCH_DECLARE(bool) CoreSession::answered() { return switch_channel_test_flag(channel, CF_ANSWERED) != 0; } +SWITCH_DECLARE(void) CoreSession::destroy(void) +{ + this_check_void(); + + switch_safe_free(xml_cdr_text); + switch_safe_free(uuid); + switch_safe_free(tts_name); + switch_safe_free(voice_name); + + if (session) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "destroy/unlink session from object\n"); + if (switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) { + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + } + switch_core_session_rwunlock(session); + session = NULL; + } + + allocated = 0; + +} + SWITCH_DECLARE(int) CoreSession::originate(CoreSession *a_leg_session, char *dest, int timeout) {