Fix TIVI-{1191,1192,2108} by implementing a connman 'Agent'.
[profile/ivi/settings-daemon.git] / plugins / connman / connman_manager.hpp
1 /**
2  * @file connman_manager.hpp
3  *
4  * @brief Connman Manager-based settings plugin 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 #ifndef IVI_SETTINGS_CONNMAN_MANAGER_HPP
28 #define IVI_SETTINGS_CONNMAN_MANAGER_HPP
29
30 #include "connman.hpp"
31 #include "subscription_manager.hpp"
32 #include "agent.hpp"
33
34 #include <settingsd/plugin.hpp>
35 #include <settingsd/event_callback.hpp>
36
37 #include <gio/gio.h>
38
39 #include <string>
40
41
42 namespace ivi
43 {
44   namespace settings
45   {
46     /**
47      * @class connman_manager
48      *
49      * @brief D-Bus Connman Manager object bridge.
50      *
51      * This class exposes the Connman Manager D-Bus API through the
52      * settings daemon WebSocket API.
53      */
54     class connman_manager : public plugin
55     {
56     public:
57
58       /// Constructor.
59       connman_manager(GDBusConnection * connection,
60                       event_callback const & e);
61
62       /// Destructor.
63       ~connman_manager();
64
65       /**
66        * @name Settings Plugin API
67        *
68        * Interface defined by the @c ivi::settings::plugin abstract
69        * base class.
70        *
71        * @see settingsd/plugin.hpp
72        */
73       //@{
74       virtual std::string const & id() const;
75       virtual void handle_request(std::string request,
76                                   response_callback response);
77       //@}
78
79       /**
80        * Register data that may be needed when handling Connman Agent
81        * method calls.
82        */
83       bool register_connect_data(char const * service_path,
84                                  std::map<std::string, std::string> && info,
85                                  response_callback const & response);
86
87       /**
88        * Deregister connection data.
89        */
90       bool deregister_connect_data(char const * service_path);
91
92       /**
93        * Get the properties for a specific technology.
94        *
95        * @param[in] technology Connman technology for which properties
96        *                       are being retrieved.
97        * @param[inout] error   Glib error object that contains
98        *                       additional error information if
99        *                       non-null if the call completes.
100        *
101        * @return @c GVariant containing a dictionary of properties
102        *         specific to @a technology.
103        */
104       GVariant * get_properties(std::string const & technology,
105                                 GError *& error) const;
106
107       /**
108        * Get connman services and their properties.
109        *
110        * @param[inout] response Callback used to send results to the
111        *                        caller.
112        */
113       void get_services(response_callback & response) const;
114
115       struct signal_data
116       {
117         signal_data(GDBusConnection * connection,
118                     event_callback const & e)
119           : callback(e)
120           , subscriptions(connection, callback)
121         {
122         }
123
124         /// Callback through which events will be sent to clients.
125         event_callback callback;
126
127         /// Signal subscription manager.
128         subscription_manager subscriptions;
129       };
130
131     private:
132
133       /**
134        * Get connman technologies and their properties.
135        *
136        * @param[inout] response Callback used to send results to the
137        *                        caller.
138        */
139       void get_technologies(response_callback & response) const;
140
141       /**
142        * Call the method @a name on the connman Manager object.
143        *
144        * @param[in]    name       The connman Manager object method
145        *                          name.
146        * @param[in]    parameters Method parameters.
147        * @param[inout] error      Pointer to error object containing
148        *                          failure related information.  Caller
149        *                          must deallocate if it is not null.
150        *
151        * @return Variant containing result of underlying Connman
152        *         Manager D-Bus call.  The caller must release the
153        *         returned @c GVariant.
154        */
155       GVariant * call_method(char const * name,
156                              GVariant * parameters,
157                              GError *& error) const;
158
159
160       /**
161        * Send response or error to client that initiated the request.
162        */
163       void handle_return_value(char const * name,
164                                GVariant * ret,
165                                GError * error,
166                                response_callback & response) const;
167
168       typedef void (*ivi_signal_callback)(GDBusConnection * connection,
169                                           char const * sender_name,
170                                           char const * object_path,
171                                           char const * interface_name,
172                                           char const * signal_name,
173                                           GVariant   * parameters,
174                                           gpointer     user_data);
175
176       /// Subscribe to Connman Manager signal @a name.
177       guint subscribe_to_signal(GDBusConnection * connection,
178                                 char const * name,
179                                 ivi_signal_callback callback,
180                                 void * user_data);
181
182     private:
183
184       /// The proxy used to access the connman Manager D-Bus API.
185       connman connman_;
186
187       /// Data passed to signal handlers.
188       signal_data data_;
189
190       /// TechnologyAdded signal subscription ID.
191       guint const technology_added_id_;
192
193       /// TechnologyRemoved signal subscription ID.
194       guint const technology_removed_id_;
195
196       /// ServicesChanged signal subscription ID.
197       guint const services_changed_id_;
198
199       /**
200        * The connman Agent implemention that handles secure and
201        * hidden network related requests.
202        */
203       agent agent_;
204
205     };
206
207   }
208 }
209
210
211 #endif  /* IVI_SETTINGS_CONNMAN_MANAGER_HPP */
212
213
214 // Local Variables:
215 // mode:c++
216 // c-basic-offset:2
217 // indent-tabs-mode: nil
218 // End: