mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
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:
committed by
Klaus Basan
parent
01085f24b3
commit
59da68da5e
@@ -8,17 +8,23 @@
|
||||
*/
|
||||
|
||||
#include "dbusobject.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CDBusObject::CDBusObject(CDBusConnection *dbusConnection)
|
||||
: m_dbusConnection(dbusConnection)
|
||||
CDBusObject::CDBusObject()
|
||||
{ }
|
||||
|
||||
CDBusObject::~CDBusObject() = default;
|
||||
|
||||
void CDBusObject::setDBusConnection(const std::shared_ptr<CDBusConnection> &dbusConnection)
|
||||
{
|
||||
m_dbusConnection = dbusConnection;
|
||||
}
|
||||
|
||||
void CDBusObject::registerDBusObjectPath(const std::string &interfaceName, const std::string &objectPath)
|
||||
{
|
||||
assert(m_dbusConnection);
|
||||
m_interfaceName = interfaceName;
|
||||
m_objectPath = objectPath;
|
||||
m_dbusConnection->registerObjectPath(this, interfaceName, objectPath, m_dbusObjectPathVTable);
|
||||
@@ -26,12 +32,14 @@ namespace XSwiftBus
|
||||
|
||||
void CDBusObject::sendDBusSignal(const std::string &name)
|
||||
{
|
||||
if (! m_dbusConnection) { return; }
|
||||
CDBusMessage signal = CDBusMessage::createSignal(m_objectPath, m_interfaceName, name);
|
||||
m_dbusConnection->sendMessage(signal);
|
||||
}
|
||||
|
||||
void CDBusObject::sendDBusMessage(const CDBusMessage &message)
|
||||
{
|
||||
if (! m_dbusConnection) { return; }
|
||||
m_dbusConnection->sendMessage(message);
|
||||
}
|
||||
|
||||
@@ -71,6 +79,7 @@ namespace XSwiftBus
|
||||
(void)connection; // unused
|
||||
|
||||
auto *obj = static_cast<CDBusObject *>(data);
|
||||
|
||||
DBusError err;
|
||||
dbus_error_init(&err);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user