Fix TIVI-{1191,1192,2108} by implementing a connman 'Agent'.
[profile/ivi/settings-daemon.git] / include / settingsd / event_callback.hpp
1 /**
2  * @file event_callback.hpp
3  *
4  * @brief Settings event callback header.
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
28 #ifndef IVI_SETTINGS_EVENT_CALLBACK_HPP
29 #define IVI_SETTINGS_EVENT_CALLBACK_HPP
30
31 #include <settingsd/settings_api.hpp>
32 #include <settingsd/send_callback.hpp>
33
34 #include <functional>
35
36
37 namespace ivi
38 {
39   namespace settings
40   {
41     class manager;
42
43     /**
44      * @class event_callback event_callback.hpp <settingsd/event_callback.hpp>
45      *
46      * @brief Callback that handles sending event to Settings app.
47      *
48      * A @c event_callback sends a JSON formatted event string
49      * to the Settings app.  It is up to the specific settings plugin
50      * to decide what goes in to the event.
51     */
52     class SETTINGS_API event_callback
53     {
54     public:
55
56       /// Constructor
57       event_callback(manager & m);
58
59       /**
60        * Send event to Settings app.
61        *
62        * The settings daemon requires that plugins use the json-glib
63        * library to build JSON event strings.  Plugins will pass a
64        * callback function @a event_builder that uses to the
65        * json-glib high level "builder" API to append the event to the
66        * JSON event string.  Plugins should take care to only use the
67        * builder functions that add members and their corresponding
68        * values.  They should not attempt to start or end the top
69        * level JSON object.  That will be automatically handled by
70        * this class.
71        *
72        * @param[in] event_builder Callback function that appends JSON
73        *                          formatted event data.
74        */
75       bool send_event(
76         std::function<void(JsonBuilder *)> event_builder) const;
77
78     private:
79
80       /**
81        * Begin the JSON formatted event to the Settings app
82        * request.
83        *
84        * The appropriate "header" information will be prepended to the
85        * event.
86        */
87       unique_ptr<JsonBuilder> begin_event() const;
88
89       /**
90        * End the JSON formatted event to the Settings app request.
91        */
92       void end_event(unique_ptr<JsonBuilder> const & builder) const;
93
94     private:
95
96       /**
97        * Settings manager used to send event to clients over
98        * corresponding WebSockets.
99        */
100       manager & manager_;
101
102     };
103
104   }
105 }
106
107 #endif  /* IVI_SETTINGS_EVENT_CALLBACK_HPP */
108
109
110 // Local Variables:
111 // mode:c++
112 // c-basic-offset:2
113 // indent-tabs-mode: nil
114 // End: