Changed the event JSON format to be more generic.
authorOssama Othman <ossama.othman@intel.com>
Wed, 9 Oct 2013 20:32:21 +0000 (13:32 -0700)
committerOssama Othman <ossama.othman@intel.com>
Wed, 9 Oct 2013 20:32:21 +0000 (13:32 -0700)
Change-Id: Ia415f9096060a70109bba5ddd7bc5c7575d45ced
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
doc/settings-protocol.js
include/settingsd/dbus_signal_callback.hpp
include/settingsd/event_callback.hpp
lib/dbus_signal_callback.cpp
lib/event_callback.cpp
lib/send_callback.cpp

index 444f685..4f83ea3 100644 (file)
@@ -33,9 +33,7 @@ var response =
 // General form of an event
 var event =
     {
-       "object_path":"<object path>" or null,
-       "interface_name":"<interface name>" or null,
-       "name":"<event name>",
+       "type": "event"
        "value": <setting specific value>
     }
 
@@ -265,13 +263,19 @@ var response =
        ]
     }
 
-// WiFi "PropertyChanged" event
+// WiFi "PropertyChanged" event format
 var event =
     {
-       "object_path":"/net/connman/technology/wifi",
-       "interface_name":"net.connman.Technology",
-       "name":"PropertyChanged",
-       "value":["Powered",false]
+       "type":"event",
+       "value":{
+           "object_path":"/net/connman/technology/wifi",
+           "interface_name":"net.connman.Technology",
+           "signal_name":"PropertyChanged",
+           "parameters":[
+               "Powered",
+               true
+           ]
+       }
     }
 
 // --------------------------------------------------------------
@@ -340,57 +344,63 @@ var response =
 // "ServicesChanged" event from Connman Manager object
 var event =
     {
-       "object_path":"/",
-       "interface_name":"net.connman.Manager"
-       "name": "ServicesChanged",
-       "value": [
-            [
+       "type": "event",
+       "value": {
+            "interface_name": "net.connman.Manager",
+            "object_path": "/",
+            "signal_name": "ServicesChanged",
+            "parameters": [
                [
-                    "/net/connman/service/ethernet_002564e81cc7_cable",
-                    {}
+                   // Changed services
+                    [
+                       "/net/connman/service/ethernet_002564e81cc7_cable",
+                       {}
+                    ],
+                    [
+                       "/net/connman/service/wifi_50465dae486e_4775657374_managed_none",
+                       {
+                            "AutoConnect": false,
+                            "Domains": [],
+                            "Domains.Configuration": [],
+                            "Ethernet": {
+                               "Address": "00:21:5D:4E:48:7D",
+                               "Interface": "wlan0",
+                               "MTU": 1500,
+                               "Method": "auto"
+                            },
+                            "Favorite": false,
+                            "IPv4": {},
+                            "IPv4.Configuration": {
+                               "Method": "dhcp"
+                            },
+                            "IPv6": {},
+                            "IPv6.Configuration": {
+                               "Method": "auto",
+                               "Privacy": "prefered"
+                            },
+                            "Immutable": false,
+                            "Name": "Guest",
+                            "Nameservers": [],
+                            "Nameservers.Configuration": [],
+                            "Provider": {},
+                            "Proxy": {},
+                            "Proxy.Configuration": {},
+                            "Security": [
+                               "none"
+                            ],
+                            "State": "idle",
+                            "Strength": 62,
+                            "Timeservers": [],
+                            "Timeservers.Configuration": [],
+                            "Type": "wifi"
+                       }
+                    ],
                ],
                [
-                    "/net/connman/service/wifi_50465dae486e_574f537769666932472d4150_managed_wep",
-                    {
-                       "AutoConnect": false,
-                       "Domains": [],
-                       "Domains.Configuration": [],
-                       "Ethernet": {
-                            "Address": "20:36:5D:AF:28:9E",
-                            "Interface": "wlan0",
-                            "MTU": 1500,
-                            "Method": "auto"
-                       },
-                       "Favorite": false,
-                       "IPv4": {},
-                       "IPv4.Configuration": {
-                            "Method": "dhcp"
-                       },
-                       "IPv6": {},
-                       "IPv6.Configuration": {
-                            "Method": "auto",
-                            "Privacy": "prefered"
-                       },
-                       "Immutable": false,
-                       "Name": "WOSwifi2G-AP",
-                       "Nameservers": [],
-                       "Nameservers.Configuration": [],
-                       "Provider": {},
-                       "Proxy": {},
-                       "Proxy.Configuration": {},
-                       "Security": [
-                            "wep"
-                       ],
-                       "State": "idle",
-                       "Strength": 73,
-                       "Timeservers": [],
-                       "Timeservers.Configuration": [],
-                       "Type": "wifi"
-                    }
+                   // Removed services
+                   "/net/connman/service/wifi_50465dae486e_54534e4f6666696365574c414e_managed_ieee8021x",
+                   "/net/connman/service/wifi_50465dae486e_4c6162776c616e_managed_ieee8021x"
                ]
-            ],
-            [
-               "/net/connman/service/wifi_50465dae486e_hidden_managed_wep"
-           ]
-       ]
+            ]
+       }
     }
index 7abea8b..6c26b7b 100644 (file)
@@ -36,6 +36,22 @@ namespace ivi
 {
   namespace settings
   {
+    /**
+     * This GDBus signal handler may be used by plugins to marsh
+     * signals into a settings daemon JSON formatted event.  The
+     * resulting JSON string will be of the form:
+     *
+     *   {
+     *     "type:   "event",
+     *     "value": {
+     *       "object_path":    "...",
+     *       "interface_path": "...",
+     *       "signal_name":    "...",
+     *       "parameters": <GVariant parameters marshaled
+     *                      into their JSON equivalents>
+     *     }
+     *   }
+     */
     extern "C" SETTINGS_API
     void on_dbus_signal(GDBusConnection * connection,
                         char const * sender_name,
index e3e5154..069296a 100644 (file)
@@ -70,16 +70,10 @@ namespace ivi
        * level JSON object.  That will be automatically handled by
        * this class.
        *
-       * @param[in] type          Setting type, e.g. @c "wifi".
-       * @param[in] event_name    Event name, e.g.
-       *                          @c "PropertyChanged".
        * @param[in] event_builder Callback function that appends JSON
        *                          formatted event data.
        */
       bool send_event(
-        char const * object_path,
-        char const * interface_name,
-        char const * event_name,
         std::function<void(JsonBuilder *)> event_builder);
 
     private:
@@ -91,9 +85,7 @@ namespace ivi
        * The appropriate "header" information will be prepended to the
        * event.
        */
-      smart_ptr<JsonBuilder> begin_event(char const * object_path,
-                                         char const * interface_name,
-                                         char const * event_name);
+      smart_ptr<JsonBuilder> begin_event();
 
       /**
        * End the JSON formatted event to the Settings app request.
index 690e8fd..632e37a 100644 (file)
@@ -43,22 +43,39 @@ ivi::settings::on_dbus_signal(GDBusConnection * /* connection */,
 
   // Send event to clients.
   e->send_event(
-    object_path,
-    interface_name,
-    signal_name,
-    [parameters](JsonBuilder * builder)
+    [object_path,
+     interface_name,
+     signal_name,
+     parameters](JsonBuilder * builder)
     {
+      json_builder_set_member_name(builder, "value");
+
+      // The event value will be JSON object embedded within the main
+      // event JSON object.
+      json_builder_begin_object(builder);
+
+      json_builder_set_member_name(builder, "object_path");
+      json_builder_add_string_value(builder, object_path);
+
+      json_builder_set_member_name(builder, "interface_name");
+      json_builder_add_string_value(builder, interface_name);
+
+      json_builder_set_member_name(builder, "signal_name");
+      json_builder_add_string_value(builder, signal_name);
+
       /**
        * @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_set_member_name(builder, "parameters");
       json_builder_add_value(builder, services);
 
       // No need to free the JsonNode.  The builder will take
       // ownership of it.
+
+      json_builder_end_object(builder);
     });
 }
 
index d0ffd50..5ec7189 100644 (file)
@@ -37,31 +37,20 @@ ivi::settings::event_callback::event_callback(manager & mgr)
 
 bool
 ivi::settings::event_callback::send_event(
-  char const * object_path,
-  char const * interface_name,
-  char const * event_name,
   std::function<void(JsonBuilder *)> event_builder)
 {
-  smart_ptr<JsonBuilder> const builder =
-    begin_event(object_path, interface_name, event_name);
+  smart_ptr<JsonBuilder> const builder = begin_event();
 
   // Append settings type-specific JSON formatted events.
   event_builder(builder.get());
 
   end_event(builder);
 
-  bool const success = manager_.send_event(builder);
-
-  if (!success)
-    g_critical("Unable to send %s event", event_name);
-
-  return success;
+  return manager_.send_event(builder);
 }
 
 ivi::settings::smart_ptr<JsonBuilder>
-ivi::settings::event_callback::begin_event(char const * object_path,
-                                           char const * interface_name,
-                                           char const * event_name)
+ivi::settings::event_callback::begin_event()
 {
   // Construct JSON event string.
   smart_ptr<JsonBuilder> safe_builder(json_builder_new());
@@ -69,20 +58,8 @@ ivi::settings::event_callback::begin_event(char const * object_path,
 
   json_builder_begin_object(builder);
 
-  json_builder_set_member_name(builder, "object_path");
-  if (object_path == nullptr)
-    json_builder_add_null_value(builder);
-  else
-    json_builder_add_string_value(builder, object_path);
-
-  json_builder_set_member_name(builder, "interface_name");
-  if (interface_name == nullptr)
-    json_builder_add_null_value(builder);
-  else
-    json_builder_add_string_value(builder, interface_name);
-
-  json_builder_set_member_name(builder, "name");
-  json_builder_add_string_value(builder, event_name);
+  json_builder_set_member_name(builder, "type");
+  json_builder_add_string_value(builder, "event");
 
   return safe_builder;
 }
index eec4025..50453ad 100644 (file)
@@ -101,6 +101,10 @@ ivi::settings::send_callback::send_payload(
                                        payload_len,
                                        LWS_WRITE_TEXT);
 
+  if (count < 0)
+    g_critical("Unable to send the following data to client: %s\n",
+               data);
+
   return count >= 0;
 }