📄 cnfboard.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@@@**********/
//***********************************************************************
//***********************************************************************
// CnfBoard.cpp: implementation of the CnfBoard class.
//
//////////////////////////////////////////////////////////////////////
#include "pdl.h"
static const char * CNF_MODULE_NAME = "SdpParser";
/////////////////////////////////////////////////////////////////////////////
// State machine definition
/////////////////////////////////////////////////////////////////////////////
// States (in addition to pre_defined S_BEGIN, S_FINAL etc.)
enum {
S_SETATTR = 0, // Set Attributes
S_SETATTR_EXIT, // Set Attributes (exiting)
S_ENABLEEVT, // Enable Events
S_ENABLEEVT_EXIT, // Enable Events ( exiting)
S_DEVCNT, // Count sub-devices
S_DEVCNT_EXIT, // Count sub-devices (exiting)
S_DISABLEEVT, // Disable Events
};
static NAME_TABLE state_tbl[] = {
{"S_SETATTR", S_SETATTR},
{"S_SETATTR_EXIT", S_SETATTR_EXIT},
{"S_ENABLEEVT", S_ENABLEEVT},
{"S_ENABLEEVT_EXIT", S_ENABLEEVT_EXIT},
{"S_DEVCNT", S_DEVCNT},
{"S_DEVCNT_EXIT", S_DEVCNT_EXIT},
{"S_DISABLEEVT", S_DISABLEEVT},
{0, 0}
}; // End of state_tbl[]
//*****************************************************************************
// Purpose :
// return state name for given value
// Parameters:
// [in] state
// Returns:
// name
//*****************************************************************************
const char * CnfBoard::state_name(int state){
const char *name;
if (! str_findname(state,&name,state_tbl) ){
name = common_state_name(state);
}
return name;
} // End of state_name()
//==========================================================
// Action codes
enum {
A_SETATTR, // set parameters
A_ENABLEEVT, // Enable events
A_DEVCNT, // Get cnf device count
A_CREATECONF, // Create Conferences
A_TRYCLOSE, // Count Conferences and close if number is 0
};
static NAME_TABLE ac_tbl[] = {
{ "A_SETATTR", A_SETATTR },
{ "A_ENABLEEVT", A_ENABLEEVT },
{ "A_DEVCNT", A_DEVCNT },
{ "A_CREATECONF", A_CREATECONF },
{ "A_TRYCLOSE", A_TRYCLOSE },
{ 0,0 }
}; // End of ac_tbl[]
//*****************************************************************************
// Purpose :
// return action name for given value
// Parameters:
// [in] action
// Returns:
// name
//*****************************************************************************
const char * CnfBoard::action_name(int action){
const char *name;
if (! str_findname(action, &name, ac_tbl) ){
name = common_action_name(action);
}
return name;
}// End of action_name()
//
// Action table
// { current_state action state_if_pass, action_if_fail, state_if_fail}
//
//====================================================================================
// OPEN -> SET_ATTR -> ENABLEEVENTS -> DEVCNT -> CREATE CONFERENCES and RELAX
// S_OPEN ->S_SETATTR-> S_ENABLEEVT -> S_DEVCNT -> S_RELAX
static ACTION_STRU board_action_stru[] = {
// current_state action state_if_pass action(fail)
{ S_ANY, A_CLOSE, S_FINAL, A_GIVEUP },
{ S_ANY, A_GIVEUP, S_FINAL, A_NONE },
{ S_OPEN, A_SETATTR, S_SETATTR, A_CLOSE },
{ S_OPEN, A_EXIT, S_OPEN_EXIT, A_CLOSE },
{ S_SETATTR, A_ENABLEEVT, S_ENABLEEVT, A_CLOSE },
{ S_SETATTR, A_EXIT, S_SETATTR_EXIT, A_CLOSE },
{ S_ENABLEEVT, A_DEVCNT, S_DEVCNT, A_CLOSE },
{ S_ENABLEEVT, A_EXIT, S_ENABLEEVT_EXIT, A_CLOSE },
{ S_DEVCNT, A_CREATECONF, S_RELAX, A_CLOSE },
{ S_DEVCNT, A_EXIT, S_DEVCNT_EXIT, A_CLOSE },
{ S_RELAX, A_TRYCLOSE, S_DISABLEEVT, A_NONE },
{ S_WAIT_SUBDEV, A_TRYCLOSE, S_DISABLEEVT, A_NONE },
{ S_DISABLEEVT, A_CLOSE, S_FINAL, A_NONE },
// No operation
{ S_ANY, A_NONE, S_SAME, A_NONE },
// State machine error (missing case to handle specified action)
{ S_RELAX, A_ERROR, S_SAME, A_CLOSE },
{ S_ANY, A_ERROR, S_SAME, A_CLOSE },
// Not part of state machine, indicates last line
{ S_END, 0, 0, 0 }
}; // End of board_action_stru[]
//------------------------------------------------------------------------------------
static EVENT_STRU board_event_stru[] = {
// current_state event action
// After Open
{ S_OPEN, CNFEV_OPEN, A_SETATTR },
{ S_OPEN, CNFEV_OPEN_FAIL, A_CLOSE },
{ S_OPEN, USREV_EXIT_REQUEST, A_EXIT },
{ S_OPEN, USREV_TIMEOUT, A_CLOSE },
{ S_OPEN_EXIT, CNFEV_OPEN, A_CLOSE, },
{ S_OPEN_EXIT, CNFEV_OPEN_FAIL, A_CLOSE, },
{ S_OPEN_EXIT, USREV_TIMEOUT, A_CLOSE, },
// After Set Attributes
{ S_SETATTR, CNFEV_SET_ATTRIBUTE, A_ENABLEEVT },
{ S_SETATTR, CNFEV_SET_ATTRIBUTE_FAIL, A_CLOSE },
{ S_SETATTR, USREV_EXIT_REQUEST, A_EXIT },
{ S_SETATTR, USREV_TIMEOUT, A_CLOSE },
{ S_SETATTR_EXIT, CNFEV_SET_ATTRIBUTE, A_CLOSE },
{ S_SETATTR_EXIT, CNFEV_SET_ATTRIBUTE_FAIL, A_CLOSE },
{ S_SETATTR_EXIT, USREV_TIMEOUT, A_CLOSE },
// After Enable events
{ S_ENABLEEVT, CNFEV_ENABLE_EVENT, A_DEVCNT },
{ S_ENABLEEVT, CNFEV_ENABLE_EVENT_FAIL, A_CLOSE },
{ S_ENABLEEVT, USREV_EXIT_REQUEST, A_EXIT },
{ S_ENABLEEVT, USREV_TIMEOUT, A_CLOSE },
{ S_ENABLEEVT_EXIT, CNFEV_ENABLE_EVENT, A_CLOSE },
{ S_ENABLEEVT_EXIT, CNFEV_ENABLE_EVENT_FAIL, A_CLOSE },
{ S_ENABLEEVT_EXIT, USREV_TIMEOUT, A_CLOSE },
// After GetDeviceCount
{ S_DEVCNT, CNFEV_GET_DEVICE_COUNT, A_CREATECONF},
{ S_DEVCNT, CNFEV_GET_DEVICE_COUNT_FAIL, A_CLOSE },
{ S_DEVCNT, USREV_EXIT_REQUEST, A_EXIT },
{ S_DEVCNT, USREV_TIMEOUT, A_CLOSE },
{ S_DEVCNT_EXIT, CNFEV_GET_DEVICE_COUNT, A_CLOSE },
{ S_DEVCNT_EXIT, CNFEV_GET_DEVICE_COUNT_FAIL, A_CLOSE },
{ S_DEVCNT_EXIT, USREV_TIMEOUT, A_CLOSE },
// Exit Request
{ S_RELAX, USREV_EXIT_REQUEST, A_TRYCLOSE },
{ S_WAIT_SUBDEV, USREV_EXIT_REQUEST, A_TRYCLOSE },
{ S_WAIT_SUBDEV, CNFEV_CONF_CLOSED, A_TRYCLOSE },
{ S_WAIT_SUBDEV, CNFEV_PARTY_REMOVED, A_TRYCLOSE },
{ S_DISABLEEVT, CNFEV_DISABLE_EVENT, A_CLOSE },
{ S_DISABLEEVT, CNFEV_DISABLE_EVENT_FAIL, A_CLOSE },
{ S_WAIT_SUBDEV, USREV_TIMEOUT, A_CLOSE },
// No timeouts in Relax state
{ S_RELAX, USREV_TIMEOUT, A_NONE },
// USREV_CNF_OPEN and CLOSE
{ S_ANY, USREV_CNF_OPEN, A_NONE },
{ S_ANY, CNFEV_CONF_CLOSED, A_NONE },
{ S_ANY, CNFEV_CONF_OPENED, A_NONE },
{ S_ANY, CNFEV_PARTY_ADDED, A_NONE },
{ S_ANY, CNFEV_PARTY_REMOVED, A_NONE },
//Anything else falls here
{ S_ANY, EVENT_ANY, A_ERROR },
{ S_END, 0, 0 }
}; // End of board_state_stru[]
//*****************************************************************************
// Purpose :
// Execute an action
// Parameters:
// [in] action
// Returns:
// true = success
// false = error
//*****************************************************************************
bool CnfBoard::Execute(int action){
bool brc = true;
switch(action) {
case A_ERROR:
// Indicate error
StateMachineError();
break;
case A_GIVEUP: // do nothing but advance state machine
SetSrlState(SRLSTATE_ALL, RESET_SRL_STATE);
SetCurrentState(S_FINAL);
break;
case A_NONE: // do nothing
case A_EXIT: // do nothing but advance state machine
break;
case A_CLOSE:
brc = Close();
break;
case A_SETATTR:
brc = SetAttributes();
break;
case A_ENABLEEVT:
brc = EnableEvents();
break;
case A_DEVCNT:
brc = GetDeviceCount();
break;
case A_CREATECONF:
brc = CreateConferences();
// And relax
SetSrlState(SRLSTATE_INIT_COMPLETE );
LOG(LOG_APP, GetName(), "Initialization complete");
break;
case A_TRYCLOSE:
brc = TryClose();
break;
default:
LOG(LOG_ERR1, GetName(),
"CnfBoard: App error. Missing case to handle action #%d %s",
action, action_name(action) );
TryClose();
break;
} // switch action
return brc;
} // End of Execute()
//*****************************************************************************
// Purpose :
// Handle events
// Parameters:
// [in] event
// [in] event data
// [in] data length
// [in] METAEVENT (not used)
// Returns:
// none
//*****************************************************************************
void CnfBoard::HandleEvent(int event,
void *evtdata, int evtlen,
METAEVENT *metaeventp){
switch (event){
case CNFEV_OPEN_FAIL:
SetSrlState(SRLSTATE_FAILED_FATAL);
break;
case CNFEV_GET_DEVICE_COUNT:
{
CPCNF_DEVICE_COUNT_INFO pInfo = (CPCNF_DEVICE_COUNT_INFO) evtdata;
cnf_dump(pInfo);
m_max_conf_count = pInfo->unFreeConfCount;
}
break;
case CNFEV_OPEN:
break;
case CNFEV_PARTY_REMOVED:
LOG( LOG_DBG, GetName(),
"Number of parties: %d",
--m_number_of_parties);
break;
case CNFEV_PARTY_ADDED:
LOG( LOG_DBG, GetName(),
"Number of parties: %d",
++m_number_of_parties);
break;
case CNFEV_CONF_CLOSED:
LOG( LOG_DBG, GetName(),
"Number of conferences: %d",
--m_number_of_conferences);
break;
case USREV_CNF_OPEN:
LOG(LOG_DBG, GetName(),
"Number of conferences: %d",
++m_number_of_conferences);
break;
default:
break;
} // switch event
CSrlDevice::HandleEvent(event, evtdata, evtlen, metaeventp);
return;
} // End of HandleEvent()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//*****************************************************************************
// Purpose :
// Constructor
// Parameters:
// Configuration parameters ( from configuration file )
// Returns:
// none
//*****************************************************************************
CnfBoard::CnfBoard(PCommonParams pCommonParams,
PBrdParams pBrdParams,
PCnfPrmContainer pCnfPrmContainer)
: CSrlDeviceContainer(DEV_CNFBOARD, pCommonParams, 0) {
brd_ActiveTalker = pBrdParams->m_brd_active_talker?ECNF_ATTR_STATE_ENABLED : ECNF_ATTR_STATE_DISABLED ;
brd_ATInterval = pBrdParams->m_brd_at_interval;
brd_DTMFClamping = pBrdParams->m_brd_dtmf_clamping?ECNF_ATTR_STATE_ENABLED : ECNF_ATTR_STATE_DISABLED ;
m_pCnfPrmContainer = pCnfPrmContainer; // get list of conference parameters
m_pBrdParams = pBrdParams;
m_max_conf_count = 0;
m_number_of_conferences = 0;
m_number_of_parties = 0;
if (IsSrlState(SRLSTATE_RESERVED, true) ){
OpenPrivateLog(pBrdParams->m_log_level);
glb_pConferencePool->push_back(this);
SetDfltTimer(BOARD_TMO);
pBrdParams->Dump(GetLog());
// State Machine
if ( SetStateMachine(board_event_stru, board_action_stru) ) {
// Open this board
Open();
}
} else {
LOG(LOG_ERR2, CNF_MODULE_NAME, "Cannot reserve CNF board ");
SetExitCode(EXIT_INIT);
}
return;
} // End of Constructor()
//*****************************************************************************
// Purpose :
// Destructor
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
CnfBoard::~CnfBoard() {
// If any conference exist (as a result of error)
// clean references to this board
list<PSrlDevice>::iterator pos;
PCnfConference pConf;
for ( pos = begin(); pos != end(); ++pos) {
pConf = static_cast<PCnfConference>(*pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -