2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
21 * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
22 * @brief Declaration of a class for communication with server
26 #ifndef SERVER_HOST_CONNECTION_HPP
27 #define SERVER_HOST_CONNECTION_HPP
29 #include "dbus/connection.hpp"
30 #include "api/method-result-builder.hpp"
31 #include "api/messages.hpp"
34 #include <condition_variable>
42 class HostConnection {
48 // ------------- API --------------
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,
56 dbus::MethodResultBuilder::Pointer result
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
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;
132 * Register proxy call callback
134 void setProxyCallCallback(const ProxyCallCallback& callback);
137 * Register get zone dbuses callback
139 void setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback);
142 * Send signal describing dbus address state change
144 void signalZoneDbusState(const std::string& zoneId, const std::string& dbusAddress);
147 * Register a callback called to get a list of zone ids
149 void setGetZoneIdsCallback(const GetZoneIdsCallback& callback);
152 * Register a callback called to get the active zone id
154 void setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback);
157 * Register a callback called to get the zone informations
159 void setGetZoneInfoCallback(const GetZoneInfoCallback& callback);
162 * Register a callback called to set network device attributes
164 void setSetNetdevAttrsCallback(const SetNetdevAttrsCallback& callback);
167 * Register a callback called to get network device attributes
169 void setGetNetdevAttrsCallback(const GetNetdevAttrsCallback& callback);
172 * Register a callback called to get network device list
174 void setGetNetdevListCallback(const GetNetdevListCallback& callback);
177 * Register a callback called to create veth
179 void setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback);
182 * Register a callback called to create macvlan
184 void setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback);
187 * Register a callback called to create/move phys
189 void setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback);
192 * Register a callback called to destroy netdev
194 void setDestroyNetdevCallback(const DestroyNetdevCallback& callback);
197 * Register a callback called to declare file
199 void setDeclareFileCallback(const DeclareFileCallback& callback);
202 * Register a callback called to declare mount point
204 void setDeclareMountCallback(const DeclareMountCallback& callback);
207 * Register a callback called to declare link
209 void setDeclareLinkCallback(const DeclareLinkCallback& callback);
212 * Register a callback called to list declarations
214 void setGetDeclarationsCallback(const GetDeclarationsCallback& callback);
217 * Register a callback called to remove declarartion
219 void setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback);
222 * Register a callback called to set the active zone
224 void setSetActiveZoneCallback(const SetActiveZoneCallback& callback);
227 * Register a callback called to create new zone
229 void setCreateZoneCallback(const CreateZoneCallback& callback);
232 * Register a callback called to destroy zone
234 void setDestroyZoneCallback(const DestroyZoneCallback& callback);
237 * Register a callback called to shutdown zone
239 void setShutdownZoneCallback(const ShutdownZoneCallback& callback);
242 * Register a callback called to start zone
244 void setStartZoneCallback(const StartZoneCallback& callback);
247 * Register a callback called to lock zone
249 void setLockZoneCallback(const LockZoneCallback& callback);
252 * Register a callback called to unlock zone
254 void setUnlockZoneCallback(const UnlockZoneCallback& callback);
257 * Register a callback called to grant device
259 void setGrantDeviceCallback(const GrantDeviceCallback& callback);
262 * Register a callback called to revoke device
264 void setRevokeDeviceCallback(const RevokeDeviceCallback& callback);
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);
277 dbus::DbusConnection::Pointer mDbusConnection;
278 std::mutex mNameMutex;
279 std::condition_variable mNameCondition;
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;
309 void onNameAcquired();
311 bool waitForName(const unsigned int timeoutMs);
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);
324 #endif // SERVER_HOST_CONNECTION_HPP