Unregister DBusObject callback when the object is destroyed

Without that cleanup, DBusConnection might try to call a dangling
std::function in case the DBusObject was removed before. That is for
example happening during shutdown.
This commit is contained in:
Roland Winklmeier
2018-10-19 14:50:55 +02:00
committed by Klaus Basan
parent dfd33e40c1
commit f8cc92341a
3 changed files with 21 additions and 9 deletions

View File

@@ -19,7 +19,6 @@
#include <dbus/dbus.h>
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>
namespace XSwiftBus
@@ -64,7 +63,10 @@ namespace XSwiftBus
bool isConnected() const;
//! Register a disconnected callback
void registerDisconnectedCallback(DisconnectedCallback func);
void registerDisconnectedCallback(CDBusObject *obj, DisconnectedCallback func);
//! Register a disconnected callback
void unregisterDisconnectedCallback(CDBusObject *obj);
//! Register DBus object with interfaceName and objectPath.
//! \param object
@@ -98,7 +100,7 @@ namespace XSwiftBus
CDBusDispatcher *m_dispatcher = nullptr;
std::unique_ptr<DBusConnection, DBusConnectionDeleter> m_connection;
CDBusError m_lastError;
std::vector<DisconnectedCallback> m_disconnectedCallbacks;
std::unordered_map<CDBusObject *, DisconnectedCallback> m_disconnectedCallbacks;
};
}