forked from Mirrors/freeswitch
Cleaning for the new code
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6223 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
77405bd53e
commit
a9101cb8c1
@ -1,35 +0,0 @@
|
||||
AM_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||
AM_CPPFLAGS = $(SWITCH_AM_CXXFLAGS)
|
||||
AM_LDFLAGS = $(SWITCH_AM_LDFLAGS)
|
||||
#we should set all these vars from configure, no reason to have these in each Makefile.am
|
||||
LIBTOOL = echo "`link=\`echo $@|grep .la;echo $@|grep .so;echo $@|grep .dll\`;if test -n "$$link"; then echo Creating $@;fi`";`if test -z "$(VERBOSE)" ; \
|
||||
then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(SHELL) $(switch_builddir)/libtool; fi`
|
||||
AM_MAKEFLAGS=`test -n "$(VERBOSE)" || echo -s`
|
||||
# Dirty trick to override the link output
|
||||
LIBS+=> $(MODNAME).log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat $(MODNAME).log;fi;if test "$$error" = "yes";then exit 1;fi
|
||||
|
||||
moddir=$(prefix)/mod
|
||||
|
||||
MODNAME=mod_opal
|
||||
|
||||
OPALDIR=$(switch_builddir)/libs/opal/opal
|
||||
PWLIBDIR=$(switch_builddir)/libs/opal/pwlib
|
||||
|
||||
mod_LTLIBRARIES = mod_opal.la
|
||||
mod_opal_la_SOURCES = opal_backend.cpp mod_opal.cpp
|
||||
mod_opal_la_CPPFLAGS = $(AM_CPPFLAGS) -D_REENTRANT -fno-exceptions -Wall -DPTRACING -Os -felide-constructors -Wreorder -I$(OPALDIR)/include -I$(PWLIBDIR)/include
|
||||
|
||||
mod_opal_la_LIBADD = $(switch_builddir)/libfreeswitch.la
|
||||
mod_opal_la_LDFLAGS = -avoid-version -module -no-undefined -export-symbols-regex ^switch_module_.*$ -rpath $(PREFIX)/$(libdir) -L$(PWLIBDIR)/lib -L$(OPALDIR)/lib -lopal_linux_x86_r -lpt_linux_x86_r -lpthread -ldl -fPIC -DPIC
|
||||
|
||||
#Override the linstall target so we just install the .so/.dylib
|
||||
|
||||
install-data-am: $(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN)
|
||||
|
||||
$(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).la
|
||||
@echo installing $(MODNAME).$(DYNAMIC_LIB_EXTEN)
|
||||
@if [ -f .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) ] ; then \
|
||||
$(LIBTOOL) --mode=install $(INSTALL) .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
|
||||
else \
|
||||
$(LIBTOOL) --mode=install $(INSTALL) $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
|
||||
fi
|
@ -1,283 +0,0 @@
|
||||
/*
|
||||
* mod_opalh323.cpp
|
||||
*
|
||||
* Opal gluer for Freeswitch
|
||||
* This file implements fontend of Opal module functions
|
||||
* that is all functions that are used for communication
|
||||
* between FreeSWITCH core and this module
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: mod_opal.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 Lukasz Zwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#include <ptlib.h>
|
||||
#include <ptlib/svcproc.h>
|
||||
#include "mod_opal.h"
|
||||
#include "opal_backend.h"
|
||||
#include <switch.h>
|
||||
|
||||
/*
|
||||
* IO routines handlers definitions for H323
|
||||
*/
|
||||
static switch_call_cause_t opalh323_outgoing_channel(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
|
||||
static switch_status_t opalh323_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_kill_channel(switch_core_session_t *, int);
|
||||
static switch_status_t opalh323_waitfor_read(switch_core_session_t *, int, int);
|
||||
static switch_status_t opalh323_waitfor_write(switch_core_session_t *, int, int);
|
||||
static switch_status_t opalh323_send_dtmf(switch_core_session_t *, char *);
|
||||
static switch_status_t opalh323_receive_message(switch_core_session_t *, switch_core_session_message_t *);
|
||||
static switch_status_t opalh323_receive_event(switch_core_session_t *, switch_event_t *);
|
||||
static switch_status_t opalh323_state_change(switch_core_session_t *);
|
||||
static switch_status_t opalh323_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
/*
|
||||
* Event handlers declaration for H323
|
||||
*/
|
||||
static switch_status_t opalh323_on_init(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_ring(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_execute(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_hangup(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_loopback(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_transmit(switch_core_session_t *session);
|
||||
|
||||
/**
|
||||
* Declaration of private variables
|
||||
*/
|
||||
static switch_memory_pool_t *opal_pool = NULL;
|
||||
static switch_endpoint_interface_t *opalh323_endpoint_interface = NULL;
|
||||
static FSOpalManager *opal_manager = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* This is Tuyan's Ozipek neat trick
|
||||
* to initialize PProcess instance
|
||||
* which is needed by OpalManager
|
||||
*/
|
||||
class _FSOpalProcess : public PProcess
|
||||
{
|
||||
PCLASSINFO(_FSOpalProcess, PProcess)
|
||||
public:
|
||||
_FSOpalProcess(){PTrace::SetLevel(PSystemLog::Info);}; //just for fun and eyecandy ;)
|
||||
void Main() {};
|
||||
} FSOpalProcess;
|
||||
|
||||
|
||||
/*
|
||||
* IO routines handlers set declaration
|
||||
*/
|
||||
static switch_io_routines_t opalh323_io_routines = {
|
||||
/*.outgoing_channel */ opalh323_outgoing_channel,
|
||||
/*.read_frame */ opalh323_read_frame,
|
||||
/*.write_frame */ opalh323_write_frame,
|
||||
/*.kill_channel */ opalh323_kill_channel,
|
||||
/*.waitfor_read */ opalh323_waitfor_read,
|
||||
/*.waitfor_read */ opalh323_waitfor_write,
|
||||
/*.send_dtmf */ opalh323_send_dtmf,
|
||||
/*.receive_message */ opalh323_receive_message,
|
||||
/*.receive_event */ opalh323_receive_event,
|
||||
/*.state_change*/ opalh323_state_change,
|
||||
/*.read_video_frame*/ opalh323_read_video_frame,
|
||||
/*.write_video_frame*/ opalh323_write_video_frame
|
||||
};
|
||||
|
||||
static switch_state_handler_table_t opalh323_event_handlers = {
|
||||
/*.on_init */ opalh323_on_init,
|
||||
/*.on_ring */ opalh323_on_ring,
|
||||
/*.on_execute */ opalh323_on_execute,
|
||||
/*.on_hangup */ opalh323_on_hangup,
|
||||
/*.on_loopback */ opalh323_on_loopback,
|
||||
/*.on_transmit */ opalh323_on_transmit
|
||||
};
|
||||
|
||||
/*
|
||||
* Loadable FreeSWITCH module functions declaration
|
||||
*/
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown);
|
||||
SWITCH_MODULE_DEFINITION(mod_opal, mod_opal_load, mod_opal_shutdown, NULL);
|
||||
|
||||
/*
|
||||
* This function is called on module load
|
||||
* It sets up frontend interface to FS
|
||||
*
|
||||
*/
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load)
|
||||
{
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Starting loading mod_opal\n");
|
||||
opal_pool = pool;
|
||||
/* frontend initialization*/
|
||||
*module_interface =NULL;
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
assert(*module_interface);
|
||||
if(!module_interface)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Can not create loadable module interfacer\n");
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
opalh323_endpoint_interface = (switch_endpoint_interface_t*)switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
|
||||
opalh323_endpoint_interface->interface_name = "opalH323";
|
||||
opalh323_endpoint_interface->io_routines = &opalh323_io_routines;
|
||||
opalh323_endpoint_interface->state_handler = &opalh323_event_handlers;
|
||||
|
||||
|
||||
/* backend initialization */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Begin opal backend init\n");
|
||||
opal_manager = new FSOpalManager();
|
||||
assert(opal_manager);
|
||||
if(!opal_manager) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not create opal manger\n");
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager created\n");
|
||||
|
||||
if(!opal_manager->initialize(modname, opal_pool, opalh323_endpoint_interface)) {
|
||||
delete opal_manager;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not initialize opal manger\n");
|
||||
return SWITCH_STATUS_FALSE; /* if can't initialize return general error */
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager initilaized and running\n");
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* This functionis called on module teardown
|
||||
* It releases all internal resources, i.e.
|
||||
* it dealocates OPAL core
|
||||
*
|
||||
*/
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown)
|
||||
{
|
||||
/* deallocate OPAL manager */
|
||||
|
||||
delete opal_manager;
|
||||
opal_manager = NULL;
|
||||
opal_pool = NULL;
|
||||
opalh323_endpoint_interface = NULL;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* IO routines handlers definitions
|
||||
*/
|
||||
static switch_call_cause_t opalh323_outgoing_channel(
|
||||
switch_core_session_t *session,
|
||||
switch_caller_profile_t *outbound_profile,
|
||||
switch_core_session_t **new_session,
|
||||
switch_memory_pool_t **pool)
|
||||
{
|
||||
return opal_manager->io_outgoing_channel(session,outbound_profile,new_session,pool);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
|
||||
{
|
||||
return opal_manager->io_read_frame(session,frame,timeout,flags,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
|
||||
{
|
||||
return opal_manager->io_write_frame(session,frame,timeout,flags,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_kill_channel(switch_core_session_t *session, int sig)
|
||||
{
|
||||
return opal_manager->io_kill_channel(session,sig);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_waitfor_read(switch_core_session_t *session, int ms, int stream_id)
|
||||
{
|
||||
return opal_manager->io_waitfor_read(session,ms,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
|
||||
{
|
||||
return opal_manager->io_waitfor_write(session,ms,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||
{
|
||||
return opal_manager->io_send_dtmf(session,dtmf);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
|
||||
{
|
||||
return opal_manager->io_receive_message(session,msg);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_receive_event(switch_core_session_t *session, switch_event_t *event)
|
||||
{
|
||||
return opal_manager->io_receive_event(session,event);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_state_change(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->io_state_change(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flag, int stream_id)
|
||||
{
|
||||
return opal_manager->io_read_video_frame(session,frame,timeout,flag,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flag, int stream_id)
|
||||
{
|
||||
return opal_manager->io_write_video_frame(session,frame,timeout,flag,stream_id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Event handlers
|
||||
*/
|
||||
|
||||
static switch_status_t opalh323_on_init(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_init(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_ring(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_ring(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_execute(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_execute(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_hangup(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_hangup(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_loopback(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_loopback(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_transmit(switch_core_session_t *session)
|
||||
{
|
||||
return opal_manager->callback_on_transmit(session);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* mod_opalh323.h
|
||||
*
|
||||
* Opal gluer for Freeswitch header file
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*
|
||||
* $Log: mod_opal.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#ifndef __FREESWITCH_MOD_OPAL__
|
||||
#define __FREESWITCH_MOD_OPAL__
|
||||
|
||||
#define HAVE_APR /* what do I need this for?? copied from mod_sofia */
|
||||
#include <switch.h>
|
||||
#include <switch_version.h>
|
||||
#define MODNAME "mod_opal"
|
||||
|
||||
|
||||
|
||||
#endif /* __FREESWITCH_MOD_OPAL__ */
|
@ -1,258 +0,0 @@
|
||||
/*
|
||||
* mod_opalh323.cpp
|
||||
*
|
||||
* Opal-H323 gluer for Freeswitch
|
||||
* This file implements fontend of OpalH323 module functions
|
||||
* that is all functions that are used for communication
|
||||
* between FreeSWITCH core and this module
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: mod_opalh323.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
|
||||
#include "mod_opalh323.h"
|
||||
#include "opalh323_backend.h"
|
||||
#include <switch.h>
|
||||
|
||||
/*
|
||||
* IO routines handlers definitions
|
||||
*/
|
||||
static switch_call_cause_t opalh323_outgoing_channel(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
|
||||
static switch_status_t opalh323_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_kill_channel(switch_core_session_t *, int);
|
||||
static switch_status_t opalh323_waitfor_read(switch_core_session_t *, int, int);
|
||||
static switch_status_t opalh323_waitfor_write(switch_core_session_t *, int, int);
|
||||
static switch_status_t opalh323_send_dtmf(switch_core_session_t *, char *);
|
||||
static switch_status_t opalh323_receive_message(switch_core_session_t *, switch_core_session_message_t *);
|
||||
static switch_status_t opalh323_receive_event(switch_core_session_t *, switch_event_t *);
|
||||
static switch_status_t opalh323_state_change(switch_core_session_t *);
|
||||
static switch_status_t opalh323_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
static switch_status_t opalh323_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
/*
|
||||
* Event handlers declaration
|
||||
*/
|
||||
static switch_status_t opalh323_on_init(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_ring(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_execute(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_hangup(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_loopback(switch_core_session_t *session);
|
||||
static switch_status_t opalh323_on_transmit(switch_core_session_t *session);
|
||||
|
||||
/**
|
||||
* Declaration of private variables
|
||||
*/
|
||||
static FSOpalManager *opalh323_manager = NULL;
|
||||
static switch_memory_pool_t *opalh323_pool = NULL;
|
||||
static switch_endpoint_interface_t *opalh323_endpoint_interface;
|
||||
|
||||
/*
|
||||
* IO routines handlers set declaration
|
||||
*/
|
||||
static switch_io_routines_t opalh323_io_routines = {
|
||||
/*.outgoing_channel */ opalh323_outgoing_channel,
|
||||
/*.read_frame */ opalh323_read_frame,
|
||||
/*.write_frame */ opalh323_write_frame,
|
||||
/*.kill_channel */ opalh323_kill_channel,
|
||||
/*.waitfor_read */ opalh323_waitfor_read,
|
||||
/*.waitfor_read */ opalh323_waitfor_write,
|
||||
/*.send_dtmf */ opalh323_send_dtmf,
|
||||
/*.receive_message */ opalh323_receive_message,
|
||||
/*.receive_event */ opalh323_receive_event,
|
||||
/*.state_change*/ opalh323_state_change,
|
||||
/*.read_video_frame*/ opalh323_read_video_frame,
|
||||
/*.write_video_frame*/ opalh323_write_video_frame
|
||||
};
|
||||
|
||||
static switch_state_handler_table_t opalh323_event_handlers = {
|
||||
/*.on_init */ opalh323_on_init,
|
||||
/*.on_ring */ opalh323_on_ring,
|
||||
/*.on_execute */ opalh323_on_execute,
|
||||
/*.on_hangup */ opalh323_on_hangup,
|
||||
/*.on_loopback */ opalh323_on_loopback,
|
||||
/*.on_transmit */ opalh323_on_transmit
|
||||
};
|
||||
|
||||
/*
|
||||
* Loadable FreeSWITCH module functions declaration
|
||||
*/
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opalh323_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opalh323_shutdown);
|
||||
SWITCH_MODULE_DEFINITION(mod_opalh323, mod_opalh323_load, mod_opalh323_shutdown, NULL);
|
||||
|
||||
/*
|
||||
* This function is called on module load
|
||||
* It sets up:
|
||||
* 1. frontend - interface to FreeSWITCH core
|
||||
* 2. backend - inerface to OPAL core
|
||||
*
|
||||
*/
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opalh323_load)
|
||||
{
|
||||
|
||||
/* frontend initialization*/
|
||||
*module_interface =NULL;
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
assert(*module_interface);
|
||||
if(!module_interface)
|
||||
{
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
opalh323_endpoint_interface = (switch_endpoint_interface_t*)switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
|
||||
opalh323_endpoint_interface->interface_name = "OPALH323";
|
||||
opalh323_endpoint_interface->io_routines = &opalh323_io_routines;
|
||||
opalh323_endpoint_interface->state_handler = &opalh323_event_handlers;
|
||||
|
||||
/* backend initialization */
|
||||
opalh323_manager = new FSOpalManager();
|
||||
assert(opalh323_manager);
|
||||
if(!opalh323_manager)
|
||||
{
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
|
||||
if(!opalh323_manager->initialize(modname,pool,opalh323_endpoint_interface))
|
||||
{
|
||||
delete opalh323_manager;
|
||||
return SWITCH_STATUS_FALSE; /* if can't initialize return general error */
|
||||
}
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* This functionis called on module teardown
|
||||
* It releases all internal resources, i.e.
|
||||
* it dealocates OPAL core
|
||||
*
|
||||
*/
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opalh323_shutdown)
|
||||
{
|
||||
/* deallocate OPAL manager */
|
||||
delete opalh323_manager;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* IO routines handlers definitions
|
||||
*/
|
||||
static switch_call_cause_t opalh323_outgoing_channel(
|
||||
switch_core_session_t *session,
|
||||
switch_caller_profile_t *outbound_profile,
|
||||
switch_core_session_t **new_session,
|
||||
switch_memory_pool_t **pool)
|
||||
{
|
||||
return opalh323_manager->io_outgoing_channel(session,outbound_profile,new_session,pool);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_read_frame(session,frame,timeout,flags,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_write_frame(session,frame,timeout,flags,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_kill_channel(switch_core_session_t *session, int sig)
|
||||
{
|
||||
return opalh323_manager->io_kill_channel(session,sig);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_waitfor_read(switch_core_session_t *session, int ms, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_waitfor_read(session,ms,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_waitfor_write(session,ms,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||
{
|
||||
return opalh323_manager->io_send_dtmf(session,dtmf);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
|
||||
{
|
||||
return opalh323_manager->io_receive_message(session,msg);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_receive_event(switch_core_session_t *session, switch_event_t *event)
|
||||
{
|
||||
return opalh323_manager->io_receive_event(session,event);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_state_change(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->io_state_change(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flag, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_read_video_frame(session,frame,timeout,flag,stream_id);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flag, int stream_id)
|
||||
{
|
||||
return opalh323_manager->io_write_video_frame(session,frame,timeout,flag,stream_id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Event handlers
|
||||
*/
|
||||
|
||||
static switch_status_t opalh323_on_init(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_init(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_ring(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_ring(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_execute(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_execute(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_hangup(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_hangup(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_loopback(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_loopback(session);
|
||||
}
|
||||
|
||||
static switch_status_t opalh323_on_transmit(switch_core_session_t *session)
|
||||
{
|
||||
return opalh323_manager->callback_on_transmit(session);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* mod_opalh323.h
|
||||
*
|
||||
* Opal-H323 gluer for Freeswitch header file
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*
|
||||
* $Log: mod_opalh323.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#ifndef __FREESWITCH_MOD_OPALH323__
|
||||
#define __FREESWITCH_MOD_OPALH323__
|
||||
|
||||
#define HAVE_APR /* what do I need this for?? copied from mod_sofia */
|
||||
#include <switch.h>
|
||||
#include <switch_version.h>
|
||||
#define MODNAME "mod_opalh323"
|
||||
|
||||
|
||||
|
||||
#endif /* __FREESWITCH_MOD_OPALH323__ */
|
@ -1,897 +0,0 @@
|
||||
/*
|
||||
* opalh323_backend.cpp
|
||||
*
|
||||
* Backend for Opal module, implements
|
||||
* H323 handling via OPAL library
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: opal_backend.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "opal_backend.h"
|
||||
|
||||
/**
|
||||
* Structure definition for private data
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TFLAG_IO = (1 << 0), /* not used, please fill this comment if you use it */
|
||||
TFLAG_INBOUND = (1 << 1), /* if set, call was originated in h323 network */
|
||||
TFLAG_OUTBOUND = (1 << 2), /* if set, call was originated by FS */
|
||||
TFLAG_DTMF = (1 << 3), /* not used, please fill this comment if you use it */
|
||||
TFLAG_VOICE = (1 << 4), /* not used, please fill this comment if you use it */
|
||||
TFLAG_H323HANGUP = (1 << 5), /* if set, call has been cleared by Opal, so no need to destroy it in on_hangup callback */
|
||||
TFLAG_LINEAR = (1 << 6), /* not used, please fill this comment if you use it */
|
||||
TFLAG_CODEC = (1 << 7), /* not used, please fill this comment if you use it */
|
||||
TFLAG_BREAK = (1 << 8) /* not used, please fill this comment if you use it */
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure definition for private data
|
||||
*/
|
||||
|
||||
typedef struct OpalH323Private_s
|
||||
{
|
||||
OpalConnection *m_opalConnection; /** pointer to OpalConnection object */
|
||||
switch_mutex_t *m_mutex; /** mutex for synchonizing access to session object */
|
||||
switch_caller_profile_t *m_callerProfile; /** caller profile */
|
||||
switch_codec_t m_readcodec; /* Read codec*/
|
||||
switch_codec_t m_writecodec; /* Write codec*/
|
||||
/* for next two variables naming convension is changed, to use them with switch_flag.. macros */
|
||||
unsigned int flags; /** connection state flags */
|
||||
switch_mutex_t *flag_mutex; /** mutex for state flags, I use it in case I decide to not use m_mutex */
|
||||
|
||||
} OpalH323Private_t;
|
||||
|
||||
|
||||
static bool OpalH323Private_Create(OpalH323Private_t **o_private, switch_core_session_t *io_session)
|
||||
{
|
||||
assert(io_session);
|
||||
*o_private = (OpalH323Private_t *)switch_core_session_alloc(io_session, sizeof(OpalH323Private_t));
|
||||
if(!o_private)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
if(SWITCH_STATUS_SUCCESS != switch_mutex_init(&(*o_private)->m_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(io_session)))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(SWITCH_STATUS_SUCCESS != switch_mutex_init(&(*o_private)->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(io_session)))
|
||||
{
|
||||
assert(0);
|
||||
switch_mutex_destroy((*o_private)->m_mutex);
|
||||
return false;
|
||||
}
|
||||
(*o_private)->m_opalConnection = NULL;
|
||||
(*o_private)->m_callerProfile = NULL;
|
||||
(*o_private)->flags = 0; //clear all flags
|
||||
switch_core_session_set_private(io_session,static_cast<void*>(*o_private)); //save private data as session private data
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
static bool OpalH323Private_Delete(OpalH323Private_t *o_private)
|
||||
{
|
||||
assert(o_private);
|
||||
switch_status_t status = switch_mutex_destroy(o_private->m_mutex);
|
||||
assert(status==SWITCH_STATUS_SUCCESS);
|
||||
status = switch_mutex_destroy(o_private->flag_mutex);
|
||||
assert(status==SWITCH_STATUS_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Default constructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager::FSOpalManager() :
|
||||
m_isInitialized(false),
|
||||
m_pH323Endpoint(NULL),
|
||||
m_pMemoryPool(NULL),
|
||||
m_pH323EndpointInterface(NULL),
|
||||
m_pSessionsHashTable(NULL),
|
||||
m_pSessionsHashTableMutex(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager::~FSOpalManager()
|
||||
{
|
||||
/**
|
||||
* Destroy all allocated resources, if any
|
||||
* !! all endpoints are automatically deleted in ~OpalManager, so leave them
|
||||
*/
|
||||
if(m_isInitialized)
|
||||
{
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method does real initialization of the manager
|
||||
*/
|
||||
bool FSOpalManager::initialize(
|
||||
const char* i_modName,
|
||||
switch_memory_pool_t* i_memoryPool,
|
||||
switch_endpoint_interface_t *i_endpointInterface
|
||||
)
|
||||
{
|
||||
/* check if not initialized */
|
||||
assert(!m_isInitialized);
|
||||
/* check input parameters */
|
||||
assert(i_modName);
|
||||
assert(i_memoryPool);
|
||||
assert(i_endpointInterface);
|
||||
|
||||
m_pModuleName = i_modName;
|
||||
m_pMemoryPool = i_memoryPool;
|
||||
m_pH323EndpointInterface = i_endpointInterface;
|
||||
|
||||
/**
|
||||
* Create hash table for storing pointers to session objects,
|
||||
* Each OpalConnection object will retreive it's session object using
|
||||
* its callToken as a key
|
||||
*/
|
||||
|
||||
if(switch_core_hash_init(&m_pSessionsHashTable,m_pMemoryPool)!=SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(switch_mutex_init(&m_pSessionsHashTableMutex,SWITCH_MUTEX_UNNESTED,m_pMemoryPool)!=SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* create h323 endpoint */
|
||||
m_pH323Endpoint = new H323EndPoint( *(static_cast<OpalManager*>(this)) ); ///TODO, replace prefix and signaling port by values from configuration
|
||||
if(!m_pH323Endpoint)
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* To do-> add codecs to capabilities (for call contol)
|
||||
* m_pH323Endpoint->AddCapability();
|
||||
*/
|
||||
|
||||
m_pH323Endpoint->DisableFastStart(false); ///TODO this should be configurable
|
||||
m_pH323Endpoint->DisableH245Tunneling(false); ///TODO this should be configurable
|
||||
|
||||
///TODO gatekeeper use should be configurable, I think that sevral options should be implemented in config file: use, dont use, use one of specified with priorities, try to reconnect to the topmost...
|
||||
///TODO m_pH323Endpoint->SetInitialBandwidth(initialBandwidth);
|
||||
///TODO m_pH323Endpoint->SetVendorIdentifierInfo()
|
||||
|
||||
///TODO address should be configurable, should allow creaeing listeners on multiple interfaces
|
||||
OpalTransportAddress opalTransportAddress("192.168.0.1",1720); //for time being create listener on all ip's and default port
|
||||
if(!m_pH323Endpoint->StartListeners(opalTransportAddress))
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
delete m_pH323Endpoint;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* at this point OPAL is ready to go */
|
||||
m_isInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch_core_session_t* FSOpalManager::getSessionToken(const PString &i_token) const
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
return static_cast<switch_core_session_t*>(switch_core_hash_find_locked(m_pSessionsHashTable,(const char*)i_token,m_pSessionsHashTableMutex));
|
||||
}
|
||||
|
||||
void FSOpalManager::saveSessionToken(const PString &i_token,switch_core_session_t* i_session)
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_insert_locked(m_pSessionsHashTable,(const char*)i_token,i_session,m_pSessionsHashTableMutex);
|
||||
}
|
||||
|
||||
void FSOpalManager::deleteSessionToken(const PString &i_token)
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_delete_locked(m_pSessionsHashTable,(const char*)i_token,m_pSessionsHashTableMutex);
|
||||
}
|
||||
|
||||
switch_call_cause_t FSOpalManager::causeH323ToOpal(OpalConnection::CallEndReason i_cause)
|
||||
{
|
||||
//TODO -> fill all causes
|
||||
return SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
}
|
||||
|
||||
OpalConnection::CallEndReason FSOpalManager::causeOpalToH323(switch_call_cause_t i_cause)
|
||||
{
|
||||
//TODO -> fill all causes
|
||||
return OpalConnection::EndedByLocalUser;
|
||||
}
|
||||
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
||||
OpalConnection::StringOptions * stringOptions
|
||||
)
|
||||
{
|
||||
//TODO check if options and stringOptions fields ever apply
|
||||
return OnIncomingConnection(connection);
|
||||
}
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options ///< options for new connection (can't use default as overrides will fail)
|
||||
)
|
||||
{
|
||||
//TODO, check if options field ever applies
|
||||
return OnIncomingConnection(connection);
|
||||
}
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection ///< Connection that is calling
|
||||
)
|
||||
{
|
||||
/* allocate new session in switch core*/
|
||||
switch_core_session_t *session = switch_core_session_request(m_pH323EndpointInterface , NULL);
|
||||
assert(session);
|
||||
if(!session)
|
||||
{
|
||||
///TODO add cause to the connection
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate session object?\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* allocate private resources */
|
||||
OpalH323Private_t *tech_pvt = NULL;
|
||||
if(!OpalH323Private_Create(&tech_pvt,session))
|
||||
{
|
||||
///TODO add cause to the connection
|
||||
switch_core_session_destroy(&session);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate private object?\n");
|
||||
return false;
|
||||
}
|
||||
tech_pvt->m_opalConnection = &connection;
|
||||
|
||||
/** Before adding this session to sessions hash table,
|
||||
* lock he mutex so no concurrent
|
||||
* callback can be running for this connection
|
||||
* probably other callbacks are called from this task
|
||||
* but carfulness wont bite
|
||||
*/
|
||||
switch_mutex_lock(tech_pvt->m_mutex);
|
||||
/**
|
||||
* insert connection to hash table, use call token as a key
|
||||
*/
|
||||
PString callToken = connection.GetCall().GetToken();
|
||||
saveSessionToken(callToken,session);
|
||||
|
||||
/** Create calling side profile */
|
||||
tech_pvt->m_callerProfile = switch_caller_profile_new(
|
||||
switch_core_session_get_pool(session),
|
||||
(const char*)connection.GetRemotePartyName(), /** username */
|
||||
"XML", /** TODO -> this should be configurable by core */
|
||||
(const char*)connection.GetRemotePartyName(), /** caller_id_name */
|
||||
(const char*)connection.GetRemotePartyNumber(), /** caller_id_number */
|
||||
(const char*)connection.GetRemotePartyAddress(),/** network addr */
|
||||
NULL, /** ANI */
|
||||
NULL, /** ANI II */
|
||||
NULL, /** RDNIS */
|
||||
m_pModuleName, /** source */
|
||||
"default", /** TODO -> set context */
|
||||
(const char*)connection.GetCalledDestinationNumber() /** destination_number */
|
||||
);
|
||||
|
||||
if(!tech_pvt->m_callerProfile) /* should never error */
|
||||
{
|
||||
deleteSessionToken(callToken);
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
OpalH323Private_Delete(tech_pvt);
|
||||
switch_core_session_destroy(&session);
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Set up sessions channel */
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_channel_set_name(channel,(const char*)callToken);
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->m_callerProfile);
|
||||
switch_channel_set_state(channel, CS_INIT);
|
||||
switch_set_flag_locked(tech_pvt,TFLAG_OUTBOUND);
|
||||
|
||||
/** Set up codecs for the channel ??? */
|
||||
/* Setting up temporary codecs, so that calling to a wav file does not make fs core dump*/
|
||||
if (switch_core_codec_init(&tech_pvt->m_readcodec,
|
||||
"L16",
|
||||
NULL,
|
||||
0, 0, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
||||
NULL) != SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Setting Read Codec\n");
|
||||
}
|
||||
switch_core_session_set_read_codec(session, &tech_pvt->m_readcodec);
|
||||
|
||||
if (switch_core_codec_init(&tech_pvt->m_writecodec,
|
||||
"L16",
|
||||
NULL,
|
||||
0, 0, 0, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
||||
NULL) != SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Setting Write Codec\n");
|
||||
}
|
||||
switch_core_session_set_write_codec(session, &tech_pvt->m_writecodec);
|
||||
|
||||
|
||||
|
||||
|
||||
/** lunch thread */
|
||||
if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
|
||||
deleteSessionToken(callToken);
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
OpalH323Private_Delete(tech_pvt);
|
||||
switch_core_session_destroy(&session);
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
|
||||
|
||||
/* the connection can be continued!!! */
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
OpalConnection::AnswerCallResponse FSOpalManager::OnAnswerCall(
|
||||
OpalConnection &connection,
|
||||
const PString &caller)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnAnswerCall token=%s\n",(const char*)connection.GetCall().GetToken());
|
||||
switch_core_session_t *session = getSessionToken((const char*)connection.GetCall().GetToken());
|
||||
if(session==NULL) /* that can mean that session has been already destroyed by core and we should release it */
|
||||
{
|
||||
return OpalConnection::AnswerCallDenied;
|
||||
}
|
||||
return OpalConnection::AnswerCallProgress; //don't send alerting signal yet
|
||||
}
|
||||
|
||||
void FSOpalManager::OnAlerting(OpalConnection &connection)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnAlerting token=%s\n",(const char*)connection.GetCall().GetToken());
|
||||
|
||||
switch_core_session_t *session = getSessionToken((const char*)connection.GetCall().GetToken());
|
||||
|
||||
if(session==NULL) /* that can mean that session has been already destroyed by core and we should release it */
|
||||
{
|
||||
assert(0); //should never happen?
|
||||
connection.Release(OpalConnection::EndedByLocalUser);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnAlerting::unknown connection\n");
|
||||
return;
|
||||
}
|
||||
|
||||
OpalH323Private_t *tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(session));
|
||||
assert(tech_prv);
|
||||
SLock(tech_prv->m_mutex);
|
||||
|
||||
switch_channel_t* channel = switch_core_session_get_channel(session);
|
||||
assert(channel);
|
||||
|
||||
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
|
||||
switch_channel_mark_ring_ready(channel);
|
||||
}
|
||||
|
||||
void FSOpalManager::OnConnected (OpalConnection &connection)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnConnected token=%s\n",(const char*)connection.GetCall().GetToken());
|
||||
switch_core_session_t *session = getSessionToken((const char*)connection.GetCall().GetToken());
|
||||
|
||||
if(session==NULL) /* that can mean that session has been already destroyed by core and we should release it */
|
||||
{
|
||||
assert(0); //should never happen?
|
||||
connection.Release(OpalConnection::EndedByLocalUser);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnConnected::unknown connection\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
OpalH323Private_t *tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(session));
|
||||
assert(tech_prv);
|
||||
SLock(tech_prv->m_mutex);
|
||||
|
||||
switch_channel_t* channel = switch_core_session_get_channel(session);
|
||||
assert(channel);
|
||||
|
||||
if(!switch_channel_test_flag(channel, CF_ANSWERED)) /* TODO -> synchronize this with callback from core then answered */
|
||||
{
|
||||
switch_channel_mark_answered(channel);
|
||||
/* todo -> mark audio/video channels as established */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void FSOpalManager::OnEstablished (OpalConnection &connection)
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnEstablished token=%s\n",(const char*)connection.GetCall().GetToken());
|
||||
switch_core_session_t *session = getSessionToken((const char*)connection.GetCall().GetToken());
|
||||
|
||||
if(session==NULL) /* that can mean that session has been already destroyed by core and we should release it */
|
||||
{
|
||||
assert(0); //should never happen?
|
||||
connection.Release(OpalConnection::EndedByLocalUser);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnConnected::unknown connection\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
OpalH323Private_t *tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(session));
|
||||
assert(tech_prv);
|
||||
SLock(tech_prv->m_mutex);
|
||||
|
||||
switch_channel_t* channel = switch_core_session_get_channel(session);
|
||||
assert(channel);
|
||||
|
||||
if(!switch_channel_test_flag(channel, CF_ANSWERED)) /* TODO -> synchronize this with callback from core then answered */
|
||||
{
|
||||
switch_channel_mark_answered(channel);
|
||||
/* todo -> mark audio/video channels as established */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FSOpalManager::OnReleased(OpalConnection &connection)
|
||||
{
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnReleased\n");
|
||||
PString callToken = connection.GetCall().GetToken();
|
||||
|
||||
switch_core_session_t *session = getSessionToken((const char*)callToken);
|
||||
|
||||
/* release this connection within it's call, the connection object is invalid after this line */
|
||||
connection.GetCall().OnReleased(connection);
|
||||
|
||||
if(session==NULL)
|
||||
{
|
||||
/* session==NULL, means that FS session has been already destroyed,
|
||||
* (because core released the connection), so this is just a callback
|
||||
* from opal (following Connection->release)
|
||||
*/
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"OnReleased::unknown connection\n");
|
||||
return;
|
||||
}
|
||||
/* else
|
||||
* we receive this callback, because h323 is releasing connection
|
||||
* so we need to clear the session
|
||||
*/
|
||||
|
||||
OpalH323Private_t *tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(session));
|
||||
assert(tech_prv);
|
||||
SLock(tech_prv->m_mutex);
|
||||
|
||||
/*
|
||||
* this is last place where callToken is available,
|
||||
* so we have to clean up all the h323 data in this gluer
|
||||
*/
|
||||
switch_set_flag_locked(tech_prv,TFLAG_H323HANGUP); /* mark that h323 side was released so we don't try to release it again in callback_on_hangup callback*/
|
||||
deleteSessionToken(callToken); /* delete token<-> call association */
|
||||
|
||||
/* start call clearing on FS side */
|
||||
switch_channel_t* channel = switch_core_session_get_channel(session);
|
||||
assert(channel);
|
||||
switch_channel_hangup(channel,SWITCH_CAUSE_NORMAL_CLEARING); ///TODO: translate connection clear cause
|
||||
|
||||
}
|
||||
|
||||
void FSOpalManager::AdjustMediaFormats(const OpalConnection & connection,
|
||||
OpalMediaFormatList & mediaFormats) const
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"AdjustMediaFormats, token=%s\n",(const char*)connection.GetCall().GetToken());
|
||||
|
||||
PString callToken = connection.GetCall().GetToken();
|
||||
switch_core_session_t *session = getSessionToken((const char*)callToken);
|
||||
if(session==NULL)
|
||||
{
|
||||
assert(0);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"AdjustMediaFormats::unknown connection\n");
|
||||
return;
|
||||
}
|
||||
|
||||
OpalH323Private_t *tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(session));
|
||||
assert(tech_prv);
|
||||
SLock(tech_prv->m_mutex);
|
||||
|
||||
/* start with removing all codecs */
|
||||
mediaFormats.RemoveAll();
|
||||
|
||||
///TODO: check what codecs are supported by FS, and add available to list, temporarly just add basic codecs
|
||||
mediaFormats+=OpalPCM16;
|
||||
mediaFormats+=OpalG711_ULAW_64K;
|
||||
mediaFormats+=OpalG711_ALAW_64K;
|
||||
mediaFormats+=OpalG711uLaw;
|
||||
mediaFormats+=OpalG711ALaw;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FS ON_INIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_init(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_init\n");
|
||||
|
||||
OpalH323Private_t* tech_prv = (OpalH323Private_t*)switch_core_session_get_private(io_session);
|
||||
|
||||
if(tech_prv==NULL)
|
||||
{
|
||||
assert(0);
|
||||
return SWITCH_STATUS_NOTFOUND;
|
||||
}
|
||||
|
||||
SLock(tech_prv->m_mutex); /* lock channel */
|
||||
switch_channel_t *channel = switch_core_session_get_channel(io_session);
|
||||
assert(channel);
|
||||
|
||||
/* for incoming connection set channel state to ring, to make core execute dialplan*/
|
||||
if(!switch_channel_test_flag(channel,CF_OUTBOUND))
|
||||
{
|
||||
switch_channel_set_state(channel, CS_RING);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_INIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_ring(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_ring\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_EXECUTE callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_execute(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_execute\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_HANGUP callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_hangup(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_hangup\n");
|
||||
|
||||
OpalH323Private_t* tech_prv = (OpalH323Private_t*)switch_core_session_get_private(io_session);
|
||||
switch_mutex_lock(tech_prv->m_mutex); /* lock channel */
|
||||
|
||||
|
||||
/* Check if this callback was not originated, after call cleared from h323 side */
|
||||
if(!switch_test_flag(tech_prv,TFLAG_H323HANGUP))
|
||||
{
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"clear h323 call\n");
|
||||
deleteSessionToken(tech_prv->m_opalConnection->GetCall().GetToken()); //delete this connection form connection pool
|
||||
if(tech_prv->m_opalConnection)
|
||||
{
|
||||
//switch_call_cause_t cause = switch_channel_get_cause(channel);
|
||||
tech_prv->m_opalConnection->Release(); ///TODO add cause
|
||||
}
|
||||
}
|
||||
|
||||
switch_channel_t *channel = switch_core_session_get_channel(io_session);
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
OpalH323Private_Delete(tech_prv);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_LOOPBACK callback handler
|
||||
*
|
||||
*/
|
||||
|
||||
switch_status_t FSOpalManager::callback_on_loopback(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_loopback\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_TRANSMIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_transmit(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_transmit\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_call_cause_t FSOpalManager::io_outgoing_channel(switch_core_session_t *i_session, switch_caller_profile_t *i_profile, switch_core_session_t **o_newSession, switch_memory_pool_t **i_memPool)
|
||||
{
|
||||
|
||||
assert(i_session);
|
||||
assert(i_profile);
|
||||
assert(i_memPool);
|
||||
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_outgoing_channel\n");
|
||||
|
||||
/* allocate session*/
|
||||
*o_newSession = switch_core_session_request(m_pH323EndpointInterface,i_memPool);
|
||||
if(*o_newSession==NULL)
|
||||
{
|
||||
assert(0);
|
||||
return SWITCH_CAUSE_UNALLOCATED;
|
||||
}
|
||||
|
||||
/* allocate private data */
|
||||
OpalH323Private_t *tech_prv = NULL;
|
||||
if(!OpalH323Private_Create(&tech_prv,*o_newSession))
|
||||
{
|
||||
assert(0);
|
||||
switch_core_session_destroy(o_newSession);
|
||||
return SWITCH_CAUSE_UNALLOCATED;
|
||||
}
|
||||
|
||||
switch_mutex_lock(tech_prv->m_mutex);
|
||||
|
||||
OpalCall *call = CreateCall(); /* init new call
|
||||
* this call will be wrapper for a single connection
|
||||
* to remote h323 party
|
||||
*/
|
||||
PString callToken = call->GetToken();
|
||||
|
||||
saveSessionToken(callToken,*o_newSession);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"Token=%s\n",(const char*)callToken);
|
||||
switch_channel_t *channel = switch_core_session_get_channel(*o_newSession);
|
||||
assert(channel);
|
||||
|
||||
switch_channel_set_name(channel,(const char*)callToken);
|
||||
tech_prv->m_callerProfile = switch_caller_profile_clone(*o_newSession, i_profile);
|
||||
assert(tech_prv->m_callerProfile);
|
||||
switch_channel_set_caller_profile(channel, tech_prv->m_callerProfile);
|
||||
|
||||
|
||||
/*PString calledParty = PString("h323:")+PString(tech_prv->m_callerProfile->destination_number);*/
|
||||
|
||||
PString calledParty("h323:192.168.0.2");
|
||||
|
||||
if(!m_pH323Endpoint->MakeConnection(*call,calledParty,(void*)NULL,0,(OpalConnection::StringOptions*)NULL)) /* attempt start call on h323 endpoint */
|
||||
{
|
||||
assert(0);
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
OpalH323Private_Delete(tech_prv);
|
||||
switch_core_session_destroy(o_newSession);
|
||||
ClearCall(callToken);
|
||||
return SWITCH_CAUSE_UNALLOCATED;
|
||||
}
|
||||
|
||||
/*if(!MakeConnection(*call,calledParty))
|
||||
{
|
||||
assert(0);
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
OpalH323Private_Delete(tech_prv);
|
||||
switch_core_session_destroy(o_newSession);
|
||||
ClearCall(callToken);
|
||||
return SWITCH_CAUSE_UNALLOCATED;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"new conn created token =%s \n",(const char*)call->GetToken());
|
||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||
switch_channel_set_state(channel, CS_INIT);
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
return SWITCH_CAUSE_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_read_frame(switch_core_session_t *i_session, switch_frame_t **o_frame, int i_timout, switch_io_flag_t i_flag, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_read_frame\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_write_frame(switch_core_session_t *i_session, switch_frame_t *i_frame, int i_timeout, switch_io_flag_t i_flag, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_write_frame\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_kill_channel(switch_core_session_t *i_session, int sig)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
PString signal;
|
||||
switch(sig)
|
||||
{
|
||||
case SWITCH_SIG_NONE:
|
||||
signal = "SWITCH_SIG_NONE";
|
||||
break;
|
||||
case SWITCH_SIG_KILL:
|
||||
signal = "SWITCH_SIG_KILL";
|
||||
break;
|
||||
case SWITCH_SIG_XFER:
|
||||
signal = "SWITCH_SIG_XFER";
|
||||
break;
|
||||
case SWITCH_SIG_BREAK:
|
||||
signal = "SWITCH_SIG_BREAK";
|
||||
break;
|
||||
default:
|
||||
signal = "UNKNOWN";
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_kill_channel sig = %s\n",(const char*)signal);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_waitfor_read(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_waitfor_read\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_waitfor_write(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_waitfor_write\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_send_dtmf(switch_core_session_t *i_session, char *i_dtmf)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_send_dtmf\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_receive_message(switch_core_session_t *i_session, switch_core_session_message_t *i_message)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
|
||||
OpalH323Private_t* tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(i_session));
|
||||
assert(tech_prv);
|
||||
|
||||
switch_mutex_lock(tech_prv->m_mutex);
|
||||
|
||||
switch(i_message->message_id)
|
||||
{
|
||||
case SWITCH_MESSAGE_REDIRECT_AUDIO:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"SWITCH_MESSAGE_REDIRECT_AUDIO\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_TRANSMIT_TEXT:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_TRANSMIT_TEXT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_ANSWER:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_ANSWER\n");
|
||||
|
||||
/* set call answer */
|
||||
//tech_prv->m_opalConnection->AnsweringCall(AnswerCallNow);
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_PROGRESS\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_BRIDGE:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_BRIDGE\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_UNBRIDGE\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_TRANSFER:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_TRANSFER\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_RINGING:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_RINGING\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_MEDIA:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_MEDIA\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_NOMEDIA\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_HOLD:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_HOLD\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_UNHOLD:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_UNHOLD\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_REDIRECT:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_REDIRECT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_REJECT:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_REJECT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_BROADCAST:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_BROADCAST\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT\n");
|
||||
break;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_???\n");
|
||||
}
|
||||
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_receive_event(switch_core_session_t *i_session, switch_event_t *i_event)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_receive_event\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_state_change(switch_core_session_t *)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
/*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_state_change\n");*/
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_read_video_frame\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_write_video_frame\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
@ -1,234 +0,0 @@
|
||||
/*
|
||||
* opalh323_backend.cpp
|
||||
*
|
||||
* Backend for OpalH323 module, implements
|
||||
* H323 handling via OPAL library
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: opal_backend.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#ifndef __FREESWITCH_OPAL_BACKEND__
|
||||
#define __FREESWITCH_OPAL_BACKEND__
|
||||
|
||||
#include <switch.h>
|
||||
#include <ptlib.h>
|
||||
#include <opal/buildopts.h>
|
||||
#include <opal/manager.h>
|
||||
#include <h323/h323ep.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper class for mutex use
|
||||
*
|
||||
**/
|
||||
class SLock
|
||||
{
|
||||
public:
|
||||
|
||||
SLock(switch_mutex_t* i_mutex) :
|
||||
m_mutex(NULL)
|
||||
{
|
||||
assert(i_mutex);
|
||||
m_mutex = i_mutex;
|
||||
switch_mutex_lock(m_mutex);
|
||||
}
|
||||
|
||||
~SLock()
|
||||
{
|
||||
switch_mutex_unlock(m_mutex);
|
||||
}
|
||||
|
||||
private:
|
||||
switch_mutex_t* m_mutex;
|
||||
|
||||
};
|
||||
|
||||
/** This class is OpalManager implementation
|
||||
* for FreeSWITCH OpalH323 module.
|
||||
* All methods are inherited from base OpalManagerClass.
|
||||
* Event callbacks will be filed with valid code
|
||||
* Additional functions have been implemented to be called, or called by
|
||||
*/
|
||||
class FSOpalManager : public OpalManager
|
||||
{
|
||||
PCLASSINFO(FSOpalManager, PObject);
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager();
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
*/
|
||||
~FSOpalManager();
|
||||
|
||||
/**
|
||||
* Method does real initialization of the manager
|
||||
*/
|
||||
bool initialize(
|
||||
const char* i_modName,
|
||||
switch_memory_pool_t* i_memoryPool,
|
||||
switch_endpoint_interface_t *i_endpointInterface
|
||||
);
|
||||
|
||||
/** FS callback handlers declarations
|
||||
*
|
||||
*/
|
||||
switch_status_t callback_on_init(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_ring(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_execute(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_hangup(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_loopback(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_transmit(switch_core_session_t *io_session);
|
||||
|
||||
/** FS io functions
|
||||
*
|
||||
*/
|
||||
|
||||
switch_call_cause_t io_outgoing_channel(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
|
||||
switch_status_t io_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
switch_status_t io_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
switch_status_t io_kill_channel(switch_core_session_t *, int);
|
||||
switch_status_t io_waitfor_read(switch_core_session_t *, int, int);
|
||||
switch_status_t io_waitfor_write(switch_core_session_t *, int, int);
|
||||
switch_status_t io_send_dtmf(switch_core_session_t *, char *);
|
||||
switch_status_t io_receive_message(switch_core_session_t *, switch_core_session_message_t *);
|
||||
switch_status_t io_receive_event(switch_core_session_t *, switch_event_t *);
|
||||
switch_status_t io_state_change(switch_core_session_t *);
|
||||
switch_status_t io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
switch_status_t io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
|
||||
|
||||
/**
|
||||
* Following OnIncomingConnection functions
|
||||
* have been overriden for serving
|
||||
* connections comming from H323 network
|
||||
* They are called on receiving SETUP
|
||||
*/
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
||||
OpalConnection::StringOptions * stringOptions
|
||||
);
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options ///< options for new connection (can't use default as overrides will fail)
|
||||
);
|
||||
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection ///< Connection that is calling
|
||||
);
|
||||
|
||||
/**
|
||||
* OnAnswerCall function is overriden for
|
||||
* serving a situation where H323 driver has send
|
||||
* CALL PROCEEDING message
|
||||
*/
|
||||
virtual OpalConnection::AnswerCallResponse OnAnswerCall(
|
||||
OpalConnection &connection,
|
||||
const PString &caller);
|
||||
|
||||
|
||||
//virtual PString OnRouteConnection (OpalConnection &connection)
|
||||
|
||||
/**
|
||||
* OnAlerting function is overriden for
|
||||
* serving callbacks when remote side sent ALERTING message
|
||||
*/
|
||||
virtual void OnAlerting (OpalConnection &connection);
|
||||
|
||||
/**
|
||||
* OnReleased function is overriden, for
|
||||
* serving callbacks when remote side released the call
|
||||
*/
|
||||
virtual void OnReleased (OpalConnection &connection);
|
||||
|
||||
/**
|
||||
* OnConnected function is overriden for
|
||||
* serving callbacks when remote side sent CONNECT message
|
||||
*/
|
||||
virtual void OnConnected (OpalConnection &connection);
|
||||
|
||||
/**
|
||||
* OnEstablished function is overriden for
|
||||
* serving callbacks when the call was fully established
|
||||
* It can happen upon receiving/sending CONNECT PDU with
|
||||
* fast start or when logical channels where established
|
||||
*/
|
||||
virtual void OnEstablished (OpalConnection &connection);
|
||||
|
||||
/*
|
||||
* AdjustMediaFormats is overriden so manager can set it's own
|
||||
* media format list. It's great for us, as we want to set,
|
||||
* our private media list from FS codecs
|
||||
*/
|
||||
virtual void AdjustMediaFormats(const OpalConnection & connection,
|
||||
OpalMediaFormatList & mediaFormats) const;
|
||||
|
||||
//virtual void OnHold (OpalConnection &connection)
|
||||
//virtual BOOL OnForwarded (OpalConnection &connection, const PString &remoteParty)
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void saveSessionToken(const PString &i_token,switch_core_session_t* i_session);
|
||||
switch_core_session_t* getSessionToken(const PString &i_token) const;
|
||||
void deleteSessionToken(const PString &i_token);
|
||||
|
||||
switch_call_cause_t causeH323ToOpal(OpalConnection::CallEndReason i_cause);
|
||||
OpalConnection::CallEndReason causeOpalToH323(switch_call_cause_t i_cause);
|
||||
|
||||
|
||||
const char *m_pModuleName; /* name of this module */
|
||||
bool m_isInitialized; /* true if module has been initialized properly */
|
||||
H323EndPoint *m_pH323Endpoint; /* h323 endpoint control */
|
||||
switch_memory_pool_t *m_pMemoryPool; /* FS memory pool */
|
||||
switch_endpoint_interface_t *m_pH323EndpointInterface; /* FS endpoint inerface */
|
||||
switch_hash_t *m_pSessionsHashTable; /* Stores pointrs to session object
|
||||
* for each OpalCall. Each OpalCall object
|
||||
* as used in this module, stores only one
|
||||
* OpalConnection. Neither OpalCall or
|
||||
* OpalConnection have any private data pointer,
|
||||
* so I can't store pointer to switch session
|
||||
* with them. Still, each OpalCall has unique
|
||||
* Token, so I store all sessions in hash table
|
||||
* where the token is the key. I could of course
|
||||
* make custom OpalCall class, which would be
|
||||
* expanded with private pointer field (which would
|
||||
* be faster), but I don't want to touch OPAL
|
||||
* code if I don't have to
|
||||
*/
|
||||
switch_mutex_t *m_pSessionsHashTableMutex; /* Protects hash table */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* __FREESWITCH_OPAL_BACKEND__ */
|
@ -1,517 +0,0 @@
|
||||
/*
|
||||
* opalh323_backend.cpp
|
||||
*
|
||||
* Backend for OpalH323 module, implements
|
||||
* H323 handling via OPAL library
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: opalh323_backend.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "opalh323_backend.h"
|
||||
|
||||
/**
|
||||
* Private structre
|
||||
*/
|
||||
|
||||
typedef struct OpalH323Private_s
|
||||
{
|
||||
OpalConnection *m_opalConnection; /** pointer to OpalConnection object */
|
||||
switch_mutex_t *m_mutex; /** mutex for synchonizing access to session object */
|
||||
switch_caller_profile_t *m_callerProfile; /** caller profile */
|
||||
|
||||
} OpalH323Private_t;
|
||||
|
||||
|
||||
static bool OpalH323Private_Create(OpalH323Private_t **o_private, switch_core_session_t *i_session)
|
||||
{
|
||||
*o_private = (OpalH323Private_t *)switch_core_session_alloc(i_session, sizeof(OpalH323Private_t));
|
||||
if(!o_private)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
if(SWITCH_STATUS_SUCCESS != switch_mutex_init(&(*o_private)->m_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(i_session)))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
static bool OpalH323Private_Delete(OpalH323Private_t *o_private)
|
||||
{
|
||||
return (switch_mutex_destroy(o_private->m_mutex)==SWITCH_STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
/** Default constructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager::FSOpalManager() :
|
||||
m_isInitialized(false),
|
||||
m_pH323Endpoint(NULL),
|
||||
m_pMemoryPool(NULL),
|
||||
m_pEndpointInterface(NULL),
|
||||
m_pSessionsHashTable(NULL),
|
||||
m_pSessionsHashTableMutex(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager::~FSOpalManager()
|
||||
{
|
||||
/**
|
||||
* Destroy all allocated resources, if any
|
||||
*/
|
||||
if(m_isInitialized)
|
||||
{
|
||||
delete m_pH323Endpoint;
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method does real initialization of the manager
|
||||
*/
|
||||
bool FSOpalManager::initialize(
|
||||
const char* i_modName,
|
||||
switch_memory_pool_t* i_memoryPool,
|
||||
switch_endpoint_interface_t *i_endpointInterface
|
||||
)
|
||||
{
|
||||
/* check if not initialized */
|
||||
assert(m_isInitialized);
|
||||
|
||||
/* check input parameters */
|
||||
assert(i_modName);
|
||||
assert(i_memoryPool);
|
||||
assert(i_endpointInterface);
|
||||
|
||||
|
||||
m_pModuleName = i_modName;
|
||||
m_pMemoryPool = i_memoryPool;
|
||||
m_pEndpointInterface = i_endpointInterface;
|
||||
|
||||
/**
|
||||
* Create hash table for storing pointers to session objects,
|
||||
* Each OpalConnection object will retreive it's session object using
|
||||
* its callToken as a key
|
||||
*/
|
||||
|
||||
if(switch_core_hash_init(&m_pSessionsHashTable,m_pMemoryPool)!=SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(switch_mutex_init(&m_pSessionsHashTableMutex,SWITCH_MUTEX_UNNESTED,m_pMemoryPool)!=SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* create h323 endpoint */
|
||||
m_pH323Endpoint = new H323EndPoint( *(static_cast<OpalManager*>(this)) ); ///TODO, replace prefix and signaling port by values from configuration
|
||||
if(!m_pH323Endpoint)
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* To do-> add codecs to capabilities (for call contol)
|
||||
* m_pH323Endpoint->AddCapability();
|
||||
*/
|
||||
|
||||
m_pH323Endpoint->DisableFastStart(false); ///TODO this should be configurable
|
||||
m_pH323Endpoint->DisableH245Tunneling(false); ///TODO this should be configurable
|
||||
|
||||
///TODO gatekeeper use should be configurable, I think that sevral options should be implemented in config file: use, dont use, use one of specified with priorities, try to reconnect to the topmost...
|
||||
///TODO m_pH323Endpoint->SetInitialBandwidth(initialBandwidth);
|
||||
///TODO m_pH323Endpoint->SetVendorIdentifierInfo()
|
||||
|
||||
///TODO address should be configurable, should allow creaeing listeners on multiple interfaces
|
||||
OpalTransportAddress opalTransportAddress("0.0.0.0",1720); //for time being create listener on all ip's and default port
|
||||
if(!m_pH323Endpoint->StartListeners(opalTransportAddress))
|
||||
{
|
||||
assert(0);
|
||||
switch_core_hash_destroy(&m_pSessionsHashTable);
|
||||
switch_mutex_destroy(m_pSessionsHashTableMutex);
|
||||
delete m_pH323Endpoint;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* at this point OPAL is ready to go */
|
||||
m_isInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch_core_session_t* FSOpalManager::getSessionToken(const PString &i_token)
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
return static_cast<switch_core_session_t*>(switch_core_hash_find_locked(m_pSessionsHashTable,(const char*)i_token,m_pSessionsHashTableMutex));
|
||||
}
|
||||
|
||||
void FSOpalManager::saveSessionToken(const PString &i_token,switch_core_session_t* i_session)
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_insert_locked(m_pSessionsHashTable,(const char*)i_token,i_session,m_pSessionsHashTableMutex);
|
||||
}
|
||||
|
||||
void FSOpalManager::deleteSessionToken(const PString &i_token)
|
||||
{
|
||||
assert(m_pSessionsHashTable);
|
||||
assert(m_pSessionsHashTableMutex);
|
||||
switch_core_hash_delete_locked(m_pSessionsHashTable,(const char*)i_token,m_pSessionsHashTableMutex);
|
||||
}
|
||||
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
||||
OpalConnection::StringOptions * stringOptions
|
||||
)
|
||||
{
|
||||
//TODO check if options and stringOptions fields ever apply
|
||||
return OnIncomingConnection(connection);
|
||||
}
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options ///< options for new connection (can't use default as overrides will fail)
|
||||
)
|
||||
{
|
||||
//TODO, check if options field ever applies
|
||||
return OnIncomingConnection(connection);
|
||||
}
|
||||
|
||||
BOOL FSOpalManager::OnIncomingConnection(
|
||||
OpalConnection & connection ///< Connection that is calling
|
||||
)
|
||||
{
|
||||
/* allocate new session in switch core*/
|
||||
switch_core_session_t *session = switch_core_session_request(m_pEndpointInterface , NULL);
|
||||
assert(session);
|
||||
if(!session)
|
||||
{
|
||||
///TODO add cause to the connection
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate session object?\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* allocate private resources */
|
||||
OpalH323Private_t *tech_pvt = NULL;
|
||||
if(!OpalH323Private_Create(&tech_pvt,session))
|
||||
{
|
||||
///TODO add cause to the connection
|
||||
switch_core_session_destroy(&session);
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate private object?\n");
|
||||
return false;
|
||||
}
|
||||
tech_pvt->m_opalConnection = &connection;
|
||||
|
||||
|
||||
/** Save private data in session private data, and save session in hash tabel, under GetToken() key */
|
||||
switch_core_session_set_private(session,static_cast<void*>(tech_pvt)); ///save private data in session context
|
||||
|
||||
/** Before adding this session to sessions hash table,
|
||||
* lock he mutex so no concurrent
|
||||
* callback can be runing for this connection
|
||||
* probably other callbacks are called from this task
|
||||
* but carfulness wont bite
|
||||
*/
|
||||
switch_mutex_lock(tech_pvt->m_mutex);
|
||||
/** insert connection to hash table */
|
||||
saveSessionToken(connection.GetToken(),session); ///save pointer to session in hash table, for later retreival
|
||||
|
||||
/** Create calling side profile */
|
||||
tech_pvt->m_callerProfile = switch_caller_profile_new(
|
||||
switch_core_session_get_pool(session),
|
||||
(const char*)connection.GetRemotePartyName(), /** username */
|
||||
"default", /** TODO -> this should be configurable by core */
|
||||
(const char*)connection.GetRemotePartyName(), /** caller_id_name */
|
||||
(const char*)connection.GetRemotePartyNumber(), /** caller_id_number */
|
||||
(const char*)connection.GetRemotePartyAddress(), /** network addr */
|
||||
NULL, /** ANI */
|
||||
NULL, /** ANI II */
|
||||
NULL, /** RDNIS */
|
||||
m_pModuleName, /** source */
|
||||
NULL, /** TODO -> set context */
|
||||
(const char*)connection.GetCalledDestinationNumber() /** destination_number */
|
||||
);
|
||||
|
||||
if(!tech_pvt->m_callerProfile) /* should never error */
|
||||
{
|
||||
deleteSessionToken(connection.GetToken());
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
OpalH323Private_Delete(tech_pvt);
|
||||
switch_core_session_destroy(&session);
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Set up sessions channel */
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_channel_set_name(channel,(const char*)connection.GetToken());
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->m_callerProfile);
|
||||
switch_channel_set_state(channel, CS_INIT);
|
||||
|
||||
/** Set up codecs for the channel ??? */
|
||||
|
||||
|
||||
/***Mark incoming call as AnsweredPending ??? */
|
||||
|
||||
|
||||
/** lunch thread */
|
||||
if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
|
||||
deleteSessionToken(connection.GetToken());
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
OpalH323Private_Delete(tech_pvt);
|
||||
switch_core_session_destroy(&session);
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
switch_mutex_unlock(tech_pvt->m_mutex);
|
||||
|
||||
|
||||
/* the connection can be continued!!! */
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FS ON_INIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_init(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_INIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_ring(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_EXECUTE callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_execute(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_HANGUP callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_hangup(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_LOOPBACK callback handler
|
||||
*
|
||||
*/
|
||||
|
||||
switch_status_t FSOpalManager::callback_on_loopback(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* FS ON_TRANSMIT callback handler
|
||||
*
|
||||
*/
|
||||
switch_status_t FSOpalManager::callback_on_transmit(switch_core_session_t *io_session)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_call_cause_t FSOpalManager::io_outgoing_channel(switch_core_session_t *i_session, switch_caller_profile_t *i_profile, switch_core_session_t **o_newSession, switch_memory_pool_t **o_memPool)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_CAUSE_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_read_frame(switch_core_session_t *i_session, switch_frame_t **o_frame, int i_timout, switch_io_flag_t i_flag, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_write_frame(switch_core_session_t *i_session, switch_frame_t *i_frame, int i_timeout, switch_io_flag_t i_flag, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_kill_channel(switch_core_session_t *i_session, int sig)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_waitfor_read(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_waitfor_write(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_send_dtmf(switch_core_session_t *i_session, char *i_dtmf)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_receive_message(switch_core_session_t *i_session, switch_core_session_message_t *i_message)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
|
||||
OpalH323Private_t* tech_prv = static_cast<OpalH323Private_t*>(switch_core_session_get_private(i_session));
|
||||
assert(tech_prv);
|
||||
|
||||
switch_mutex_lock(tech_prv->m_mutex);
|
||||
|
||||
switch(i_message->message_id)
|
||||
{
|
||||
case SWITCH_MESSAGE_REDIRECT_AUDIO:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_REDIRECT_AUDIO\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_TRANSMIT_TEXT:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_TRANSMIT_TEXT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_ANSWER:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_ANSWER\n");
|
||||
|
||||
/* set call answer */
|
||||
//tech_prv->m_opalConnection->AnsweringCall(AnswerCallNow);
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_PROGRESS\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_BRIDGE:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_BRIDGE\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_UNBRIDGE\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_TRANSFER:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_TRANSFER\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_RINGING:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_RINGING\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_MEDIA:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_MEDIA\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_NOMEDIA\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_HOLD:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_HOLD\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_UNHOLD:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_UNHOLD\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_REDIRECT:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_REDIRECT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_REJECT:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_REJECT\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_BROADCAST:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_BROADCAST\n");
|
||||
break;
|
||||
case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG "SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT\n");
|
||||
break;
|
||||
}
|
||||
|
||||
switch_mutex_unlock(tech_prv->m_mutex);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_receive_event(switch_core_session_t *i_session, switch_event_t *i_event)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_state_change(switch_core_session_t *)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t FSOpalManager::io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int)
|
||||
{
|
||||
assert(m_isInitialized);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* opalh323_backend.cpp
|
||||
*
|
||||
* Backend for OpalH323 module, implements
|
||||
* H323 handling via OPAL library
|
||||
*
|
||||
* Copyright (c) 2007 Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of the Original Code is Lukasz Zwierko (lzwierko@gmail.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* $Log: opalh323_backend.cpp,v $
|
||||
*
|
||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
#ifndef __FREESWITCH_OPALH323_BACKEND__
|
||||
#define __FREESWITCH_OPALH323_BACKEND__
|
||||
|
||||
#include <switch.h>
|
||||
#include <ptlib.h>
|
||||
#include <opal/buildopts.h>
|
||||
#include <opal/manager.h>
|
||||
#include <h323/h323ep.h>
|
||||
|
||||
/** This class is OpalManager implementation
|
||||
* for FreeSWITCH OpalH323 module.
|
||||
* All methods are inherited from base OpalManagerClass.
|
||||
* Event callbacks will be filed with valid code
|
||||
* Additional functions have been implemented to be called, or called by
|
||||
*/
|
||||
class FSOpalManager : public OpalManager
|
||||
{
|
||||
PCLASSINFO(FSOpalManager, PObject);
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor
|
||||
*
|
||||
*/
|
||||
FSOpalManager();
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
*/
|
||||
~FSOpalManager();
|
||||
|
||||
/**
|
||||
* Method does real initialization of the manager
|
||||
*/
|
||||
bool initialize(
|
||||
const char* i_modName,
|
||||
switch_memory_pool_t* i_memoryPool,
|
||||
switch_endpoint_interface_t *i_endpointInterface
|
||||
);
|
||||
|
||||
/** FS callback handlers declarations
|
||||
*
|
||||
*/
|
||||
switch_status_t callback_on_init(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_ring(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_execute(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_hangup(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_loopback(switch_core_session_t *io_session);
|
||||
switch_status_t callback_on_transmit(switch_core_session_t *io_session);
|
||||
|
||||
/** FS io functions
|
||||
*
|
||||
*/
|
||||
|
||||
switch_call_cause_t io_outgoing_channel(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
|
||||
switch_status_t io_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
switch_status_t io_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
switch_status_t io_kill_channel(switch_core_session_t *, int);
|
||||
switch_status_t io_waitfor_read(switch_core_session_t *, int, int);
|
||||
switch_status_t io_waitfor_write(switch_core_session_t *, int, int);
|
||||
switch_status_t io_send_dtmf(switch_core_session_t *, char *);
|
||||
switch_status_t io_receive_message(switch_core_session_t *, switch_core_session_message_t *);
|
||||
switch_status_t io_receive_event(switch_core_session_t *, switch_event_t *);
|
||||
switch_status_t io_state_change(switch_core_session_t *);
|
||||
switch_status_t io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
||||
switch_status_t io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
|
||||
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
||||
OpalConnection::StringOptions * stringOptions
|
||||
);
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection, ///< Connection that is calling
|
||||
unsigned options ///< options for new connection (can't use default as overrides will fail)
|
||||
);
|
||||
|
||||
virtual BOOL OnIncomingConnection(
|
||||
OpalConnection & connection ///< Connection that is calling
|
||||
);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void saveSessionToken(const PString &i_token,switch_core_session_t* i_session);
|
||||
switch_core_session_t* getSessionToken(const PString &i_token);
|
||||
void deleteSessionToken(const PString &i_token);
|
||||
|
||||
|
||||
const char *m_pModuleName; /* name of this module */
|
||||
bool m_isInitialized; /* true if module has been initialized properly */
|
||||
H323EndPoint *m_pH323Endpoint; /* h323 endpoint control */
|
||||
switch_memory_pool_t *m_pMemoryPool; /* FS memory pool */
|
||||
switch_endpoint_interface_t *m_pEndpointInterface; /* FS endpoint inerface */
|
||||
switch_hash_t *m_pSessionsHashTable; /* Stores pointrs to session object for each Opal connection */
|
||||
switch_mutex_t *m_pSessionsHashTableMutex; /* Protects hash table */
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user