Added API for enabling tethering
[profile/ivi/settings-daemon.git] / lib / dbus_signal_callback.cpp
1 /**
2  * @file dbus_signal_callback.cpp
3  *
4  * @brief D-Bus signal callback.
5  *
6  * @author Ossama Othman @<ossama.othman@@intel.com@>
7  *
8  * @copyright @par
9  * Copyright 2013 Intel Corporation All Rights Reserved.
10  * @par
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation;
14  * version 2.1 of the License.
15  * @par
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  * @par
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA  02110-1301  USA
25  */
26
27 #include <settingsd/dbus_signal_callback.hpp>
28 #include <settingsd/event_callback.hpp>
29
30 #include <json-glib/json-glib.h>
31
32
33 void
34 ivi::settings::on_dbus_signal(GDBusConnection * /* connection */,
35                               char const * /* sender_name */,
36                               char const * object_path,
37                               char const * interface_name,
38                               char const * signal_name,
39                               GVariant   * parameters,
40                               gpointer     user_data)
41 {
42   event_callback * const e = static_cast<event_callback *>(user_data);
43
44   // Send event to clients.
45   e->send_event(
46     [object_path,
47      interface_name,
48      signal_name,
49      parameters](JsonBuilder * builder)
50     {
51       json_builder_set_member_name(builder, "value");
52
53       // The event value will be JSON object embedded within the main
54       // event JSON object.
55       json_builder_begin_object(builder);
56
57       json_builder_set_member_name(builder, "object_path");
58       json_builder_add_string_value(builder, object_path);
59
60       json_builder_set_member_name(builder, "interface_name");
61       json_builder_add_string_value(builder, interface_name);
62
63       json_builder_set_member_name(builder, "signal_name");
64       json_builder_add_string_value(builder, signal_name);
65
66       /**
67        * @todo Can @c json_gvariant_serialize() ever return a
68        *       @c nullptr?
69        */
70       JsonNode * const services = json_gvariant_serialize(parameters);
71
72       json_builder_set_member_name(builder, "parameters");
73       json_builder_add_value(builder, services);
74
75       // No need to free the JsonNode.  The builder will take
76       // ownership of it.
77
78       json_builder_end_object(builder);
79     });
80 }
81
82
83 // Local Variables:
84 // mode:c++
85 // c-basic-offset:2
86 // indent-tabs-mode: nil
87 // End: