diff --git a/coreapi/vtables.c b/coreapi/vtables.c index 13472609c..2c6f6d712 100644 --- a/coreapi/vtables.c +++ b/coreapi/vtables.c @@ -88,6 +88,7 @@ static void cleanup_dead_vtable_refs(LinphoneCore *lc){ lc->vtable_notify_recursion--; void linphone_core_notify_global_state_changed(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message) { + L_GET_PRIVATE_FROM_C_OBJECT(lc)->notifyGlobalStateChanged(gstate); NOTIFY_IF_EXIST(global_state_changed,lc,gstate,message); cleanup_dead_vtable_refs(lc); } diff --git a/src/chat/notification/imdn.cpp b/src/chat/notification/imdn.cpp index 24d1300e1..6c98c3143 100644 --- a/src/chat/notification/imdn.cpp +++ b/src/chat/notification/imdn.cpp @@ -92,6 +92,16 @@ void Imdn::onImdnMessageDelivered (const std::shared_ptr &message) // ----------------------------------------------------------------------------- +void Imdn::onGlobalStateChanged (LinphoneGlobalState state) { + if (state == LinphoneGlobalShutdown) { + auto ref = chatRoom->getSharedFromThis(); + deliveredMessages.clear(); + displayedMessages.clear(); + nonDeliveredMessages.clear(); + sentImdnMessages.clear(); + } +} + void Imdn::onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) { if (sipNetworkReachable) { // When the SIP network gets up, retry sending every IMDN message that has not diff --git a/src/chat/notification/imdn.h b/src/chat/notification/imdn.h index cf8c46eb8..1fd44caf8 100644 --- a/src/chat/notification/imdn.h +++ b/src/chat/notification/imdn.h @@ -62,6 +62,7 @@ public: void onImdnMessageDelivered (const std::shared_ptr &message); // CoreListener + void onGlobalStateChanged (LinphoneGlobalState state) override; void onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) override; static std::string createXml (const std::string &id, time_t time, Imdn::Type imdnType, LinphoneReason reason); diff --git a/src/core/core-listener.h b/src/core/core-listener.h index d3589bc2e..b26d2de8d 100644 --- a/src/core/core-listener.h +++ b/src/core/core-listener.h @@ -30,6 +30,7 @@ class CoreListener { public: virtual ~CoreListener () = default; + virtual void onGlobalStateChanged (LinphoneGlobalState state) {} virtual void onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) {} virtual void onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) {} }; diff --git a/src/core/core-p.h b/src/core/core-p.h index cfd5e5755..772ea2941 100644 --- a/src/core/core-p.h +++ b/src/core/core-p.h @@ -39,6 +39,7 @@ public: void unregisterListener (CoreListener *listener); void uninit (); + void notifyGlobalStateChanged (LinphoneGlobalState state); void notifyNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable); void notifyRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message); diff --git a/src/core/core.cpp b/src/core/core.cpp index 9e9d94cc6..aeb77fd2d 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -86,13 +86,21 @@ void CorePrivate::uninit () { // ----------------------------------------------------------------------------- +void CorePrivate::notifyGlobalStateChanged (LinphoneGlobalState state) { + auto listenersCopy = listeners; // Allow removable of a listener in its own call + for (const auto &listener : listenersCopy) + listener->onGlobalStateChanged(state); +} + void CorePrivate::notifyNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) { - for (const auto &listener : listeners) + auto listenersCopy = listeners; // Allow removable of a listener in its own call + for (const auto &listener : listenersCopy) listener->onNetworkReachable(sipNetworkReachable, mediaNetworkReachable); } void CorePrivate::notifyRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const string &message) { - for (const auto &listener : listeners) + auto listenersCopy = listeners; // Allow removable of a listener in its own call + for (const auto &listener : listenersCopy) listener->onRegistrationStateChanged(cfg, state, message); }