Implemented event reporting to settings daemon clients.
authorOssama Othman <ossama.othman@intel.com>
Mon, 7 Oct 2013 23:28:54 +0000 (16:28 -0700)
committerOssama Othman <ossama.othman@intel.com>
Tue, 3 Dec 2013 21:29:38 +0000 (13:29 -0800)
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
include/settingsd/send_callback.hpp
plugins/connman/connman.cpp
plugins/connman/connman_manager.cpp
plugins/connman/signal_callback.cpp [new file with mode: 0644]
plugins/connman/signal_callback.hpp [new file with mode: 0644]
plugins/connman/technology.hpp

index 8da7f5e..9846cb9 100644 (file)
@@ -83,6 +83,16 @@ namespace ivi
         return wsi_ == wsi;
       }
 
+      /**
+       * Check if the WebSocket instance @a wsi corresponds to this
+       * @c send_callback.
+       */
+      bool
+      operator==(libwebsocket const * wsi) const
+      {
+        return wsi_ == wsi;
+      }
+
     private:
 
       /**
index 707111b..1426282 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "connman.hpp"
+#include "signal_callback.hpp"
 
 #include <settingsd/glib_traits.hpp>
 #include <settingsd/unique_ptr.hpp>
index 79a70eb..7002227 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "connman_manager.hpp"
+#include "signal_callback.hpp"
 
 #include <settingsd/response_callback.hpp>
 #include <settingsd/dbus_signal_callback.hpp>
diff --git a/plugins/connman/signal_callback.cpp b/plugins/connman/signal_callback.cpp
new file mode 100644 (file)
index 0000000..899707c
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * @file signal_callback.cpp
+ *
+ * @brief Connman signal callback.
+ *
+ * @author Ossama Othman @<ossama.othman@@intel.com@>
+ *
+ * @copyright @par
+ * Copyright 2013 Intel Corporation All Rights Reserved.
+ * @par
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ * @par
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * @par
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+
+#include "signal_callback.hpp"
+
+#include <settingsd/event_callback.hpp>
+
+#include <json-glib/json-glib.h>
+
+
+void
+on_connman_signal(GDBusConnection * /* connection */,
+                  char const * /* sender_name */,
+                  char const * object_path,
+                  char const * interface_name,
+                  char const * signal_name,
+                  GVariant   * parameters,
+                  gpointer     user_data)
+{
+  using ivi::settings::event_callback;
+  event_callback * const e = static_cast<event_callback *>(user_data);
+
+  // Send event to clients.
+
+  /**
+   * @todo Fix type == nullptr.
+   */
+  e->send_event(
+    object_path,
+    interface_name,
+    signal_name,
+    [parameters](JsonBuilder * builder)
+    {
+      // Serialize the changed services into a JSON tree.
+      // The ServicesChanged signal parameters are:
+      //
+      //   array{object, dict}, array{object})
+      //
+      // where "object" is the D-Bus object path, and "dict" is a
+      // dictionary of object-specific properties.  The first
+      // parameter is list of changed services.  The second is a
+      // list of removed services.
+
+      /**
+       * @todo Can @c json_gvariant_serialize() ever return a
+       *       @c nullptr?
+       */
+      JsonNode * const services = json_gvariant_serialize(parameters);
+
+      json_builder_set_member_name(builder, "value");
+      json_builder_add_value(builder, services);
+
+      // No need to free the JsonNode.  The builder will take
+      // ownership of it.
+    });
+}
+
+
+// Local Variables:
+// mode:c++
+// c-basic-offset:2
+// indent-tabs-mode: nil
+// End:
diff --git a/plugins/connman/signal_callback.hpp b/plugins/connman/signal_callback.hpp
new file mode 100644 (file)
index 0000000..3c781a3
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * @file signal_callback.hpp
+ *
+ * @brief Connman signal callback.
+ *
+ * @author Ossama Othman @<ossama.othman@@intel.com@>
+ *
+ * @copyright @par
+ * Copyright 2013 Intel Corporation All Rights Reserved.
+ * @par
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ * @par
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * @par
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef IVI_SETTINGS_CONNMAN_SIGNAL_CALLBACK_HPP
+#define IVI_SETTINGS_CONNMAN_SIGNAL_CALLBACK_HPP
+
+#include <gio/gio.h>
+
+
+extern "C"
+void on_connman_signal(GDBusConnection * connection,
+                       char const * sender_name,
+                       char const * object_path,
+                       char const * interface_name,
+                       char const * signal_name,
+                       GVariant   * parameters,
+                       gpointer     user_data);
+
+#endif  /* IVI_SETTINGS_CONNMAN_SIGNAL_CALLBACK_HPP */
+
+
+// Local Variables:
+// mode:c++
+// c-basic-offset:2
+// indent-tabs-mode: nil
+// End:
index fde6737..8ebb50b 100644 (file)
@@ -67,7 +67,6 @@ namespace ivi
                  connman_manager & manager,
                  event_callback const & e);
 
-
       /**
        * Handle connman technology-specific request.
        *