// 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>
}
]
}
-// 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
+ ]
+ }
}
// --------------------------------------------------------------
// "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"
- ]
- ]
+ ]
+ }
}
{
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,
* 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:
* 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.
// 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);
});
}
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());
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;
}
payload_len,
LWS_WRITE_TEXT);
+ if (count < 0)
+ g_critical("Unable to send the following data to client: %s\n",
+ data);
+
return count >= 0;
}