📄 sipdialogmanagement.cxx
字号:
void SipDialogManagement::setUpStateMachine(){ State<SipSMCommand,string> *s_start= new State<SipSMCommand,string>(this,"start"); addState(s_start); setUpStateMachine_shutdown(s_start); setUpStateMachine_dialogops(s_start); setCurrentState(s_start);}//separate for the sake of clarityvoid SipDialogManagement::setUpStateMachine_shutdown(State<SipSMCommand,string> *s_start){ State<SipSMCommand,string> *s_start_sh= new State<SipSMCommand,string>(this,"start_shutdown"); addState(s_start_sh); State<SipSMCommand,string> *s_terminateCalls_sh= new State<SipSMCommand,string>(this,"terminateCalls_shutdown"); addState(s_terminateCalls_sh); State<SipSMCommand,string> *s_deRegAll_sh= new State<SipSMCommand,string>(this,"deRegisterAll_shutdown"); addState(s_deRegAll_sh); State<SipSMCommand,string> *s_terminated= new State<SipSMCommand,string>(this,"terminated"); addState(s_terminated); new StateTransition<SipSMCommand,string>( this, "transition_start_startSh_startShutdown", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a0_start_startShutdown_startShutdown, s_start, s_start_sh); new StateTransition<SipSMCommand,string>( this, "transition_startSh_terminateCallsSh_startShutdown", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a10_startSh_terminateCallsSh_terminateAll, s_start_sh, s_terminateCalls_sh); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsSh_callTerminatedEarly", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a11_terminateCallsSh_callTerminatedEarly, s_terminateCalls_sh, s_terminateCalls_sh); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsSh_timeIsUp", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a12_terminateCallsSh_timeIsUp, s_terminateCalls_sh, s_terminateCalls_sh); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsSh_allTerminated", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a13_terminateCallsSh_allTerminated, s_terminateCalls_sh, s_terminateCalls_sh); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsSh_s_deRegAllSh_allTerminated", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a20_terminateCallsSh_deRegAllSh_allTerminated, s_terminateCalls_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_deRegAllSh_callTerminatedEarly", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a21_deRegAllSh_callTerminatedEarly, s_deRegAll_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_deRegAllSh_registerOk", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a22_deRegAllSh_registerOk, s_deRegAll_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_deRegAllSh_timeIsUp", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a23_deRegAllSh_timeIsUp, s_deRegAll_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_deRegAllSh_deRegAlldone", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a24_deRegAllSh_deRegAlldone, s_deRegAll_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_deRegAllSh_allTerminated", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a25_deRegAllSh_allTerminated, s_deRegAll_sh, s_deRegAll_sh); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllSh_terminated_shutdownDone", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::a30_deRegAllSh_terminated_timeIsUp, s_deRegAll_sh, s_terminated); }void SipDialogManagement::setUpStateMachine_dialogops(State<SipSMCommand,string> *s_start){ //TERMINATE ALL CALLS SETUP State<SipSMCommand,string> *s_terminateCalls_ops= new State<SipSMCommand,string>(this,"terminateCalls_ops"); addState(s_terminateCalls_ops); new StateTransition<SipSMCommand,string>( this, "transition_start_terminateCallsOps_terminateAll", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::b0_start_terminateCallsOps_terminateAll, s_start, s_terminateCalls_ops); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsOps_terminateEarly", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::b11_terminateCallsOps_terminateEarly, s_terminateCalls_ops, s_terminateCalls_ops); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsOps_timeIsUp", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::b12_terminateCallsOps_timeIsUp, s_terminateCalls_ops, s_terminateCalls_ops); new StateTransition<SipSMCommand,string>( this, "transition_terminateCallsOps_start_terminateAllDone", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::b30_terminateCallsOps_start_terminateAllDone, s_terminateCalls_ops, s_start); //UNREGISTER ALL IDENTITIES SETUP State<SipSMCommand,string> *s_deRegAll_ops= new State<SipSMCommand,string>(this,"deRegAll_ops"); addState(s_deRegAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_start_deRegAllOps_terminateAll", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::c0_start_deRegAllOps_deRegAll, s_start, s_deRegAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_registerOk", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::c11_deRegAllOps_registerOk, s_deRegAll_ops, s_deRegAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_timeIsUp", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::c12_deRegAllOps_timeIsUp, s_deRegAll_ops, s_deRegAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_start_terminateAllDone", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::c30_deRegAllOps_start_deRegAllDone, s_deRegAll_ops, s_start); //REGISTER ALL IDENTITIES SETUP State<SipSMCommand,string> *s_regAll_ops= new State<SipSMCommand,string>(this,"regAll_ops"); addState(s_regAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_start_deRegAllOps_terminateAll", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::d0_start_regAllOps_regAll, s_start, s_regAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_registerOk", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::d11_regAllOps_registerOk, s_regAll_ops, s_regAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_timeIsUp", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::d12_regAllOps_timeIsUp, s_regAll_ops, s_regAll_ops); new StateTransition<SipSMCommand,string>( this, "transition_deRegAllOps_start_terminateAllDone", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogManagement::d30_regAllOps_start_regAllDone, s_regAll_ops, s_start); }SipDialogManagement::SipDialogManagement(MRef<SipStack*> stack): SipDialog(stack, NULL){ dialogState.callId = "shutdown_dialog"; setUpStateMachine(); //cerr << "SipDialogManagement hello!"<<endl; pendingHangUps = 0; pendingDeRegs = 0;} SipDialogManagement::~SipDialogManagement(){ }bool SipDialogManagement::terminateAllCalls() { list<MRef<SipDialog *> > dlgs; dlgs = sipStack->getDispatcher()->getDialogs(); merr << end; merr << "Terminating all ongoing calls:" << end; for( list<MRef<SipDialog *> >::iterator it = dlgs.begin(); it != dlgs.end(); it ++ ) { //First, skip the register dialogs ... we'll deal with them later if( (*it)->getMemObjectType() == "SipDialogRegister" ) { //mdbg << "SipDialogManagement::terminateAllCalls : dialog skipped" << end; continue; } SipSMCommand cmd( CommandString( (*it)->dialogState.callId, SipCommandString::hang_up), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); pendingHangUps++; merr << " - Hanging up " << (*it)->dialogState.remoteUri << end; } if( pendingHangUps <= 0 ) { merr << " CALLS: No ongoing calls!" << end; //if we have not sent any hang_ups ... notify all calls terminated SipSMCommand cmd( CommandString( "", SipCommandString::terminate_all_calls_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } return true;}bool SipDialogManagement::receivedCallTerminateEarly() { pendingHangUps --; if( pendingHangUps <= 0 ) { merr << " CALLS: all calls have been terminated!" << end; SipSMCommand cmd( CommandString( "", SipCommandString::terminate_all_calls_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } return true;}bool SipDialogManagement::deRegisterAll() { list<MRef<SipDialog *> > dlgs; dlgs = sipStack->getDispatcher()->getDialogs(); merr << end; merr << "De-Registering all identities from their registrar:" << end; for( list<MRef<SipDialog *> >::iterator it = dlgs.begin(); it != dlgs.end(); it ++ ) { //First, skip the register dialogs ... we'll deal with them later if( (*it)->getMemObjectType() != "SipDialogRegister" ) { //mdbg << "SipDialogManagement::deRegisterAll : non-reg dialog skipped" << end; continue; } if(! (*it)->getDialogConfig()->inherited->sipIdentity->isRegistered() ) { //mdbg << "SipDialogManagement::deRegisterAll : skipping already de-registered identity" << end; continue; } CommandString cmdstr( (*it)->dialogState.callId, SipCommandString::proxy_register); cmdstr["proxy_domain"] = (*it)->getDialogConfig()->inherited->sipIdentity->sipDomain; cmdstr.setParam3("0"); //expires = 0 ==> de-register SipSMCommand cmd( cmdstr, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); pendingDeRegs++; merr << " De-registration request sent (username = " << (*it)->getDialogConfig()->inherited->sipIdentity->getSipUri() << ")" << end; } if( pendingDeRegs == 0 ) { //if we have not sent any de-regs ... notify all un-registered merr << " DE-REGISTER: all identities were already not registered!" << end; SipSMCommand cmd( CommandString( "", SipCommandString::unregister_all_identities_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } return true;}bool SipDialogManagement::registerAll() { list<MRef<SipDialog *> > dlgs; dlgs = sipStack->getDispatcher()->getDialogs(); merr << end; merr << "Registering all identities to their registrar:" << end; for( list<MRef<SipDialog *> >::iterator it = dlgs.begin(); it != dlgs.end(); it ++ ) { //First, skip the register dialogs ... we'll deal with them later if( (*it)->getMemObjectType() != "SipDialogRegister" ) { //mdbg << "SipDialogManagement::registerAll : non-reg dialog skipped" << end; continue; } if( (*it)->getDialogConfig()->inherited->sipIdentity->isRegistered() ) { //mdbg << "SipDialogManagement::registerAll : skipping already registered identity" << end; continue; } CommandString cmdstr( (*it)->dialogState.callId, SipCommandString::proxy_register); cmdstr["proxy_domain"] = (*it)->getDialogConfig()->inherited->sipIdentity->sipDomain; //expires = defaultExpires, read from the config file cmdstr.setParam3((*it)->getDialogConfig()->inherited->sipIdentity->getSipProxy()->getDefaultExpires()); SipSMCommand cmd( cmdstr, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); pendingDeRegs++; merr << " Registration request sent (username = " << (*it)->getDialogConfig()->inherited->sipIdentity->getSipUri() << ")" << end; } if( pendingDeRegs == 0 ) { //if we have not sent any de-regs ... notify all un-registered merr << " REGISTER: all identities were already registered!" << end; SipSMCommand cmd( CommandString( "", SipCommandString::unregister_all_identities_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } return true;}bool SipDialogManagement::receivedRegisterOk(bool deregistering){ //FIXME: Should do some kind of checking whether the register_ok is correct // It may be a problem if minisip shutsdown at the same moment it was re-registering ... pendingDeRegs--; if( pendingDeRegs <= 0 ) { if( deregistering ) { merr << " DE-REGISTER: all identities have been de-registered correctly!" << end; SipSMCommand cmd( CommandString( "", SipCommandString::unregister_all_identities_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } else { merr << " REGISTER: all identities have been registered correctly!" << end; SipSMCommand cmd( CommandString( "", SipCommandString::register_all_identities_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); } } return true;}bool SipDialogManagement::shutdownDone( bool force ) { if( !force ) { if( pendingHangUps > 0 || pendingDeRegs > 0 ) { //Still can wait a bit more ... //mdbg << "CESC: shutdown: still not finished ... wait ... "<< end; return false; } //else ... shutdown ... nothing else to do ... merr << end << "SipStack Shutdown process is completed."<< end; } else { merr << "Shutdown process timed out (there was some problem): "<< end; if( pendingHangUps > 0 ) { merr << " CALLS: Not all calls could be correctly hung up."<< end; } if( pendingDeRegs > 0 ) { merr << " DE-REGISTER: Not all identities were correctly de-registered."<< end; } } SipSMCommand cmd( CommandString( "", SipCommandString::sip_stack_shutdown_done), SipSMCommand::dispatcher, SipSMCommand::dispatcher); sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -