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