Delay setting the DBusConnection for a DBusObject

Previously, the DBusconnection had to be set at construction time and could
not be changed over the DBusObject life time. Now a new connection can be
set anytime and as often as required.
The shared ownership is now also properly implemented by shared pointers.

ref T291
This commit is contained in:
Roland Winklmeier
2018-07-26 21:52:45 +02:00
committed by Klaus Basan
parent 01085f24b3
commit 59da68da5e
10 changed files with 45 additions and 28 deletions

View File

@@ -22,11 +22,19 @@ namespace XSwiftBus
{
public:
//! Constructor
CDBusObject(CDBusConnection *dbusConnection);
CDBusObject();
//! Destructor
virtual ~CDBusObject();
//! Set the assigned DBus connection.
//! \remark Currently one object can only manage one connection at a time
void setDBusConnection(const std::shared_ptr<CDBusConnection> &dbusConnection);
//! Register itself with interfaceName and objectPath
//! \warning Before calling this method, make sure that a valid DBus connection was set.
void registerDBusObjectPath(const std::string &interfaceName, const std::string &objectPath);
//! Process DBus messages. Needs to be implemented by deriving classes
virtual int processDBus() = 0;
@@ -34,9 +42,6 @@ namespace XSwiftBus
//! DBus message handler
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) = 0;
//! Register itself with interfaceName and objectPath
void registerDBusObjectPath(const std::string &interfaceName, const std::string &objectPath);
//! Send DBus signal
void sendDBusSignal(const std::string &name);
@@ -76,7 +81,7 @@ namespace XSwiftBus
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
static DBusHandlerResult dbusObjectPathMessageFunction(DBusConnection *connection, DBusMessage *message, void *data);
CDBusConnection *m_dbusConnection;
std::shared_ptr<CDBusConnection> m_dbusConnection;
std::string m_interfaceName;
std::string m_objectPath;