e96542d6038d793900832ee7e49e43654396574e
[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
33 #include <settingsd/plugin.hpp>
34 #include <settingsd/event_callback.hpp>
35
36 #include <gio/gio.h>
37
38 #include <string>
39
40
41 namespace ivi
42 {
43   namespace settings
44   {
45     /**
46      * @class connman_manager
47      *
48      * @brief D-Bus Connman Manager object bridge.
49      *
50      * This class exposes the Connman Manager D-Bus API through the
51      * settings daemon WebSocket API.
52      */
53     class connman_manager : public plugin
54     {
55     public:
56
57       /// Constructor.
58       connman_manager(GDBusConnection * connection,
59                       event_callback const & e);
60
61       /// Destructor.
62       ~connman_manager();
63
64       /**
65        * @name Settings Plugin API
66        *
67        * Interface defined by the @c ivi::settings::plugin abstract
68        * base class.
69        *
70        * @see settingsd/plugin.hpp
71        */
72       //@{
73       virtual std::string const & id() const;
74       virtual void handle_request(std::string request,
75                                   response_callback response);
76       //@}
77
78       /**
79        * Get the properties for a specific technology.
80        *
81        * @param[in] technology Connman technology for which properties
82        *                       are being retrieved.
83        * @param[inout] error   Glib error object that contains
84        *                       additional error information if
85        *                       non-null if the call completes.
86        *
87        * @return @c GVariant containing a dictionary of properties
88        *         specific to @a technology.
89        */
90       GVariant * get_properties(std::string const & technology,
91                                 GError *& error) const;
92
93       /**
94        * Get connman services and their properties.
95        *
96        * @param[inout] response Callback used to send results to the
97        *                        caller.
98        */
99       void get_services(response_callback & response) const;
100
101       struct signal_data
102       {
103         signal_data(GDBusConnection * connection,
104                     event_callback const & e)
105           : callback(e)
106           , subscriptions(connection, callback)
107         {
108         }
109
110         /// Callback through which events will be sent to clients.
111         event_callback callback;
112
113         /// Signal subscription manager.
114         subscription_manager subscriptions;
115       };
116
117     private:
118
119       /**
120        * Get connman technologies and their properties.
121        *
122        * @param[inout] response Callback used to send results to the
123        *                        caller.
124        */
125       void get_technologies(response_callback & response) const;
126
127       /**
128        * Call the method @a name on the connman Manager object.  This
129        * method is meant to be used for @c GetServices and
130        * @c GetTechnologies requests.
131        *
132        * @param[in]    name     The connman Manager object method
133        *                        name.
134        * @param[inout] response Callback used to inform the caller of
135        *                        the results.
136        */
137       void call_method(char const * name,
138                        response_callback & response) const;
139
140       typedef void (*ivi_signal_callback)(GDBusConnection * connection,
141                                           char const * sender_name,
142                                           char const * object_path,
143                                           char const * interface_name,
144                                           char const * signal_name,
145                                           GVariant   * parameters,
146                                           gpointer     user_data);
147
148       /// Subscribe to Connman Manager signal @a name.
149       guint subscribe_to_signal(GDBusConnection * connection,
150                                 char const * name,
151                                 ivi_signal_callback callback,
152                                 void * user_data);
153
154     private:
155
156       /// The proxy used to access the connman Manager D-Bus API.
157       connman connman_;
158
159       /// Data passed to signal handlers.
160       signal_data data_;
161
162       /// TechnologyAdded signal subscription ID.
163       guint const technology_added_id_;
164
165       /// TechnologyRemoved signal subscription ID.
166       guint const technology_removed_id_;
167
168       /// ServicesChanged signal subscription ID.
169       guint const services_changed_id_;
170
171     };
172
173   }
174 }
175
176
177 #endif  /* IVI_SETTINGS_CONNMAN_MANAGER_HPP */
178
179
180 // Local Variables:
181 // mode:c++
182 // c-basic-offset:2
183 // indent-tabs-mode: nil
184 // End: