Using libConfig structures for input in server
[platform/core/security/vasum.git] / server / host-connection.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
22  * @brief   Declaration of a class for communication with server
23  */
24
25
26 #ifndef SERVER_HOST_CONNECTION_HPP
27 #define SERVER_HOST_CONNECTION_HPP
28
29 #include "dbus/connection.hpp"
30 #include "api/method-result-builder.hpp"
31 #include "api/messages.hpp"
32
33 #include <mutex>
34 #include <condition_variable>
35 #include <tuple>
36 #include <vector>
37
38
39 namespace vasum {
40
41
42 class HostConnection {
43
44 public:
45     HostConnection();
46     ~HostConnection();
47
48     // ------------- API --------------
49
50     typedef std::function<void(const std::string& target,
51                                const std::string& targetBusName,
52                                const std::string& targetObjectPath,
53                                const std::string& targetInterface,
54                                const std::string& targetMethod,
55                                GVariant* parameters,
56                                dbus::MethodResultBuilder::Pointer result
57                               )> ProxyCallCallback;
58     typedef std::function<void(api::MethodResultBuilder::Pointer result
59                               )> GetZoneDbusesCallback;
60     typedef std::function<void(api::MethodResultBuilder::Pointer result
61                               )> GetZoneIdsCallback;
62     typedef std::function<void(api::MethodResultBuilder::Pointer result
63                               )> GetActiveZoneIdCallback;
64     typedef std::function<void(const api::ZoneId& dataIn,
65                                api::MethodResultBuilder::Pointer result
66                               )> GetZoneInfoCallback;
67     typedef std::function<void(const api::SetNetDevAttrsIn& dataIn,
68                                api::MethodResultBuilder::Pointer result
69                               )> SetNetdevAttrsCallback;
70     typedef std::function<void(const api::GetNetDevAttrsIn& dataIn,
71                                api::MethodResultBuilder::Pointer result
72                               )> GetNetdevAttrsCallback;
73     typedef std::function<void(const api::ZoneId& dataIn,
74                                api::MethodResultBuilder::Pointer result
75                               )> GetNetdevListCallback;
76     typedef std::function<void(const api::CreateNetDevVethIn& dataIn,
77                                api::MethodResultBuilder::Pointer result
78                               )> CreateNetdevVethCallback;
79     typedef std::function<void(const api::CreateNetDevMacvlanIn& dataIn,
80                                api::MethodResultBuilder::Pointer result
81                               )> CreateNetdevMacvlanCallback;
82     typedef std::function<void(const api::CreateNetDevPhysIn& dataIn,
83                                api::MethodResultBuilder::Pointer result
84                               )> CreateNetdevPhysCallback;
85     typedef std::function<void(const api::DestroyNetDevIn& dataIn,
86                                api::MethodResultBuilder::Pointer result
87                               )> DestroyNetdevCallback;
88     typedef std::function<void(const api::DeclareFileIn& dataIn,
89                                api::MethodResultBuilder::Pointer result
90                               )> DeclareFileCallback;
91     typedef std::function<void(const api::DeclareMountIn& dataIn,
92                                api::MethodResultBuilder::Pointer result
93                               )> DeclareMountCallback;
94     typedef std::function<void(const api::DeclareLinkIn& dataIn,
95                                api::MethodResultBuilder::Pointer result
96                               )> DeclareLinkCallback;
97     typedef std::function<void(const api::ZoneId& dataIn,
98                                api::MethodResultBuilder::Pointer result
99                               )> GetDeclarationsCallback;
100     typedef std::function<void(const api::RemoveDeclarationIn& dataIn,
101                                api::MethodResultBuilder::Pointer result
102                               )> RemoveDeclarationCallback;
103     typedef std::function<void(const api::ZoneId& dataIn,
104                                api::MethodResultBuilder::Pointer result
105                               )> SetActiveZoneCallback;
106     typedef std::function<void(const api::CreateZoneIn& dataIn,
107                                api::MethodResultBuilder::Pointer result
108                               )> CreateZoneCallback;
109     typedef std::function<void(const api::ZoneId& dataIn,
110                                api::MethodResultBuilder::Pointer result
111                               )> DestroyZoneCallback;
112     typedef std::function<void(const api::ZoneId& dataIn,
113                                api::MethodResultBuilder::Pointer result
114                               )> ShutdownZoneCallback;
115     typedef std::function<void(const api::ZoneId& dataIn,
116                                api::MethodResultBuilder::Pointer result
117                               )> StartZoneCallback;
118     typedef std::function<void(const api::ZoneId& dataIn,
119                                api::MethodResultBuilder::Pointer result
120                               )> LockZoneCallback;
121     typedef std::function<void(const api::ZoneId& dataIn,
122                                api::MethodResultBuilder::Pointer result
123                               )> UnlockZoneCallback;
124     typedef std::function<void(const api::GrantDeviceIn& dataIn,
125                                api::MethodResultBuilder::Pointer result
126                               )> GrantDeviceCallback;
127     typedef std::function<void(const api::RevokeDeviceIn& dataIn,
128                                api::MethodResultBuilder::Pointer result
129                               )> RevokeDeviceCallback;
130
131     /**
132      * Register proxy call callback
133      */
134     void setProxyCallCallback(const ProxyCallCallback& callback);
135
136     /**
137      * Register get zone dbuses callback
138      */
139     void setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback);
140
141     /**
142      * Send signal describing dbus address state change
143      */
144     void signalZoneDbusState(const std::string& zoneId, const std::string& dbusAddress);
145
146     /**
147      * Register a callback called to get a list of zone ids
148      */
149     void setGetZoneIdsCallback(const GetZoneIdsCallback& callback);
150
151     /**
152      * Register a callback called to get the active zone id
153      */
154     void setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback);
155
156     /**
157      * Register a callback called to get the zone informations
158      */
159     void setGetZoneInfoCallback(const GetZoneInfoCallback& callback);
160
161     /**
162      * Register a callback called to set network device attributes
163      */
164     void setSetNetdevAttrsCallback(const SetNetdevAttrsCallback& callback);
165
166     /**
167      * Register a callback called to get network device attributes
168      */
169     void setGetNetdevAttrsCallback(const GetNetdevAttrsCallback& callback);
170
171     /**
172      * Register a callback called to get network device list
173      */
174     void setGetNetdevListCallback(const GetNetdevListCallback& callback);
175
176     /**
177      * Register a callback called to create veth
178      */
179     void setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback);
180
181     /**
182      * Register a callback called to create macvlan
183      */
184     void setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback);
185
186     /**
187      * Register a callback called to create/move phys
188      */
189     void setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback);
190
191     /**
192      * Register a callback called to destroy netdev
193      */
194     void setDestroyNetdevCallback(const DestroyNetdevCallback& callback);
195
196     /**
197      * Register a callback called to declare file
198      */
199     void setDeclareFileCallback(const DeclareFileCallback& callback);
200
201     /**
202      * Register a callback called to declare mount point
203      */
204     void setDeclareMountCallback(const DeclareMountCallback& callback);
205
206     /**
207      * Register a callback called to declare link
208      */
209     void setDeclareLinkCallback(const DeclareLinkCallback& callback);
210
211     /**
212      * Register a callback called to list declarations
213      */
214     void setGetDeclarationsCallback(const GetDeclarationsCallback& callback);
215
216     /**
217      * Register a callback called to remove declarartion
218      */
219     void setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback);
220
221     /**
222      * Register a callback called to set the active zone
223      */
224     void setSetActiveZoneCallback(const SetActiveZoneCallback& callback);
225
226     /**
227      * Register a callback called to create new zone
228      */
229     void setCreateZoneCallback(const CreateZoneCallback& callback);
230
231     /**
232      * Register a callback called to destroy zone
233      */
234     void setDestroyZoneCallback(const DestroyZoneCallback& callback);
235
236     /**
237      * Register a callback called to shutdown zone
238      */
239     void setShutdownZoneCallback(const ShutdownZoneCallback& callback);
240
241     /**
242      * Register a callback called to start zone
243      */
244     void setStartZoneCallback(const StartZoneCallback& callback);
245
246     /**
247      * Register a callback called to lock zone
248      */
249     void setLockZoneCallback(const LockZoneCallback& callback);
250
251     /**
252      * Register a callback called to unlock zone
253      */
254     void setUnlockZoneCallback(const UnlockZoneCallback& callback);
255
256     /**
257      * Register a callback called to grant device
258      */
259     void setGrantDeviceCallback(const GrantDeviceCallback& callback);
260
261     /**
262      * Register a callback called to revoke device
263      */
264     void setRevokeDeviceCallback(const RevokeDeviceCallback& callback);
265
266     /**
267      * Make a proxy call
268      */
269     void proxyCallAsync(const std::string& busName,
270                         const std::string& objectPath,
271                         const std::string& interface,
272                         const std::string& method,
273                         GVariant* parameters,
274                         const dbus::DbusConnection::AsyncMethodCallCallback& callback);
275
276 private:
277     dbus::DbusConnection::Pointer mDbusConnection;
278     std::mutex mNameMutex;
279     std::condition_variable mNameCondition;
280     bool mNameAcquired;
281     bool mNameLost;
282     ProxyCallCallback mProxyCallCallback;
283     GetZoneDbusesCallback mGetZoneDbusesCallback;
284     GetZoneIdsCallback mGetZoneIdsCallback;
285     GetActiveZoneIdCallback mGetActiveZoneIdCallback;
286     GetZoneInfoCallback mGetZoneInfoCallback;
287     SetNetdevAttrsCallback mSetNetdevAttrsCallback;
288     GetNetdevAttrsCallback mGetNetdevAttrsCallback;
289     GetNetdevListCallback mGetNetdevListCallback;
290     CreateNetdevVethCallback mCreateNetdevVethCallback;
291     CreateNetdevMacvlanCallback mCreateNetdevMacvlanCallback;
292     CreateNetdevPhysCallback mCreateNetdevPhysCallback;
293     DestroyNetdevCallback mDestroyNetdevCallback;
294     DeclareFileCallback mDeclareFileCallback;
295     DeclareMountCallback mDeclareMountCallback;
296     DeclareLinkCallback mDeclareLinkCallback;
297     GetDeclarationsCallback mGetDeclarationsCallback;
298     RemoveDeclarationCallback mRemoveDeclarationCallback;
299     SetActiveZoneCallback mSetActiveZoneCallback;
300     CreateZoneCallback mCreateZoneCallback;
301     DestroyZoneCallback mDestroyZoneCallback;
302     ShutdownZoneCallback mShutdownZoneCallback;
303     StartZoneCallback mStartZoneCallback;
304     LockZoneCallback mLockZoneCallback;
305     UnlockZoneCallback mUnlockZoneCallback;
306     GrantDeviceCallback mGrantDeviceCallback;
307     RevokeDeviceCallback mRevokeDeviceCallback;
308
309     void onNameAcquired();
310     void onNameLost();
311     bool waitForName(const unsigned int timeoutMs);
312
313     void onMessageCall(const std::string& objectPath,
314                        const std::string& interface,
315                        const std::string& methodName,
316                        GVariant* parameters,
317                        dbus::MethodResultBuilder::Pointer result);
318 };
319
320
321 } // namespace vasum
322
323
324 #endif // SERVER_HOST_CONNECTION_HPP