1. added Tuyan fix/simplification for Opal engine starting
2. some progress in call control implementation git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6138 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
cd6a8d991e
commit
14275814da
|
@ -26,11 +26,12 @@
|
||||||
*
|
*
|
||||||
* $Log: mod_opal.cpp,v $
|
* $Log: mod_opal.cpp,v $
|
||||||
*
|
*
|
||||||
* Revision 1.00 2007/10/24 07:29:52 lzwierko
|
* Revision 1.00 2007/10/24 07:29:52 Lukasz Zwierko
|
||||||
* Initial revision
|
* Initial revision
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ptlib.h>
|
||||||
|
#include <ptlib/svcproc.h>
|
||||||
#include "mod_opal.h"
|
#include "mod_opal.h"
|
||||||
#include "opal_backend.h"
|
#include "opal_backend.h"
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
@ -65,162 +66,23 @@ static switch_status_t opalh323_on_transmit(switch_core_session_t *session);
|
||||||
*/
|
*/
|
||||||
static switch_memory_pool_t *opal_pool = NULL;
|
static switch_memory_pool_t *opal_pool = NULL;
|
||||||
static switch_endpoint_interface_t *opalh323_endpoint_interface = NULL;
|
static switch_endpoint_interface_t *opalh323_endpoint_interface = NULL;
|
||||||
|
static FSOpalManager *opal_manager = NULL;
|
||||||
|
|
||||||
/**
|
|
||||||
* Declaration of PProces ancestor for OpalManager starting
|
/*
|
||||||
*
|
* This is Tuyan's Ozipek neat trick
|
||||||
|
* to initialize PProcess instance
|
||||||
|
* which is needed by OpalManager
|
||||||
*/
|
*/
|
||||||
class OpalStartProcess : public PProcess
|
class _FSOpalProcess : public PProcess
|
||||||
{
|
{
|
||||||
PCLASSINFO(OpalStartProcess, PProcess)
|
PCLASSINFO(_FSOpalProcess, PProcess)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
_FSOpalProcess(){PTrace::SetLevel(PSystemLog::Info);}; //just for fun and eyecandy ;)
|
||||||
|
void Main() {};
|
||||||
|
} FSOpalProcess;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This dunction creates new instace of
|
|
||||||
* OpalStartProcess and starts it's task
|
|
||||||
*/
|
|
||||||
static void createInstance(
|
|
||||||
const char* i_moduleName,
|
|
||||||
switch_memory_pool_t *i_memoryPool,
|
|
||||||
switch_endpoint_interface_t *i_endpointInterface)
|
|
||||||
{
|
|
||||||
assert(!s_startProcess);
|
|
||||||
assert(i_moduleName);
|
|
||||||
assert(i_memoryPool);
|
|
||||||
assert(i_endpointInterface);
|
|
||||||
|
|
||||||
PProcess::PreInitialise(0, NULL, NULL);
|
|
||||||
s_startProcess = new OpalStartProcess(i_moduleName,i_memoryPool,i_endpointInterface);
|
|
||||||
assert(s_startProcess);
|
|
||||||
if(!s_startProcess)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s_startProcess->_main(); /* run process */
|
|
||||||
delete s_startProcess; /* delete opal manager instance */
|
|
||||||
s_startProcess = NULL; /* clear pointer */
|
|
||||||
}
|
|
||||||
|
|
||||||
static OpalStartProcess* getInstance()
|
|
||||||
{
|
|
||||||
assert(s_startProcess);
|
|
||||||
return s_startProcess;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkInstanceExists()
|
|
||||||
{
|
|
||||||
return s_startProcess!=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
OpalStartProcess(
|
|
||||||
const char* i_moduleName,
|
|
||||||
switch_memory_pool_t *i_memoryPool,
|
|
||||||
switch_endpoint_interface_t *i_endpointInterface
|
|
||||||
):
|
|
||||||
PProcess("FreeSWITCH", "mod_opal"),
|
|
||||||
m_pStopCondition(NULL),
|
|
||||||
m_pModuleName(i_moduleName),
|
|
||||||
m_pMemoryPool(i_memoryPool),
|
|
||||||
m_pEndpointInterface(i_endpointInterface)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
switch_status_t status = switch_thread_cond_create(&m_pStopCondition, m_pMemoryPool);
|
|
||||||
assert(status==SWITCH_STATUS_SUCCESS);
|
|
||||||
if(status!=SWITCH_STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not init stop condition.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "OpalStartProcess created\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
~OpalStartProcess()
|
|
||||||
{
|
|
||||||
switch_thread_cond_destroy(m_pStopCondition);
|
|
||||||
|
|
||||||
m_pModuleName = NULL;
|
|
||||||
m_pMemoryPool = NULL;
|
|
||||||
m_pEndpointInterface = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
FSOpalManager *getManager()
|
|
||||||
{
|
|
||||||
assert(!m_pFSOpalManager);
|
|
||||||
return m_pFSOpalManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* main task of this PProcess */
|
|
||||||
void Main()
|
|
||||||
{
|
|
||||||
/* backend initialization */
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Begin opal backend init\n");
|
|
||||||
m_pFSOpalManager = new FSOpalManager();
|
|
||||||
assert(m_pFSOpalManager);
|
|
||||||
if(!m_pFSOpalManager) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not create opal manger\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager created\n");
|
|
||||||
|
|
||||||
if(!m_pFSOpalManager->initialize(m_pModuleName, m_pMemoryPool, m_pEndpointInterface))
|
|
||||||
{
|
|
||||||
delete m_pFSOpalManager;
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not initialize opal manger\n");
|
|
||||||
return; /* if can't initialize return general error */
|
|
||||||
}
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager initilaized and running\n");
|
|
||||||
WaitUntilStopped();
|
|
||||||
delete m_pFSOpalManager;
|
|
||||||
m_pFSOpalManager = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits until this process is terminated
|
|
||||||
* which means it exits Main() function
|
|
||||||
*/
|
|
||||||
void StopProcess()
|
|
||||||
{
|
|
||||||
switch_thread_cond_signal(m_pStopCondition);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
/*
|
|
||||||
* After entering this functon, process
|
|
||||||
* locks o condition
|
|
||||||
* and stays there until signalled
|
|
||||||
*/
|
|
||||||
|
|
||||||
void WaitUntilStopped()
|
|
||||||
{
|
|
||||||
switch_mutex_t* mutex = NULL;
|
|
||||||
switch_status_t status = switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, m_pMemoryPool);
|
|
||||||
if(status!=SWITCH_STATUS_SUCCESS)
|
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Error acquiring mutex!\n");
|
|
||||||
assert(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch_mutex_lock(mutex);
|
|
||||||
switch_thread_cond_wait(m_pStopCondition, mutex);
|
|
||||||
switch_mutex_unlock(mutex);
|
|
||||||
switch_mutex_destroy(mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static OpalStartProcess *s_startProcess;
|
|
||||||
|
|
||||||
const char *m_pModuleName;
|
|
||||||
switch_memory_pool_t *m_pMemoryPool;
|
|
||||||
switch_endpoint_interface_t *m_pEndpointInterface;
|
|
||||||
FSOpalManager *m_pFSOpalManager;
|
|
||||||
switch_thread_cond_t *m_pStopCondition; /* the main thread waits on this condition until is to be stopped */
|
|
||||||
|
|
||||||
};
|
|
||||||
OpalStartProcess* OpalStartProcess::s_startProcess = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IO routines handlers set declaration
|
* IO routines handlers set declaration
|
||||||
*/
|
*/
|
||||||
|
@ -253,8 +115,7 @@ static switch_state_handler_table_t opalh323_event_handlers = {
|
||||||
*/
|
*/
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load);
|
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load);
|
||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown);
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown);
|
||||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_opal_runtime);
|
SWITCH_MODULE_DEFINITION(mod_opal, mod_opal_load, mod_opal_shutdown, NULL);
|
||||||
SWITCH_MODULE_DEFINITION(mod_opal, mod_opal_load, mod_opal_shutdown, mod_opal_runtime);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is called on module load
|
* This function is called on module load
|
||||||
|
@ -277,26 +138,32 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load)
|
||||||
return SWITCH_STATUS_MEMERR;
|
return SWITCH_STATUS_MEMERR;
|
||||||
}
|
}
|
||||||
opalh323_endpoint_interface = (switch_endpoint_interface_t*)switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
|
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->interface_name = "opalH323";
|
||||||
opalh323_endpoint_interface->io_routines = &opalh323_io_routines;
|
opalh323_endpoint_interface->io_routines = &opalh323_io_routines;
|
||||||
opalh323_endpoint_interface->state_handler = &opalh323_event_handlers;
|
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;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This function is called after module initilization
|
|
||||||
* It sets up and run backend interface to opal
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_opal_runtime)
|
|
||||||
{
|
|
||||||
OpalStartProcess::createInstance(modname,opal_pool,opalh323_endpoint_interface);
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Opal runtime fun exit\n");
|
|
||||||
return SWITCH_STATUS_TERM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This functionis called on module teardown
|
* This functionis called on module teardown
|
||||||
* It releases all internal resources, i.e.
|
* It releases all internal resources, i.e.
|
||||||
|
@ -307,12 +174,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown)
|
||||||
{
|
{
|
||||||
/* deallocate OPAL manager */
|
/* deallocate OPAL manager */
|
||||||
|
|
||||||
OpalStartProcess::getInstance()->StopProcess(); /* terminate process */
|
delete opal_manager;
|
||||||
while(OpalStartProcess::checkInstanceExists())
|
opal_manager = NULL;
|
||||||
{
|
opal_pool = NULL;
|
||||||
switch_yield(1000); /* wait 1s in each loop */
|
opalh323_endpoint_interface = NULL;
|
||||||
}
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Opal shutdown succesfully\n");
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,62 +190,62 @@ static switch_call_cause_t opalh323_outgoing_channel(
|
||||||
switch_core_session_t **new_session,
|
switch_core_session_t **new_session,
|
||||||
switch_memory_pool_t **pool)
|
switch_memory_pool_t **pool)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_outgoing_channel(session,outbound_profile,new_session,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)
|
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 OpalStartProcess::getInstance()->getManager()->io_read_frame(session,frame,timeout,flags,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)
|
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 OpalStartProcess::getInstance()->getManager()->io_write_frame(session,frame,timeout,flags,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)
|
static switch_status_t opalh323_kill_channel(switch_core_session_t *session, int sig)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_kill_channel(session,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)
|
static switch_status_t opalh323_waitfor_read(switch_core_session_t *session, int ms, int stream_id)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_waitfor_read(session,ms,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)
|
static switch_status_t opalh323_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_waitfor_write(session,ms,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)
|
static switch_status_t opalh323_send_dtmf(switch_core_session_t *session, char *dtmf)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_send_dtmf(session,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)
|
static switch_status_t opalh323_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_receive_message(session,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)
|
static switch_status_t opalh323_receive_event(switch_core_session_t *session, switch_event_t *event)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_receive_event(session,event);
|
return opal_manager->io_receive_event(session,event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_state_change(switch_core_session_t *session)
|
static switch_status_t opalh323_state_change(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->io_state_change(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)
|
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 OpalStartProcess::getInstance()->getManager()->io_read_video_frame(session,frame,timeout,flag,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)
|
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 OpalStartProcess::getInstance()->getManager()->io_write_video_frame(session,frame,timeout,flag,stream_id);
|
return opal_manager->io_write_video_frame(session,frame,timeout,flag,stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -389,30 +254,30 @@ static switch_status_t opalh323_write_video_frame(switch_core_session_t *session
|
||||||
|
|
||||||
static switch_status_t opalh323_on_init(switch_core_session_t *session)
|
static switch_status_t opalh323_on_init(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_init(session);
|
return opal_manager->callback_on_init(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_on_ring(switch_core_session_t *session)
|
static switch_status_t opalh323_on_ring(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_ring(session);
|
return opal_manager->callback_on_ring(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_on_execute(switch_core_session_t *session)
|
static switch_status_t opalh323_on_execute(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_execute(session);
|
return opal_manager->callback_on_execute(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_on_hangup(switch_core_session_t *session)
|
static switch_status_t opalh323_on_hangup(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_hangup(session);
|
return opal_manager->callback_on_hangup(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_on_loopback(switch_core_session_t *session)
|
static switch_status_t opalh323_on_loopback(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_loopback(session);
|
return opal_manager->callback_on_loopback(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t opalh323_on_transmit(switch_core_session_t *session)
|
static switch_status_t opalh323_on_transmit(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return OpalStartProcess::getInstance()->getManager()->callback_on_transmit(session);
|
return opal_manager->callback_on_transmit(session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ bool FSOpalManager::initialize(
|
||||||
///TODO m_pH323Endpoint->SetVendorIdentifierInfo()
|
///TODO m_pH323Endpoint->SetVendorIdentifierInfo()
|
||||||
|
|
||||||
///TODO address should be configurable, should allow creaeing listeners on multiple interfaces
|
///TODO address should be configurable, should allow creaeing listeners on multiple interfaces
|
||||||
OpalTransportAddress opalTransportAddress("localhost",1720); //for time being create listener on all ip's and default port
|
OpalTransportAddress opalTransportAddress("192.168.0.1",1720); //for time being create listener on all ip's and default port
|
||||||
if(!m_pH323Endpoint->StartListeners(opalTransportAddress))
|
if(!m_pH323Endpoint->StartListeners(opalTransportAddress))
|
||||||
{
|
{
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -174,8 +174,6 @@ bool FSOpalManager::initialize(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch_core_session_t* FSOpalManager::getSessionToken(const PString &i_token)
|
switch_core_session_t* FSOpalManager::getSessionToken(const PString &i_token)
|
||||||
{
|
{
|
||||||
assert(m_pSessionsHashTable);
|
assert(m_pSessionsHashTable);
|
||||||
|
@ -197,6 +195,18 @@ void FSOpalManager::deleteSessionToken(const PString &i_token)
|
||||||
switch_core_hash_delete_locked(m_pSessionsHashTable,(const char*)i_token,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(
|
BOOL FSOpalManager::OnIncomingConnection(
|
||||||
OpalConnection & connection, ///< Connection that is calling
|
OpalConnection & connection, ///< Connection that is calling
|
||||||
|
@ -263,7 +273,7 @@ BOOL FSOpalManager::OnIncomingConnection(
|
||||||
"default", /** TODO -> this should be configurable by core */
|
"default", /** TODO -> this should be configurable by core */
|
||||||
(const char*)connection.GetRemotePartyName(), /** caller_id_name */
|
(const char*)connection.GetRemotePartyName(), /** caller_id_name */
|
||||||
(const char*)connection.GetRemotePartyNumber(), /** caller_id_number */
|
(const char*)connection.GetRemotePartyNumber(), /** caller_id_number */
|
||||||
(const char*)connection.GetRemotePartyAddress(), /** network addr */
|
(const char*)connection.GetRemotePartyAddress(),/** network addr */
|
||||||
NULL, /** ANI */
|
NULL, /** ANI */
|
||||||
NULL, /** ANI II */
|
NULL, /** ANI II */
|
||||||
NULL, /** RDNIS */
|
NULL, /** RDNIS */
|
||||||
|
@ -313,7 +323,17 @@ BOOL FSOpalManager::OnIncomingConnection(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpalConnection::AnswerCallResponse FSOpalManager::OnAnswerCall(
|
||||||
|
OpalConnection &connection,
|
||||||
|
const PString &caller)
|
||||||
|
{
|
||||||
|
switch_core_session_t *session = getSessionToken((const char*)connection.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::AnswerCallDeferred; //don't send alerting signal yet
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,6 +346,22 @@ BOOL FSOpalManager::OnIncomingConnection(
|
||||||
switch_status_t FSOpalManager::callback_on_init(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_init(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
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);
|
||||||
|
/* Move Channel's State Machine to RING */
|
||||||
|
switch_channel_set_state(channel, CS_RING);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,6 +372,7 @@ switch_status_t FSOpalManager::callback_on_init(switch_core_session_t *io_sessio
|
||||||
switch_status_t FSOpalManager::callback_on_ring(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_ring(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_ring\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,6 +383,7 @@ switch_status_t FSOpalManager::callback_on_ring(switch_core_session_t *io_sessio
|
||||||
switch_status_t FSOpalManager::callback_on_execute(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_execute(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_execute\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,6 +394,20 @@ switch_status_t FSOpalManager::callback_on_execute(switch_core_session_t *io_ses
|
||||||
switch_status_t FSOpalManager::callback_on_hangup(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_hangup(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
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 */
|
||||||
|
deleteSessionToken(tech_prv->m_opalConnection->GetToken()); //delete this connection form connection pool
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(io_session);
|
||||||
|
if(tech_prv->m_opalConnection)
|
||||||
|
{
|
||||||
|
//switch_call_cause_t cause = switch_channel_get_cause(channel);
|
||||||
|
tech_prv->m_opalConnection->Release(); ///TODO add cause
|
||||||
|
}
|
||||||
|
switch_mutex_unlock(tech_prv->m_mutex);
|
||||||
|
OpalH323Private_Delete(tech_prv);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +419,7 @@ switch_status_t FSOpalManager::callback_on_hangup(switch_core_session_t *io_sess
|
||||||
switch_status_t FSOpalManager::callback_on_loopback(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_loopback(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_loopback\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,48 +430,56 @@ switch_status_t FSOpalManager::callback_on_loopback(switch_core_session_t *io_se
|
||||||
switch_status_t FSOpalManager::callback_on_transmit(switch_core_session_t *io_session)
|
switch_status_t FSOpalManager::callback_on_transmit(switch_core_session_t *io_session)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"callback_on_transmit\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
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)
|
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);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_outgoing_channel\n");
|
||||||
return SWITCH_CAUSE_SUCCESS;
|
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)
|
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);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_read_frame\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
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)
|
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);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_write_frame\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_status_t FSOpalManager::io_kill_channel(switch_core_session_t *i_session, int sig)
|
switch_status_t FSOpalManager::io_kill_channel(switch_core_session_t *i_session, int sig)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_kill_channel\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_status_t FSOpalManager::io_waitfor_read(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
switch_status_t FSOpalManager::io_waitfor_read(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_waitfor_read\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_status_t FSOpalManager::io_waitfor_write(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
switch_status_t FSOpalManager::io_waitfor_write(switch_core_session_t *i_session, int i_ms, int i_streamId)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_waitfor_write\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_status_t FSOpalManager::io_send_dtmf(switch_core_session_t *i_session, char *i_dtmf)
|
switch_status_t FSOpalManager::io_send_dtmf(switch_core_session_t *i_session, char *i_dtmf)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_send_dtmf\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,6 +545,8 @@ switch_status_t FSOpalManager::io_receive_message(switch_core_session_t *i_sessi
|
||||||
case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
|
case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT\n");
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"SWITCH_MESSAGE_???\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_mutex_unlock(tech_prv->m_mutex);
|
switch_mutex_unlock(tech_prv->m_mutex);
|
||||||
|
@ -493,23 +556,27 @@ switch_status_t FSOpalManager::io_receive_message(switch_core_session_t *i_sessi
|
||||||
switch_status_t FSOpalManager::io_receive_event(switch_core_session_t *i_session, switch_event_t *i_event)
|
switch_status_t FSOpalManager::io_receive_event(switch_core_session_t *i_session, switch_event_t *i_event)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_receive_event\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_status_t FSOpalManager::io_state_change(switch_core_session_t *)
|
switch_status_t FSOpalManager::io_state_change(switch_core_session_t *)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_state_change\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
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)
|
switch_status_t FSOpalManager::io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_read_video_frame\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
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)
|
switch_status_t FSOpalManager::io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int)
|
||||||
{
|
{
|
||||||
assert(m_isInitialized);
|
assert(m_isInitialized);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG ,"io_write_video_frame\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,35 @@
|
||||||
#include <opal/manager.h>
|
#include <opal/manager.h>
|
||||||
#include <h323/h323ep.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
|
/** This class is OpalManager implementation
|
||||||
* for FreeSWITCH OpalH323 module.
|
* for FreeSWITCH OpalH323 module.
|
||||||
* All methods are inherited from base OpalManagerClass.
|
* All methods are inherited from base OpalManagerClass.
|
||||||
|
@ -94,6 +123,13 @@ public:
|
||||||
switch_status_t io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
|
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);
|
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(
|
virtual BOOL OnIncomingConnection(
|
||||||
OpalConnection & connection, ///< Connection that is calling
|
OpalConnection & connection, ///< Connection that is calling
|
||||||
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
unsigned options, ///< options for new connection (can't use default as overrides will fail)
|
||||||
|
@ -108,6 +144,16 @@ public:
|
||||||
OpalConnection & connection ///< Connection that is calling
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -116,6 +162,9 @@ private:
|
||||||
switch_core_session_t* getSessionToken(const PString &i_token);
|
switch_core_session_t* getSessionToken(const PString &i_token);
|
||||||
void deleteSessionToken(const PString &i_token);
|
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 */
|
const char *m_pModuleName; /* name of this module */
|
||||||
bool m_isInitialized; /* true if module has been initialized properly */
|
bool m_isInitialized; /* true if module has been initialized properly */
|
||||||
|
|
Loading…
Reference in New Issue