📄 cnfconference.cpp
字号:
{ S_RELAX, USREV_BEEP_IN, A_BEEP_IN },
// cnf timeouts in Relax state
{ S_RELAX, USREV_CNF_TIMEOUT, A_BEEP_BYE },
{ S_ANY, USREV_BEEP_OUT, A_NONE }, // dont beep in any other state
{ S_ANY, USREV_BEEP_IN, A_NONE },
{ S_BEEP, USREV_TIMEOUT, A_MOVE },
{ S_BEEP, TDX_ERROR, A_MOVE },
{ S_BEEP, TDX_PLAYTONE, A_MOVE },
// in case play or record instead beeping
{ S_BEEP, TDX_PLAY, A_MOVE },
{ S_BEEP, TDX_RECORD, A_MOVE },
{ S_BEEP_EXIT, TDX_PLAYTONE, A_DEVDISCONNECTDX },
{ S_BEEP_EXIT, TDX_ERROR, A_DEVDISCONNECTDX },
{ S_BEEP_EXIT, USREV_TIMEOUT, A_DEVDISCONNECTDX },
{ S_BEEP_BYE, TDX_PLAYTONE, A_DISBAND },
{ S_BEEP_BYE, TDX_ERROR, A_DEVDISCONNECTDX },
{ S_BEEP_BYE, USREV_TIMEOUT, A_DEVDISCONNECTDX },
{ S_BEEP_BYE, USREV_EXIT_REQUEST, A_EXIT },
{ S_WAIT_SUBDEV, USREV_EXIT_REQUEST, A_TRYCLOSE },
// { S_WAIT_SUBDEV, CNFEV_PARTY_REMOVED, A_TRYCLOSE },
{ S_WAIT_SUBDEV, USREV_PARTY_REMOVED, A_TRYCLOSE },
{ S_WAIT_SUBDEV, USREV_CNF_TIMEOUT, A_CLOSE },
{ S_ANY, CNFEV_PARTY_REMOVED, A_NONE },
{ S_ANY, USREV_PARTY_REMOVED, A_NONE },
// Dev disconnect
{ S_DEVDISCONNECTDX, USREV_SKIP_VOICE, A_TRYCLOSE },
{ S_DEVDISCONNECTDX, DMEV_DISCONNECT_FAIL, A_DEVDISCONNECTCNF },
{ S_DEVDISCONNECTDX, DMEV_DISCONNECT, A_DEVDISCONNECTCNF },
{ S_DEVDISCONNECTDX, USREV_TIMEOUT, A_DEVDISCONNECTCNF },
{ S_DEVDISCONNECTCNF, DMEV_DISCONNECT, A_REMOVE_DX_PARTY },
{ S_DEVDISCONNECTCNF, DMEV_DISCONNECT_FAIL, A_REMOVE_DX_PARTY },
{ S_DEVDISCONNECTCNF, USREV_TIMEOUT, A_REMOVE_DX_PARTY },
{ S_REMOVE_DX_PARTY, CNFEV_REMOVE_PARTY, A_TRYCLOSE },
{ S_REMOVE_DX_PARTY, CNFEV_REMOVE_PARTY_FAIL, A_TRYCLOSE },
{ S_REMOVE_DX_PARTY, USREV_TIMEOUT, A_TRYCLOSE },
{ S_ANY, CNFEV_PARTY_ADDED, A_NONE },
//Anything else falls here
{ S_ANY, EVENT_ANY, A_ERROR },
{ S_END, 0, 0 }
}; // End of cnf_evemt_stru[]
//*****************************************************************************
// Purpose :
// Execute next step of state machine
// Parameters:
// [in] action
// Returns:
// true = success
// false = error
//*****************************************************************************
bool CnfConference::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
case A_MOVE: // do nothing but advance state machine to next
case A_MOVE_DEVCONNECT2_EXIT: // do nothing but advance to devdisconnect2_exit
break;
case A_CLOSE:
brc = Close();
break;
case A_SETATTR:
brc = SetAttributes();
break;
case A_ENABLEEVENTS:
brc = EnableEvents();
break;
case A_TRYCLOSE:
brc = TryClose();
break;
case A_RELAX:
SetSrlState(SRLSTATE_INIT_COMPLETE );
LOG(LOG_APP, GetName(), "Initialization complete, password = %s", conf_PassCode);
break;
case A_OPEN_DX_PARTY:
brc = TryOpenParty();
break;
case A_ADD_DX_PARTY:
brc = AddPartyLocal();
break;
case A_DEVCONNECT:
brc = DevConnect(DEV_DX_PARTY);
break;
case A_DEVDISCONNECTDX:
TryDevDisconnectDx();
break;
case A_DEVDISCONNECTCNF:
brc = DevDisconnect(DEV_CNF_PARTY);
break;
case A_REMOVE_DX_PARTY:
brc = RemovePartyLocal();
break;
case A_CLOSE_DX_PARTY:
CloseParty();
TryClose();
break;
case A_BEEP_IN:
if (conf_VoiceParty){
brc = DxBeep(BEEP_IN);
}else {
brc = false;
}
break;
case A_BEEP_OUT:
if (conf_VoiceParty){
brc = DxBeep(BEEP_OUT);
}else {
brc = false;
}
break;
case A_BEEP_BYE:
if ( conf_VoiceParty ){
DxBeep(BEEP_BYE);
}else {
brc = false;
}
break;
case A_DISBAND:
LOG(LOG_APP,GetName(),"**Conference timed out");
SignalToMembers(USREV_LEAVE_CNF);
break;
default:
LOG( LOG_ERR1, GetName(),
"CnfConference: App error. Missing case to handle action #%d %s",
action, action_name(action) );
TryClose();
break;
} // switch action
return brc;
} // End Execute()
//*****************************************************************************
// Purpose :
// Handle events
// Parameters:
// [in] event
// [in] event data
// [in] data length
// [in] METAEVENT (not used)
// Returns:
// none
//*****************************************************************************
void CnfConference::HandleEvent(int event,
void *evtdata, int evtlen,
METAEVENT *metaeventp ){
switch (event){
case USREV_PARTY_REMOVED:
{ PSrlDevice pDev = *(PSrlDevice*)evtdata;
if (pDev != this){
m_CnfList.remove(pDev);
DumpMembers();
}
if ( cnf_size() == 0) {
m_cnf_timer.StopTimer();
LOG(LOG_DBG,GetName(),"***Stop cnf timer");
}
}
break;
case CNFEV_OPEN_CONF_FAIL:
SetSrlState(SRLSTATE_FAILED_FATAL);
break;
case CNFEV_OPEN_CONF:
{ PCNF_OPEN_CONF_RESULT pResult = static_cast<PCNF_OPEN_CONF_RESULT>(evtdata);
SetName(pResult->szConfName);
cnf_dump(pResult);
}
break;
default:
break;
} // switch event
CSrlDevice::HandleEvent(event, evtdata, evtlen, metaeventp);
return;
} // End HandleEvent()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//*****************************************************************************
// Purpose :
// Constructor
// Parameters:
// [in ] Cnf Board ( that hosts this conference )
// [in ] Configuration parameters ( from configuration file )
// [in ] This Conference parameters ( from configuration file )
// Returns:
// none
//*****************************************************************************
CnfConference::CnfConference(PCnfBoard pCnfBoard,
PCommonParams pCommonParams,
PCnfParams pCnfParams)
: CSrlDevice(DEV_CNFCONFERENCE, pCommonParams, 0) {
conf_DTMFClamping = pCnfParams->dtmf_clamping ? ECNF_ATTR_STATE_ENABLED: ECNF_ATTR_STATE_DISABLED;
conf_DetectDigits = pCnfParams->detect_digits;
conf_VoiceParty = pCnfParams->voice_party;
conf_BeepNotify = pCnfParams->beep_notify;
conf_PrivateLog = pCnfParams->private_log;
conf_Tmo = pCnfParams->tmo;
conf_Id = pCnfParams->cnf_id;
conf_PassCode = 0;
str_storestring(&conf_PassCode, pCnfParams->pass_code);
SetCnfBoard( pCnfBoard );
char buffer[256];
snprintf(buffer, sizeof(buffer),"cnf_%d",conf_Id);
SetName(buffer); // temp name until CNFEV_OPEN returns actual name
OpenPrivateLog(conf_PrivateLog);
SetDfltTimer(CONF_TMO);
pCnfParams->Dump(GetLog());
// State Machine
if (SetStateMachine(cnf_event_stru, cnf_action_stru) ){
//
// Open this Conference
Open();
}
return;
} // End of Constructor()
//*****************************************************************************
// Purpose :
// Destructor
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
CnfConference::~CnfConference() {
// Close Conference
Close();
str_deletestoredstring(&conf_PassCode);
return;
} // End of Destructor()
//*****************************************************************************
// Purpose :
// Open conference
// Parameters:
// none
// Returns:
// true = success
//*****************************************************************************
bool CnfConference::Open(){
bool brc = false;
int rc;
CNF_ASSERT(GetCnfBoard(), "Missing m_pCnfBoard object");
rc = cnf_OpenConference(GetCnfBoard()->GetSrlHandle(), 0, 0, this);
LOG( RCHANDLE(rc), GetName(),
"0x%x = cnf_OpenConference(0,0,0,0x%x(this))",
rc,this);
if ( rc == CNF_ERROR ) {
process_cnf_error();
SetCurrentState(S_FINAL);
SetSrlState(SRLSTATE_FAILED_FATAL);
}else {
brc = true;
m_srl_handle = rc;
SetSrlState(SRLSTATE_OPENED);
SetCurrentState(S_OPEN);
GetCnfBoard()->PutEvent(USREV_CNF_OPEN, GetName());
if (conf_VoiceParty){
open_dx();
//set_dx_cst(DM_DIGITS);
}
}
return brc;
} // End of Open()
//*****************************************************************************
// Purpose :
// Close conference
// Parameters:
// none
// Returns:
// true = success
//*****************************************************************************
bool CnfConference::Close(){
bool brc = true;
int rc;
if( IsSrlState(SRLSTATE_OPENED, true) ){
if ( IsSrlState(SRLSTATE_WAITEVENT, true) ){
LOG( LOG_WARNING, GetName(),
"cnf_CloseConference() while waiting for event, state = %d %s",
GetCurrentState(), state_name(GetCurrentState()));
DumpMissingEvents();
}
if (cnf_size() > 0 ){
LOG( LOG_WARNING, GetName(),
"cnf_Close() while parties are still in conferences");
}
CNF_CLOSE_CONF_INFO CloseInfo;
// will post CNFEV_CONF_CLOSED to board
rc = cnf_CloseConference(m_srl_handle, &CloseInfo);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -