3 #include "connection.hpp"
4 #include "icd2_light.h"
7 static ConnectionChecker *_instance = NULL;
10 // --------------------------------------------------
11 // ConnectionChecker singleton
12 // --------------------------------------------------
13 ConnectionChecker *ConnectionChecker::instance ()
16 _instance = new ConnectionChecker;
21 ConnectionChecker::ConnectionChecker ()
22 : _bus (QDBusConnection::systemBus ())
26 _itf = new QDBusInterface (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, _bus);
27 _bus.connect (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, ICD_DBUS_API_STATE_SIG,
28 this, SLOT (stateSignal (const QDBusMessage&)));
34 void ConnectionChecker::requestState ()
36 QDBusMessage reply = _itf->call (ICD_DBUS_API_STATE_REQ);
38 // If there is no connection, we get no reply at all
39 if (!reply.arguments ().value (0).toUInt ())
44 void ConnectionChecker::stateSignal (const QDBusMessage& msg)
46 unsigned int status = msg.arguments ().value (7).value<unsigned int>();
48 updateState (status == ICD_STATE_CONNECTED);
52 void ConnectionChecker::updateState (bool new_state)
54 if (new_state != _connected) {
55 _connected = new_state;
56 emit connected (_connected);