📄 srldevice.cpp
字号:
/**********@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********************************
* DIALOGIC CONFIDENTIAL
*
* Copyright (C) 2006-2007 Dialogic Corporation. All Rights Reserved.
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Dialogic Corporation or its
* suppliers or licensors. Title to the Material remains with Dialogic Corporation
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Dialogic or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Dialogic's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Dialogic in writing.
*
***********************************@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********/
//***********************************************************************
//***********************************************************************
// SrlHandle.cpp: implementation of the CSrlHandle class.
//
//////////////////////////////////////////////////////////////////////
#include <fcntl.h>
#include "pdl.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//*****************************************************************************
// Purpose :
// Constructor
// Parameters:
// [in] Device type (DEV_IPT or DEV_DTI)
// [in] Configuration parameters (from configuration file)
// [in] Optional name. When name is 0, use any available from specified type
// Returns:
// none
//*****************************************************************************
CSrlDevice::CSrlDevice(DLG_DEVICE_TYPE devtype,
PCommonParams pCommonParams,
const char *name )
: CanLog(glb_pAppLog) {
// Default
m_pPrivateLog = 0;
m_srl_state = 0;
m_srl_handle = INV_SRL_HANDLE;
m_dx_srl_handle = INV_SRL_HANDLE;
m_cnf_party_srl_handle = INV_SRL_HANDLE;
m_ntwk_srl_handle = INV_SRL_HANDLE;
m_dx_name = 0;
file_index = 0;
m_type = devtype;
m_pCommonParams = pCommonParams;
if ( glb_pDetectCfg->Reserve(m_type,&name) ) {
SetName(name);
SetSrlState(SRLSTATE_RESERVED);
}
m_pStateMachine = 0;
memset (&m_iott,0,sizeof(m_iott));
m_iott.io_fhandle = INV_FILE_HANDLE; // invalid handle
SetDfltTimer(NTWK_TMO);
m_pCnfBoard = 0;
separate_ntwk_open = false; // device opened via gc_Open
return;
} // End of Constructor()
//*****************************************************************************
// Purpose :
// Destructor
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
CSrlDevice::~CSrlDevice(){
if ( IsSrlState(SRLSTATE_RESERVED, true) ) {
glb_pDetectCfg->UnReserve(m_type, GetName());
}
delete m_pStateMachine;
// Delete private log
ClosePrivateLog();
} // End of Destructor()
//----------------------------------------------------------------
//*****************************************************************************
// Purpose :
// Open voice device associated with this object
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CSrlDevice::open_dx(){
if (!IS_VALID_HANDLE(m_dx_srl_handle) ) {
if (glb_pDetectCfg->Reserve(DEV_DX, &m_dx_name)){
SetSrlState(SRLSTATE_VOICERESERVED);
m_dx_srl_handle = dx_open(m_dx_name,0);
LOG( RCHANDLE(m_dx_srl_handle), GetName(),
"0x%x = dx_open(%s)",
m_dx_srl_handle, m_dx_name);
if (IS_VALID_HANDLE(m_dx_srl_handle )) {
SetSrlState(SRLSTATE_VOICEOPENED);
return true;
}
} else {
LOG(LOG_ERR2, GetName(), "dx_open:: no more devices left");
}
}else {
LOG(LOG_WARNING, GetName(), "dx_open:: (%s) device is already opened",m_dx_name);
}
return false;
} // End of open_dx()
//*****************************************************************************
// Purpose :
// setup voice device to receive cst events
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CSrlDevice::set_dx_cst(int events){
// Enable CST events (get digits)
int rc = dx_setevtmsk(m_dx_srl_handle, events); // dm_digits, etc
LOG( RC(rc), GetName(),
"%d = dx_setevtmsk(0x%x, events = %d)",
rc,m_dx_srl_handle, events);
bool brc = ( rc != AT_FAILURE);
if (!brc) {
process_dx_error(m_dx_srl_handle, GetName());
}
return brc;
} // End of open_dx()
//*****************************************************************************
// Purpose :
// Close voice device associated with this object
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CSrlDevice::close_dx(){
int rc = 0;
if (IS_VALID_HANDLE(m_dx_srl_handle) ) {
rc = dx_close(m_dx_srl_handle);
LOG( RC(rc), GetName(),
"%d = dx_close(0x%x) [%s]",
rc, m_dx_srl_handle, m_dx_name);
m_dx_srl_handle = INV_SRL_HANDLE;
SetSrlState(SRLSTATE_VOICEOPENED, RESET_SRL_STATE);
glb_pDetectCfg->UnReserve(DEV_DX,m_dx_name);
SetSrlState(SRLSTATE_VOICERESERVED, RESET_SRL_STATE);
}
return (rc != AT_FAILURE);
} // End of close_dx()
//*****************************************************************************
// Purpose :
// Create private log for this device and arrange LOG to refer this log
// Parameters:
// [in] verbosity
// Returns:
// bool true = success
//*****************************************************************************
bool CSrlDevice::OpenPrivateLog(MSG_TYPE verbosity){
bool brc = true;
if ( verbosity < LOG_NONE ) {
char name[_MAX_PATH];
snprintf(name, sizeof(name), "%s.log", GetName());
m_pPrivateLog = new CFileLog();
if (! m_pPrivateLog->InitLog(name, m_pCommonParams->m_maxlogsize) ){
LOG( LOG_ERR2, GetName(),
"Error creating log object(%s,%d)",
name, m_pCommonParams->m_maxlogsize );
brc = false;
} else {
// Set new log object and chain original log
m_pPrivateLog->SetVerbosity(verbosity);
m_pPrivateLog->DefineChainLog(GetLog());
SetLog(m_pPrivateLog);
} // if private log
}
return brc;
} // End of OpenPrivateLog()
//*****************************************************************************
// Purpose :
// Close previously created private log and arrange LOG to refer to global log
// Parameters:
// none
// Returns:
// bool true = success
//*****************************************************************************
bool CSrlDevice::ClosePrivateLog(){
if ( m_pPrivateLog){
CGenLog *pLog = m_pPrivateLog->GetChainedLog();
m_pPrivateLog->UnlinkChainedLog();
delete m_pPrivateLog;
m_pPrivateLog=0;
SetLog(pLog);
}
return true;
} // End of ClosePrivateLog()
//*****************************************************************************
// Purpose :
// Forward to StateMachine::FindInStates
// Parameters:
// [in] event
// [out] holder to return line in state table
// Returns:
// bool true = found
// false = not found
//*****************************************************************************
bool CSrlDevice::FindInStates(int event, PEVENT_STRU *ppNewEventLine){
if (m_pStateMachine){
return m_pStateMachine->FindInStates(GetCurrentState(), event, ppNewEventLine);
}
return false;
} // End of FindInStates()
//*****************************************************************************
// Purpose :
// Forward to StateMachine::FindInActions
// Parameters:
// [in] action
// [out] holder to return line in action table
// Returns:
// bool = found
// false = not found
//*****************************************************************************
bool CSrlDevice::FindInActions(int action, PACTION_STRU *ppNewActionLine){
if (m_pStateMachine){
return m_pStateMachine->FindInActions(GetCurrentState(), action, ppNewActionLine);
}
return false;
} // End of FindInActions()
//*****************************************************************************
// Purpose :
// Advance state machine to specified stare
// Parameters:
// [in] state
// Returns:
// none
//*****************************************************************************
void CSrlDevice::SetCurrentState(int state){
if ( m_pStateMachine){
if( S_FINAL == GetCurrentState()){
return;
}
if ( ( state != S_SAME )
&& ( S_FINAL != GetCurrentState() ) ){
m_pStateMachine->SetCurrentState(state);
LOG( LOG_DBG, GetName(),
"Current state advanced to %d %s",
state, state_name(state));
if ( IsInRelaxedState() ) {
StopTimer();
LOG(LOG_DBG,GetName(),"***Stop timer");
}else {
StartTimer();
LOG(LOG_DBG,GetName(),"***Start timer for %d ms", GetDfltTimer());
}
}else{
LOG( LOG_DBG, GetName(),
"Current state not changed: %d %s",
m_pStateMachine->GetCurrentState(),
state_name( m_pStateMachine->GetCurrentState()));
} // else - not advanced
if( S_FINAL == GetCurrentState()){
LOG( LOG_APP, GetName(), "***Final state reached");
}
} // if StateMachine exist
} // End SetCurrentState()
//-------------------------------------------------------------
// Timer
//-------------------------------------------------------------
//*****************************************************************************
// Purpose :
// Signal TMO if timer is expired
// Parameters:
// none
// Returns:
// true if timer has expired
// false if timer is off or if it is not expired yet
//*****************************************************************************
bool CSrlDevice::CheckTmo(){
bool brc = CheckTimer();
if ( brc ){
PutEvent(USREV_TIMEOUT, GetName());
DumpMissingEvents();
LOG(LOG_DBG,GetName(),"***StopTimer (Timer expired)");
}
return brc;
}// End CheckTmo()
//*****************************************************************************
// Purpose :
// indicate missing line in table actions ( log failure )
// Parameters:
// [in] action
// Returns:
// none
//*****************************************************************************
//-----------------------------------------------------------------------------
void CSrlDevice::action_table_error(int action){
LOG( LOG_ERR2, GetName(),
"Cannot find action_table entry for action %d %s, Current state is %d %s",
action, action_name(action),
GetCurrentState(), state_name(GetCurrentState()) );
return;
} // End of action_table_error()
//*****************************************************************************
// Purpose :
// Execute next step of state machine
// Parameters:
// [in] event
// Returns:
// true = success
// false = error
//*****************************************************************************
bool CSrlDevice::AdvanceStateMachine(int event){
bool brc = true;
// Normal flow;
PEVENT_STRU pEventLine;
if ( FindInStates(event, &pEventLine ) ){
int action;
PACTION_STRU pNewAction;
action = pEventLine->action;
if ( ! FindInActions(action, &pNewAction) ) {
action_table_error(action);
brc = false;
}else {
// Action line found
// Not waiting for event until action is complete
SetSrlState(SRLSTATE_WAITEVENT, RESET_SRL_STATE );
brc = Execute(action);
if (!brc) {
action = pNewAction->action_if_fail;
if ( ! FindInActions(action, &pNewAction) ) {
action_table_error(action);
brc = false;
}else {
brc = Execute(action);
if (!brc) {
// Even recover failed
LOG( LOG_ERR2, GetName(), "Recover action failed, exiting");
brc = false;
}
}
}
if (brc) {
SetCurrentState(pNewAction->state_if_pass);
}
}
}
else {
// Not found in event table
// This is possible, if notification event such as GCEV_PROCEEDING is received
LOG( LOG_WARNING, GetName(), "Can't handle this event in state (%d %s)",
GetCurrentState(), state_name(GetCurrentState()) );
}
// Indicate waiting for event
if ( ! IsInRelaxedState() ) {
SetSrlState(SRLSTATE_WAITEVENT, SET_SRL_STATE);
}
return brc;
} // End of AdvanceStateMachine()
//*****************************************************************************
// Purpose :
// Handle events
// Parameters:
// [in] event
// [in] event data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -