From 8273149b353a45ab2087b7eae4e2e6cb649f90fe Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Tue, 23 Sep 2008 19:05:18 +0000 Subject: [PATCH] act on SystemEvent::ServerShutdown TODO: wait until contacts are really deregistered (resent with uac) or shutdown git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1088 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/registrar_client/SIPRegistrarClient.cpp | 32 ++++++++++++++++++-- apps/registrar_client/SIPRegistrarClient.h | 3 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/registrar_client/SIPRegistrarClient.cpp b/apps/registrar_client/SIPRegistrarClient.cpp index c3e6fc76..baecdb9c 100644 --- a/apps/registrar_client/SIPRegistrarClient.cpp +++ b/apps/registrar_client/SIPRegistrarClient.cpp @@ -197,7 +197,8 @@ SIPRegistrarClient* SIPRegistrarClient::instance() SIPRegistrarClient::SIPRegistrarClient(const string& name) : AmEventQueue(this), uac_auth_i(NULL), - AmDynInvokeFactory(MOD_NAME) + AmDynInvokeFactory(MOD_NAME), + stop_requested(false) { } @@ -211,7 +212,7 @@ void SIPRegistrarClient::run() { uac_auth_i = uac_auth_f->getInstance(); } - while (true) { + while (!stop_requested.get()) { if (registrations.size()) { unsigned int cnt = 250; while (cnt > 0) { @@ -294,7 +295,33 @@ int SIPRegistrarClient::onLoad() { return 0; } +void SIPRegistrarClient::onServerShutdown() { + // TODO: properly wait until unregistered, with timeout + DBG("shutdown SIP registrar client: deregistering\n"); + for (std::map::iterator it= + registrations.begin(); it != registrations.end(); it++) { + it->second->doUnregister(); + AmEventDispatcher::instance()->delEventQueue(it->first); + } + + stop_requested.set(true); +// +// setStopped(); +// return; +} + void SIPRegistrarClient::process(AmEvent* ev) { + if (ev->event_id == E_SYSTEM) { + AmSystemEvent* sys_ev = dynamic_cast(ev); + if(sys_ev){ + DBG("Session received system Event\n"); + if (sys_ev->sys_event == AmSystemEvent::ServerShutdown) { + onServerShutdown(); + } + return; + } + } + AmSipReplyEvent* sip_rep = dynamic_cast(ev); if (sip_rep) { onSipReplyEvent(sip_rep); @@ -313,6 +340,7 @@ void SIPRegistrarClient::process(AmEvent* ev) { return; } + } void SIPRegistrarClient::onSipReplyEvent(AmSipReplyEvent* ev) { diff --git a/apps/registrar_client/SIPRegistrarClient.h b/apps/registrar_client/SIPRegistrarClient.h index 6833f9e6..d97f158b 100644 --- a/apps/registrar_client/SIPRegistrarClient.h +++ b/apps/registrar_client/SIPRegistrarClient.h @@ -167,8 +167,9 @@ class SIPRegistrarClient : public AmThread, AmDynInvoke* uac_auth_i; - + AmSharedVar stop_requested; void checkTimeouts(); + void onServerShutdown(); public: SIPRegistrarClient(const string& name); // DI factory