summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-04-03 23:09:50 -0700
committerThiago Macieira <thiago.macieira@intel.com>2015-09-15 02:09:01 +0000
commit8888eae0d3da23f233ce49cd3457885998444db4 (patch)
tree45cb47cff81bedeb7ea63bd3c1e4bdbe2541a5be /src/dbus
parent75f6f1d8439ce9874bf31905210ff5be3afa213a (diff)
Merge two more QDBusConnectionPrivate members into a union
QDBusConnectionPrivate can only be a client or a server, not both, so the DBusServer and DBusConnection pointers can be shared, like the QDBusConnectionInterface and QDBusServer pointers in the other anonymous union. Change-Id: I9a75ad8521ae4e5cbbe5ffff13d1baa8ab83c42f Reviewed-by: Albert Astals Cid <aacid@kde.org> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusconnection_p.h6
-rw-r--r--src/dbus/qdbusintegrator.cpp27
2 files changed, 18 insertions, 15 deletions
diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h
index e12b77837e..49c7564566 100644
--- a/src/dbus/qdbusconnection_p.h
+++ b/src/dbus/qdbusconnection_p.h
@@ -303,8 +303,10 @@ public:
// the dispatch lock protects everything related to the DBusConnection or DBusServer
// including the timeouts and watches
QMutex dispatchLock;
- DBusConnection *connection;
- DBusServer *server;
+ union {
+ DBusConnection *connection;
+ DBusServer *server;
+ };
WatcherHash watchers;
TimeoutHash timeouts;
PendingTimeoutList timeoutsPendingAdd;
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 6fccccabd3..ec9a88a210 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -949,7 +949,7 @@ extern bool qDBusInitThreads();
QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
: QObject(p), ref(1), capabilities(0), mode(InvalidMode), busService(0),
- dispatchLock(QMutex::Recursive), connection(0), server(0),
+ dispatchLock(QMutex::Recursive), connection(0),
rootNode(QString(QLatin1Char('/'))),
anonymousAuthenticationAllowed(false)
{
@@ -995,22 +995,23 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate()
rootNode.children.clear(); // free resources
qDeleteAll(cachedMetaObjects);
- if (mode == ClientMode) {
+ if (mode == ClientMode || mode == PeerMode) {
// the bus service object holds a reference back to us;
// we need to destroy it before we finish destroying ourselves
Q_ASSERT(ref.load() == 0);
QObject *obj = (QObject *)busService;
- disconnect(obj, Q_NULLPTR, this, Q_NULLPTR);
- delete obj;
+ if (obj) {
+ disconnect(obj, Q_NULLPTR, this, Q_NULLPTR);
+ delete obj;
+ }
+ if (connection)
+ q_dbus_connection_unref(connection);
+ connection = 0;
+ } else if (mode == ServerMode) {
+ if (server)
+ q_dbus_server_unref(server);
+ server = 0;
}
-
- if (server)
- q_dbus_server_unref(server);
- if (connection)
- q_dbus_connection_unref(connection);
-
- connection = 0;
- server = 0;
}
void QDBusConnectionPrivate::closeConnection()
@@ -1020,7 +1021,7 @@ void QDBusConnectionPrivate::closeConnection()
mode = InvalidMode; // prevent reentrancy
baseService.clear();
- if (server) {
+ if (oldMode == ServerMode && server) {
q_dbus_server_disconnect(server);
q_dbus_server_free_data_slot(&server_slot);
}