Refactored connman signal callback to generic D-Bus signal callback.
[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       /**
52        * @todo Can @c json_gvariant_serialize() ever return a
53        *       @c nullptr?
54        */
55       JsonNode * const services = json_gvariant_serialize(parameters);
56
57       json_builder_set_member_name(builder, "value");
58       json_builder_add_value(builder, services);
59
60       // No need to free the JsonNode.  The builder will take
61       // ownership of it.
62     });
63 }
64
65
66 // Local Variables:
67 // mode:c++
68 // c-basic-offset:2
69 // indent-tabs-mode: nil
70 // End: