DBusConnectionStatusEvent: AVAILABLE on subscribe if isConnected
[profile/ivi/common-api-dbus-runtime.git] / src / CommonAPI / DBus / DBusConnection.cpp
index c468dbc..dc9f798 100644 (file)
 namespace CommonAPI {
 namespace DBus {
 
+DBusConnectionStatusEvent::DBusConnectionStatusEvent(DBusConnection* dbusConnection):
+                dbusConnection_(dbusConnection) {
+}
+
+void DBusConnectionStatusEvent::onListenerAdded(const CancellableListener& listener) {
+    if (dbusConnection_->isConnected())
+        listener(AvailabilityStatus::AVAILABLE);
+}
+
 
 DBusObjectPathVTable DBusConnection::libdbusObjectPathVTable_ = {
                 NULL, // no need to handle unregister callbacks
@@ -28,6 +37,7 @@ void DBusConnection::dispatch() {
 DBusConnection::DBusConnection(BusType busType) :
                 busType_(busType),
                 libdbusConnection_(NULL),
+                dbusConnectionStatusEvent_(this),
                 isLibdbusSignalFilterAdded_(false),
                 stopDispatching_(false) {
     dbus_threads_init_default();
@@ -36,6 +46,7 @@ DBusConnection::DBusConnection(BusType busType) :
 DBusConnection::DBusConnection(::DBusConnection* libDbusConnection) :
                 busType_(WRAPPED),
                 libdbusConnection_(libDbusConnection),
+                dbusConnectionStatusEvent_(this),
                 isLibdbusSignalFilterAdded_(false),
                 stopDispatching_(false)  {
     dbus_threads_init_default();