📄 dialogusagemanager.cxx
字号:
#include "resip/stack/Security.hxx"#include "resip/stack/SecurityAttributes.hxx"#include "resip/stack/ShutdownMessage.hxx"#include "resip/stack/SipFrag.hxx"#include "resip/stack/SipMessage.hxx"#include "resip/stack/SipStack.hxx"#include "resip/stack/Helper.hxx"#include "resip/stack/TransactionUserMessage.hxx"#include "resip/stack/ConnectionTerminated.hxx"#include "resip/dum/AppDialog.hxx"#include "resip/dum/AppDialogSet.hxx"#include "resip/dum/AppDialogSetFactory.hxx"#include "resip/dum/BaseUsage.hxx"#include "resip/dum/ClientAuthManager.hxx"#include "resip/dum/ClientInviteSession.hxx"#include "resip/dum/ClientOutOfDialogReq.hxx"#include "resip/dum/ClientPublication.hxx"#include "resip/dum/ClientRegistration.hxx"#include "resip/dum/ClientSubscription.hxx"#include "resip/dum/DefaultServerReferHandler.hxx"#include "resip/dum/DestroyUsage.hxx"#include "resip/dum/Dialog.hxx"#include "resip/dum/DialogUsageManager.hxx"#include "resip/dum/ClientPagerMessage.hxx"#include "resip/dum/DumException.hxx"#include "resip/dum/DumShutdownHandler.hxx"#include "resip/dum/DumFeatureMessage.hxx"#include "resip/dum/ExternalMessageBase.hxx"#include "resip/dum/ExternalMessageHandler.hxx"#include "resip/dum/InviteSessionCreator.hxx"#include "resip/dum/InviteSessionHandler.hxx"#include "resip/dum/KeepAliveManager.hxx"#include "resip/dum/KeepAliveTimeout.hxx"#include "resip/dum/MasterProfile.hxx"#include "resip/dum/OutOfDialogReqCreator.hxx"#include "resip/dum/PagerMessageCreator.hxx"#include "resip/dum/PublicationCreator.hxx"#include "resip/dum/RedirectManager.hxx"#include "resip/dum/RegistrationCreator.hxx"#include "resip/dum/ServerAuthManager.hxx"#include "resip/dum/ServerInviteSession.hxx"#include "resip/dum/ServerPublication.hxx"#include "resip/dum/ServerSubscription.hxx"#include "resip/dum/SubscriptionCreator.hxx"#include "resip/dum/SubscriptionHandler.hxx"#include "resip/dum/UserAuthInfo.hxx"#include "resip/dum/DumFeature.hxx"#include "resip/dum/EncryptionManager.hxx"#include "resip/dum/IdentityHandler.hxx"#include "resip/dum/DumDecrypted.hxx"#include "resip/dum/CertMessage.hxx"#include "resip/dum/OutgoingEvent.hxx"#include "resip/dum/DumHelper.hxx"#include "resip/dum/MergedRequestRemovalCommand.hxx"#include "rutil/Inserter.hxx"#include "rutil/Logger.hxx"#include "rutil/Random.hxx"#include "rutil/RWMutex.hxx"#include "rutil/WinLeakCheck.hxx"#include "rutil/Timer.hxx"#define RESIPROCATE_SUBSYSTEM Subsystem::DUMusing namespace resip;using namespace std;DialogUsageManager::DialogUsageManager(SipStack& stack, bool createDefaultFeatures) : TransactionUser(TransactionUser::DoNotRegisterForTransactionTermination, TransactionUser::RegisterForConnectionTermination), mRedirectManager(new RedirectManager()), mInviteSessionHandler(0), mClientRegistrationHandler(0), mServerRegistrationHandler(0), mRedirectHandler(0), mDialogSetHandler(0), mRegistrationPersistenceManager(0), mIsDefaultServerReferHandler(true), mClientPagerMessageHandler(0), mServerPagerMessageHandler(0), mAppDialogSetFactory(new AppDialogSetFactory()), mStack(stack), mDumShutdownHandler(0), mShutdownState(Running){ //TODO -- create default features mStack.registerTransactionUser(*this); addServerSubscriptionHandler("refer", new DefaultServerReferHandler()); mIncomingTarget = new IncomingTarget(*this); mOutgoingTarget = new OutgoingTarget(*this); if (createDefaultFeatures) { SharedPtr<IdentityHandler> identity = SharedPtr<IdentityHandler>(new IdentityHandler(*this, *mIncomingTarget));#if defined (USE_SSL) SharedPtr<EncryptionManager> encryptionIncoming = SharedPtr<EncryptionManager>(new EncryptionManager(*this, *mIncomingTarget)); SharedPtr<EncryptionManager> encryptionOutgoing = SharedPtr<EncryptionManager>(new EncryptionManager(*this, *mOutgoingTarget));#endif // default incoming features. addIncomingFeature(identity);#if defined (USE_SSL) addIncomingFeature(encryptionIncoming);#endif // default outgoing features.#if defined (USE_SSL) addOutgoingFeature(encryptionOutgoing);#endif }}DialogUsageManager::~DialogUsageManager(){ mShutdownState = Destroying; //InfoLog ( << "~DialogUsageManager" );#if(0) // !kh! DialogSetMap::iterator dialogSet = mDialogSetMap.begin(); for (; dialogSet != mDialogSetMap.end(); ++dialogSet) { delete dialogSet->second; }#endif if(!mDialogSetMap.empty()) { DebugLog(<< "DialogUsageManager::mDialogSetMap has " << mDialogSetMap.size() << " DialogSets"); DialogSetMap::const_iterator ds = mDialogSetMap.begin(); for(; ds != mDialogSetMap.end(); ++ds) { DebugLog(<< "DialgSetId:" << ds->first); DialogSet::DialogMap::const_iterator d = ds->second->mDialogs.begin(); for(; d != ds->second->mDialogs.end(); ++d) { //const Dialog* p = &(d->second); DebugLog(<<"DialogId:" << d->first << ", " << *d->second); } } } while(!mDialogSetMap.empty()) { DialogSet* ds = mDialogSetMap.begin()->second; delete ds; } if(mIsDefaultServerReferHandler) { delete mServerSubscriptionHandlers["refer"]; } delete mIncomingTarget; delete mOutgoingTarget; //InfoLog ( << "~DialogUsageManager done" );}const Data& DialogUsageManager::name() const{ static Data n("DialogUsageManager"); return n;}voidDialogUsageManager::addTransport( TransportType protocol, int port, IpVersion version, const Data& ipInterface, const Data& sipDomainname, // only used const Data& privateKeyPassPhrase, SecurityTypes::SSLType sslType){ mStack.addTransport(protocol, port, version, StunDisabled, ipInterface, sipDomainname, privateKeyPassPhrase, sslType);}SipStack& DialogUsageManager::getSipStack(){ return mStack;}Security*DialogUsageManager::getSecurity(){ return mStack.getSecurity();}DataDialogUsageManager::getHostAddress(){ return mStack.getHostAddress();}voidDialogUsageManager::onAllHandlesDestroyed(){ if (mDumShutdownHandler) { switch (mShutdownState) { case ShutdownRequested: InfoLog (<< "DialogUsageManager::onAllHandlesDestroyed: removing TU"); //assert(mHandleMap.empty()); mShutdownState = RemovingTransactionUser; mStack.unregisterTransactionUser(*this); break; default: break; } }}voidDialogUsageManager::shutdown(DumShutdownHandler* h){ InfoLog (<< "shutdown: dialogSets=" << mDialogSetMap.size()); mDumShutdownHandler = h; mShutdownState = ShutdownRequested; mStack.requestTransactionUserShutdown(*this); shutdownWhenEmpty();}// void// DialogUsageManager::shutdownIfNoUsages(DumShutdownHandler* h)// {// InfoLog (<< "shutdown when no usages");// // mDumShutdownHandler = h;// mShutdownState = ShutdownRequested;// assert(0);// }voidDialogUsageManager::forceShutdown(DumShutdownHandler* h){ WarningLog (<< "force shutdown "); dumpHandles(); mDumShutdownHandler = h; //HandleManager::shutdown(); // clear out usages mShutdownState = ShutdownRequested; DialogUsageManager::onAllHandlesDestroyed();}void DialogUsageManager::setAppDialogSetFactory(std::auto_ptr<AppDialogSetFactory> factory){ mAppDialogSetFactory = factory;}SharedPtr<MasterProfile>&DialogUsageManager::getMasterProfile(){ assert(mMasterProfile.get()); return mMasterProfile;}SharedPtr<UserProfile>&DialogUsageManager::getMasterUserProfile(){ assert(mMasterUserProfile.get()); return mMasterUserProfile;}void DialogUsageManager::setMasterProfile(const SharedPtr<MasterProfile>& masterProfile){ assert(!mMasterProfile.get()); mMasterProfile = masterProfile; mMasterUserProfile = masterProfile; // required so that we can return a reference to SharedPtr<UserProfile> in getMasterUserProfile}void DialogUsageManager::setKeepAliveManager(std::auto_ptr<KeepAliveManager> manager){ mKeepAliveManager = manager; mKeepAliveManager->setDialogUsageManager(this);}void DialogUsageManager::setRedirectManager(std::auto_ptr<RedirectManager> manager){ mRedirectManager = manager;}void DialogUsageManager::setRedirectHandler(RedirectHandler* handler){ mRedirectHandler = handler;}RedirectHandler* DialogUsageManager::getRedirectHandler(){ return mRedirectHandler;}voidDialogUsageManager::setClientAuthManager(std::auto_ptr<ClientAuthManager> manager){ mClientAuthManager = manager;}voidDialogUsageManager::setServerAuthManager(SharedPtr<ServerAuthManager> manager){ mIncomingFeatureList.insert(mIncomingFeatureList.begin(), manager);}voidDialogUsageManager::setClientRegistrationHandler(ClientRegistrationHandler* handler){ assert(!mClientRegistrationHandler); mClientRegistrationHandler = handler;}voidDialogUsageManager::setServerRegistrationHandler(ServerRegistrationHandler* handler){ assert(!mServerRegistrationHandler); mServerRegistrationHandler = handler;}voidDialogUsageManager::setDialogSetHandler(DialogSetHandler* handler){ mDialogSetHandler = handler;}voidDialogUsageManager::setInviteSessionHandler(InviteSessionHandler* handler){ assert(!mInviteSessionHandler); mInviteSessionHandler = handler;}voidDialogUsageManager::setRegistrationPersistenceManager(RegistrationPersistenceManager* manager){ assert(!mRegistrationPersistenceManager); mRegistrationPersistenceManager = manager;}voidDialogUsageManager::setRemoteCertStore(auto_ptr<RemoteCertStore> store){}voidDialogUsageManager::addTimer(DumTimeout::Type type, unsigned long duration, BaseUsageHandle target, unsigned int cseq, unsigned int rseq){ DumTimeout t(type, duration, target, cseq, rseq); mStack.post(t, duration, this);}voidDialogUsageManager::addTimerMs(DumTimeout::Type type, unsigned long duration, BaseUsageHandle target, unsigned int cseq, unsigned int rseq, const Data &transactionId /*= Data::Empty*/){ DumTimeout t(type, duration, target, cseq, rseq, transactionId); mStack.postMS(t, duration, this);}voidDialogUsageManager::addClientSubscriptionHandler(const Data& eventType, ClientSubscriptionHandler* handler){ assert(handler); assert(mClientSubscriptionHandlers.count(eventType) == 0); mClientSubscriptionHandlers[eventType] = handler;}voidDialogUsageManager::addServerSubscriptionHandler(const Data& eventType, ServerSubscriptionHandler* handler){ assert(handler); //default do-nothing server side refer handler can be replaced if (eventType == "refer" && mServerSubscriptionHandlers.count(eventType)) { delete mServerSubscriptionHandlers[eventType]; mIsDefaultServerReferHandler = false; //mServerSubscriptionHandlers.erase(eventType); } mServerSubscriptionHandlers[eventType] = handler;}voidDialogUsageManager::addClientPublicationHandler(const Data& eventType, ClientPublicationHandler* handler){ assert(handler); assert(mClientPublicationHandlers.count(eventType) == 0); mClientPublicationHandlers[eventType] = handler;}voidDialogUsageManager::addServerPublicationHandler(const Data& eventType, ServerPublicationHandler* handler){ assert(handler); assert(mServerPublicationHandlers.count(eventType) == 0); mServerPublicationHandlers[eventType] = handler;}voidDialogUsageManager::addOutOfDialogHandler(MethodTypes type, OutOfDialogHandler* handler){ assert(handler); assert(mOutOfDialogHandlers.count(type) == 0); mOutOfDialogHandlers[type] = handler;}voidDialogUsageManager::setClientPagerMessageHandler(ClientPagerMessageHandler* handler){ mClientPagerMessageHandler = handler;}voidDialogUsageManager::setServerPagerMessageHandler(ServerPagerMessageHandler* handler){ mServerPagerMessageHandler = handler;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -