mod_opal now loads and unloads without core dump, h323 endpoint seems to be established but call handling is yet to be implemented

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6119 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Łukasz Zwierko 2007-11-01 09:24:48 +00:00
parent 823fb40226
commit b416d80212
2 changed files with 23 additions and 51 deletions

View File

@ -109,6 +109,11 @@ class OpalStartProcess : public PProcess
return s_startProcess; return s_startProcess;
} }
static bool checkInstanceExists()
{
return s_startProcess!=NULL;
}
OpalStartProcess( OpalStartProcess(
const char* i_moduleName, const char* i_moduleName,
switch_memory_pool_t *i_memoryPool, switch_memory_pool_t *i_memoryPool,
@ -116,7 +121,6 @@ class OpalStartProcess : public PProcess
): ):
PProcess("FreeSWITCH", "mod_opal"), PProcess("FreeSWITCH", "mod_opal"),
m_pStopCondition(NULL), m_pStopCondition(NULL),
m_pWaitCondition(NULL),
m_pModuleName(i_moduleName), m_pModuleName(i_moduleName),
m_pMemoryPool(i_memoryPool), m_pMemoryPool(i_memoryPool),
m_pEndpointInterface(i_endpointInterface) m_pEndpointInterface(i_endpointInterface)
@ -130,26 +134,16 @@ class OpalStartProcess : public PProcess
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not init stop condition."); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not init stop condition.");
return; return;
} }
status = switch_thread_cond_create(&m_pWaitCondition, m_pMemoryPool);
assert(status==SWITCH_STATUS_SUCCESS);
if(status!=SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can not init wait condition.");
return;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "OpalStartProcess created\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "OpalStartProcess created\n");
} }
~OpalStartProcess() ~OpalStartProcess()
{ {
switch_thread_cond_destroy(m_pWaitCondition);
switch_thread_cond_destroy(m_pStopCondition); switch_thread_cond_destroy(m_pStopCondition);
m_pModuleName = NULL; m_pModuleName = NULL;
m_pMemoryPool = NULL; m_pMemoryPool = NULL;
m_pEndpointInterface = NULL; m_pEndpointInterface = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "OpalStartProcess deleted\n");
} }
FSOpalManager *getManager() FSOpalManager *getManager()
@ -179,39 +173,16 @@ class OpalStartProcess : public PProcess
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager initilaized and running\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager initilaized and running\n");
WaitUntilStopped(); WaitUntilStopped();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "OpalStartProcess received stop signal\n");
delete m_pFSOpalManager; delete m_pFSOpalManager;
m_pFSOpalManager = NULL; m_pFSOpalManager = NULL;
switch_thread_cond_signal(m_pWaitCondition); /* signal task waiting that it's all over ... */
} }
/** /**
* Waits until this process is terminated * Waits until this process is terminated
* which means it exits Main() function * which means it exits Main() function
*/ */
void WaitProcess() void StopProcess()
{ {
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_pWaitCondition,mutex);
switch_mutex_unlock(mutex);
switch_mutex_destroy(mutex);
}
/**
* Waits until this process is terminated
* which means it exits Main() function
*/
void StopProcessAndWait()
{
switch_mutex_lock(m_pStopMutex)
switch_thread_cond_signal(m_pStopCondition); switch_thread_cond_signal(m_pStopCondition);
} }
@ -246,10 +217,6 @@ class OpalStartProcess : public PProcess
switch_endpoint_interface_t *m_pEndpointInterface; switch_endpoint_interface_t *m_pEndpointInterface;
FSOpalManager *m_pFSOpalManager; FSOpalManager *m_pFSOpalManager;
switch_thread_cond_t *m_pStopCondition; /* the main thread waits on this condition until is to be stopped */ switch_thread_cond_t *m_pStopCondition; /* the main thread waits on this condition until is to be stopped */
switch_thread_cond_t *m_pWaitCondition; /* condition for managing thread to wait on until this process exits */
switch_mutex_t *m_pStopMutex;
switch_mutex_t *m_pWaitMutex;
}; };
OpalStartProcess* OpalStartProcess::s_startProcess = NULL; OpalStartProcess* OpalStartProcess::s_startProcess = NULL;
@ -326,7 +293,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load)
SWITCH_MODULE_RUNTIME_FUNCTION(mod_opal_runtime) SWITCH_MODULE_RUNTIME_FUNCTION(mod_opal_runtime)
{ {
OpalStartProcess::createInstance(modname,opal_pool,opalh323_endpoint_interface); OpalStartProcess::createInstance(modname,opal_pool,opalh323_endpoint_interface);
return SWITCH_STATUS_SUCCESS; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Opal runtime fun exit\n");
return SWITCH_STATUS_TERM;
} }
/* /*
@ -340,7 +308,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown)
/* deallocate OPAL manager */ /* deallocate OPAL manager */
OpalStartProcess::getInstance()->StopProcess(); /* terminate process */ OpalStartProcess::getInstance()->StopProcess(); /* terminate process */
OpalStartProcess::getInstance()->WaitProcess(); /* wait here until stopped */ while(OpalStartProcess::checkInstanceExists())
{
switch_yield(1000); /* wait 1s in each loop */
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Opal shutdown succesfully\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -87,10 +87,10 @@ FSOpalManager::~FSOpalManager()
{ {
/** /**
* Destroy all allocated resources, if any * Destroy all allocated resources, if any
* !! all endpoints are automatically deleted in ~OpalManager, so leave them
*/ */
if(m_isInitialized) if(m_isInitialized)
{ {
delete m_pH323Endpoint;
switch_mutex_destroy(m_pSessionsHashTableMutex); switch_mutex_destroy(m_pSessionsHashTableMutex);
switch_core_hash_destroy(&m_pSessionsHashTable); switch_core_hash_destroy(&m_pSessionsHashTable);
@ -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("0.0.0.0",1720); //for time being create listener on all ip's and default port OpalTransportAddress opalTransportAddress("localhost",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);