TIVI-1924: Initial commit of IVI settings daemon.
[profile/ivi/settings-daemon.git] / plugins / connman / connman_manager.hpp
1 /**
2  * @file connman_manager.hpp
3  *
4  * @brief Connman 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
32 #include <settingsd/glib_traits.hpp>
33 #include <settingsd/smart_ptr.hpp>
34
35 #include <gio/gio.h>
36 #include <json-glib/json-glib.h>
37
38 #include <future>
39 #include <list>
40 #include <memory>
41
42
43 namespace ivi
44 {
45   namespace settings
46   {
47     /**
48      * @class connman_manager
49      *
50      * @brief Common connman-based settings functionality.
51      *
52      * This class implements functionality common to all connman-based
53      * settings, such as bluetooth, wifi, date/time, etc.
54      */
55     class connman_manager
56     {
57     public:
58
59       /// Constructor.
60       connman_manager();
61
62       /// Destructor.
63       ~connman_manager();
64
65       /**
66        * Get the properties for a specific technology.
67        *
68        * @param[in] technology Connman technology for which properties
69        *                       are being retrieved.
70        * @param[inout] error   Glib error object that contains
71        *                       additional error information if
72        *                       non-null if the call completes.
73        *
74        * @return @c GVariant containing a dictionary of properties
75        *         specific to @a technology.
76        */
77       GVariant * get_properties(std::string const & technology,
78                                 GError *& error) const;
79
80       /**
81        * Get connman services and their properties.
82        *
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 services and
88        *         corresponding properties.
89        */
90       GVariant * get_services(GError *& error) const;
91
92       /// The type held by the @c future containing the async result.
93       typedef smart_ptr<JsonNode>             future_value_type;
94
95       /// The @c future type returned by the @c promise.
96       typedef std::future<future_value_type>  future_type;
97
98       /// The @c promise that provides the async result.
99       typedef std::promise<future_value_type> promise_type;
100
101       /**
102        * Smart pointer to the @c promise that provides the async
103        * result.
104        */
105       typedef std::shared_ptr<promise_type> shared_promise_type;
106
107       /// List type for promises to be updated with async result.
108       typedef std::list<shared_promise_type> promise_list_type;
109
110       /**
111        * Get a promise that will contain changed connman services when
112        * they become available.  The user must obtain the value from
113        * the corresponding future object and release the @c JsonNode*
114        * value contained within that future with @c json_node_free().
115        */
116       shared_promise_type get_services_changed_promise();
117
118       /**
119        * @struct user_data
120        *
121        * @brief Struct passed to @c ServicesChanged signal handler.
122        */
123       struct user_data
124       {
125         /// Constructor.
126         user_data(std::mutex & m, promise_list_type & p)
127           : mutex(m)
128           , promises(p)
129         {
130         }
131
132         /**
133          * References to mutex used to synchronize access to the list
134          * of promises.
135          */
136         std::mutex & mutex;
137
138         /// List of promises to be updated with the changed services.
139         promise_list_type & promises;
140       };
141
142     private:
143
144       /// The proxy used to access the connman Manager D-Bus API.
145       connman connman_;
146
147       /// Mutex used to synchronize access to the promises list.
148       std::mutex mutex_;
149
150       /**
151        * List of promises that will be updated with the
152        * ServicesChanged signal results.
153        */
154       promise_list_type promises_;
155
156       /// User data passed to @c ServicesChanged signal handler.
157       user_data data_;
158
159       /// ServicesChanged signal subscription ID.
160       guint const subscription_id_;
161
162     };
163
164   }
165 }
166
167
168 #endif  /* IVI_SETTINGS_CONNMAN_MANAGER_HPP */
169
170
171 // Local Variables:
172 // mode:c++
173 // c-basic-offset:2
174 // indent-tabs-mode: nil
175 // End: