Fix TIVI-{1191,1192,2108} by implementing a connman 'Agent'.
[profile/ivi/settings-daemon.git] / lib / event_callback.cpp
1 /**
2  * @file event_callback.cpp
3  *
4  * @brief Settings plugin event_callback implementation.
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/event_callback.hpp>
28 #include <settingsd/json_glib_traits.hpp>
29 #include <settingsd/unique_ptr.hpp>
30 #include "manager.hpp"
31
32
33 ivi::settings::event_callback::event_callback(manager & mgr)
34   : manager_(mgr)
35 {
36 }
37
38 bool
39 ivi::settings::event_callback::send_event(
40   std::function<void(JsonBuilder *)> event_builder) const
41 {
42   unique_ptr<JsonBuilder> const builder = begin_event();
43
44   // Append settings type-specific JSON formatted events.
45   event_builder(builder.get());
46
47   end_event(builder);
48
49   return manager_.send_event(builder);
50 }
51
52 ivi::settings::unique_ptr<JsonBuilder>
53 ivi::settings::event_callback::begin_event() const
54 {
55   // Construct JSON event string.
56   unique_ptr<JsonBuilder> safe_builder(json_builder_new());
57   JsonBuilder * const builder = safe_builder.get();
58
59   json_builder_begin_object(builder);
60
61   json_builder_set_member_name(builder, "type");
62   json_builder_add_string_value(builder, "event");
63
64   return safe_builder;
65 }
66
67 void
68 ivi::settings::event_callback::end_event(
69   ivi::settings::unique_ptr<JsonBuilder> const & builder) const
70 {
71   json_builder_end_object(builder.get());
72 }
73
74
75
76 // Local Variables:
77 // mode:c++
78 // c-basic-offset:2
79 // indent-tabs-mode: nil
80 // End: