2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Mateusz Malicki <m.malicki2@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 Mateusz Malicki (m.malicki2@samsung.com)
22 * @brief HostIPCConnection class
29 #include "host-ipc-connection.hpp"
30 #include "host-ipc-definitions.hpp"
31 #include "exception.hpp"
32 #include "logger/logger.hpp"
33 #include "zones-manager.hpp"
38 HostIPCConnection::HostIPCConnection(ipc::epoll::EventPoll& eventPoll, ZonesManager* zonesManagerPtr)
39 : mZonesManagerPtr(zonesManagerPtr)
41 LOGT("Connecting to host IPC socket");
43 ipc::PeerCallback removedCallback = [this](const ipc::PeerID peerID,
44 const ipc::FileDescriptor) {
45 std::string id = api::IPC_CONNECTION_PREFIX + peerID;
46 mZonesManagerPtr->disconnectedCallback(id);
48 mService.reset(new ipc::Service(eventPoll, HOST_IPC_SOCKET,
49 nullptr, removedCallback));
51 using namespace std::placeholders;
52 setLockQueueCallback(std::bind(&ZonesManager::handleLockQueueCall,
53 mZonesManagerPtr, _1));
55 setUnlockQueueCallback(std::bind(&ZonesManager::handleUnlockQueueCall,
56 mZonesManagerPtr, _1));
58 setGetZoneIdsCallback(std::bind(&ZonesManager::handleGetZoneIdsCall,
59 mZonesManagerPtr, _1));
61 setGetActiveZoneIdCallback(std::bind(&ZonesManager::handleGetActiveZoneIdCall,
62 mZonesManagerPtr, _1));
64 setGetZoneInfoCallback(std::bind(&ZonesManager::handleGetZoneInfoCall,
65 mZonesManagerPtr, _1, _2));
67 setSetNetdevAttrsCallback(std::bind(&ZonesManager::handleSetNetdevAttrsCall,
68 mZonesManagerPtr, _1, _2));
70 setGetNetdevAttrsCallback(std::bind(&ZonesManager::handleGetNetdevAttrsCall,
71 mZonesManagerPtr, _1, _2));
73 setGetNetdevListCallback(std::bind(&ZonesManager::handleGetNetdevListCall,
74 mZonesManagerPtr, _1, _2));
76 setCreateNetdevVethCallback(std::bind(&ZonesManager::handleCreateNetdevVethCall,
77 mZonesManagerPtr, _1, _2));
79 setCreateNetdevMacvlanCallback(std::bind(&ZonesManager::handleCreateNetdevMacvlanCall,
80 mZonesManagerPtr, _1, _2));
82 setCreateNetdevPhysCallback(std::bind(&ZonesManager::handleCreateNetdevPhysCall,
83 mZonesManagerPtr, _1, _2));
85 setDestroyNetdevCallback(std::bind(&ZonesManager::handleDestroyNetdevCall,
86 mZonesManagerPtr, _1, _2));
88 setDeleteNetdevIpAddressCallback(std::bind(&ZonesManager::handleDeleteNetdevIpAddressCall,
89 mZonesManagerPtr, _1, _2));
91 setDeclareFileCallback(std::bind(&ZonesManager::handleDeclareFileCall,
92 mZonesManagerPtr, _1, _2));
94 setDeclareMountCallback(std::bind(&ZonesManager::handleDeclareMountCall,
95 mZonesManagerPtr, _1, _2));
97 setDeclareLinkCallback(std::bind(&ZonesManager::handleDeclareLinkCall,
98 mZonesManagerPtr, _1, _2));
100 setGetDeclarationsCallback(std::bind(&ZonesManager::handleGetDeclarationsCall,
101 mZonesManagerPtr, _1, _2));
103 setRemoveDeclarationCallback(std::bind(&ZonesManager::handleRemoveDeclarationCall,
104 mZonesManagerPtr, _1, _2));
106 setSetActiveZoneCallback(std::bind(&ZonesManager::handleSetActiveZoneCall,
107 mZonesManagerPtr, _1, _2));
109 setCreateZoneCallback(std::bind(&ZonesManager::handleCreateZoneCall,
110 mZonesManagerPtr, _1, _2));
112 setDestroyZoneCallback(std::bind(&ZonesManager::handleDestroyZoneCall,
113 mZonesManagerPtr, _1, _2));
115 setShutdownZoneCallback(std::bind(&ZonesManager::handleShutdownZoneCall,
116 mZonesManagerPtr, _1, _2));
118 setStartZoneCallback(std::bind(&ZonesManager::handleStartZoneCall,
119 mZonesManagerPtr, _1, _2));
121 setLockZoneCallback(std::bind(&ZonesManager::handleLockZoneCall,
122 mZonesManagerPtr, _1, _2));
124 setUnlockZoneCallback(std::bind(&ZonesManager::handleUnlockZoneCall,
125 mZonesManagerPtr, _1, _2));
127 setGrantDeviceCallback(std::bind(&ZonesManager::handleGrantDeviceCall,
128 mZonesManagerPtr, _1, _2));
130 setRevokeDeviceCallback(std::bind(&ZonesManager::handleRevokeDeviceCall,
131 mZonesManagerPtr, _1, _2));
133 setSwitchToDefaultCallback(std::bind(&ZonesManager::handleSwitchToDefaultCall,
134 mZonesManagerPtr, "", _1));
136 setCreateFileCallback(std::bind(&ZonesManager::handleCreateFileCall,
137 mZonesManagerPtr, _1, _2));
139 setCleanUpZonesRootCallback(std::bind(&ZonesManager::handleCleanUpZonesRootCall,
140 mZonesManagerPtr, _1));
143 HostIPCConnection::~HostIPCConnection()
147 void HostIPCConnection::start()
149 LOGT("Starting IPC");
154 void HostIPCConnection::stop(bool wait)
156 LOGT("Stopping IPC");
157 mService->stop(wait);
160 bool HostIPCConnection::isRunning()
162 return mService->isStarted();
165 void HostIPCConnection::setLockQueueCallback(const Method<api::Void>::type& callback)
167 typedef IPCMethodWrapper<api::Void> Callback;
168 mService->setMethodHandler<Callback::out, Callback::in>(
169 api::ipc::METHOD_LOCK_QUEUE,
170 Callback::getWrapper(callback));
173 void HostIPCConnection::setUnlockQueueCallback(const Method<api::Void>::type& callback)
175 typedef IPCMethodWrapper<api::Void> Callback;
176 mService->setMethodHandler<Callback::out, Callback::in>(
177 api::ipc::METHOD_UNLOCK_QUEUE,
178 Callback::getWrapper(callback));
181 void HostIPCConnection::setGetZoneIdsCallback(const Method<api::ZoneIds>::type& callback)
183 typedef IPCMethodWrapper<api::ZoneIds> Callback;
184 mService->setMethodHandler<Callback::out, Callback::in>(
185 api::ipc::METHOD_GET_ZONE_ID_LIST,
186 Callback::getWrapper(callback));
189 void HostIPCConnection::setGetActiveZoneIdCallback(const Method<api::ZoneId>::type& callback)
191 typedef IPCMethodWrapper<api::ZoneId> Callback;
192 mService->setMethodHandler<Callback::out, Callback::in>(
193 api::ipc::METHOD_GET_ACTIVE_ZONE_ID,
194 Callback::getWrapper(callback));
197 void HostIPCConnection::setGetZoneInfoCallback(const Method<const api::ZoneId, api::ZoneInfoOut>::type& callback)
199 typedef IPCMethodWrapper<const api::ZoneId, api::ZoneInfoOut> Callback;
200 mService->setMethodHandler<Callback::out, Callback::in>(
201 api::ipc::METHOD_GET_ZONE_INFO,
202 Callback::getWrapper(callback));
205 void HostIPCConnection::setSetNetdevAttrsCallback(const Method<const api::SetNetDevAttrsIn>::type& callback)
207 typedef IPCMethodWrapper<const api::SetNetDevAttrsIn> Callback;
208 mService->setMethodHandler<Callback::out, Callback::in>(
209 api::ipc::METHOD_SET_NETDEV_ATTRS,
210 Callback::getWrapper(callback));
213 void HostIPCConnection::setGetNetdevAttrsCallback(const Method<const api::GetNetDevAttrsIn, api::GetNetDevAttrs>::type& callback)
215 typedef IPCMethodWrapper<const api::GetNetDevAttrsIn, api::GetNetDevAttrs> Callback;
216 mService->setMethodHandler<Callback::out, Callback::in>(
217 api::ipc::METHOD_GET_NETDEV_ATTRS,
218 Callback::getWrapper(callback));
221 void HostIPCConnection::setGetNetdevListCallback(const Method<const api::ZoneId, api::NetDevList>::type& callback)
223 typedef IPCMethodWrapper<const api::ZoneId, api::NetDevList> Callback;
224 mService->setMethodHandler<Callback::out, Callback::in>(
225 api::ipc::METHOD_GET_NETDEV_LIST,
226 Callback::getWrapper(callback));
229 void HostIPCConnection::setCreateNetdevVethCallback(const Method<const api::CreateNetDevVethIn>::type& callback)
231 typedef IPCMethodWrapper<const api::CreateNetDevVethIn> Callback;
232 mService->setMethodHandler<Callback::out, Callback::in>(
233 api::ipc::METHOD_CREATE_NETDEV_VETH,
234 Callback::getWrapper(callback));
237 void HostIPCConnection::setCreateNetdevMacvlanCallback(const Method<const api::CreateNetDevMacvlanIn>::type& callback)
239 typedef IPCMethodWrapper<const api::CreateNetDevMacvlanIn> Callback;
240 mService->setMethodHandler<Callback::out, Callback::in>(
241 api::ipc::METHOD_CREATE_NETDEV_MACVLAN,
242 Callback::getWrapper(callback));
245 void HostIPCConnection::setCreateNetdevPhysCallback(const Method<const api::CreateNetDevPhysIn>::type& callback)
247 typedef IPCMethodWrapper<const api::CreateNetDevPhysIn> Callback;
248 mService->setMethodHandler<Callback::out, Callback::in>(
249 api::ipc::METHOD_CREATE_NETDEV_PHYS,
250 Callback::getWrapper(callback));
253 void HostIPCConnection::setDestroyNetdevCallback(const Method<const api::DestroyNetDevIn>::type& callback)
255 typedef IPCMethodWrapper<const api::DestroyNetDevIn> Callback;
256 mService->setMethodHandler<Callback::out, Callback::in>(
257 api::ipc::METHOD_DESTROY_NETDEV,
258 Callback::getWrapper(callback));
261 void HostIPCConnection::setDeleteNetdevIpAddressCallback(const Method<const api::DeleteNetdevIpAddressIn>::type& callback)
263 typedef IPCMethodWrapper<const api::DeleteNetdevIpAddressIn> Callback;
264 mService->setMethodHandler<Callback::out, Callback::in>(
265 api::ipc::METHOD_DELETE_NETDEV_IP_ADDRESS,
266 Callback::getWrapper(callback));
269 void HostIPCConnection::setDeclareFileCallback(const Method<const api::DeclareFileIn, api::Declaration>::type& callback)
271 typedef IPCMethodWrapper<const api::DeclareFileIn, api::Declaration> Callback;
272 mService->setMethodHandler<Callback::out, Callback::in>(
273 api::ipc::METHOD_DECLARE_FILE,
274 Callback::getWrapper(callback));
277 void HostIPCConnection::setDeclareMountCallback(const Method<const api::DeclareMountIn, api::Declaration>::type& callback)
279 typedef IPCMethodWrapper<const api::DeclareMountIn, api::Declaration> Callback;
280 mService->setMethodHandler<Callback::out, Callback::in>(
281 api::ipc::METHOD_DECLARE_MOUNT,
282 Callback::getWrapper(callback));
285 void HostIPCConnection::setDeclareLinkCallback(const Method<const api::DeclareLinkIn, api::Declaration>::type& callback)
287 typedef IPCMethodWrapper<const api::DeclareLinkIn, api::Declaration> Callback;
288 mService->setMethodHandler<Callback::out, Callback::in>(
289 api::ipc::METHOD_DECLARE_LINK,
290 Callback::getWrapper(callback));
293 void HostIPCConnection::setGetDeclarationsCallback(const Method<const api::ZoneId, api::Declarations>::type& callback)
295 typedef IPCMethodWrapper<const api::ZoneId, api::Declarations> Callback;
296 mService->setMethodHandler<Callback::out, Callback::in>(
297 api::ipc::METHOD_GET_DECLARATIONS,
298 Callback::getWrapper(callback));
301 void HostIPCConnection::setRemoveDeclarationCallback(const Method<const api::RemoveDeclarationIn>::type& callback)
303 typedef IPCMethodWrapper<const api::RemoveDeclarationIn> Callback;
304 mService->setMethodHandler<Callback::out, Callback::in>(
305 api::ipc::METHOD_REMOVE_DECLARATION,
306 Callback::getWrapper(callback));
309 void HostIPCConnection::setSetActiveZoneCallback(const Method<const api::ZoneId>::type& callback)
311 typedef IPCMethodWrapper<const api::ZoneId> Callback;
312 mService->setMethodHandler<Callback::out, Callback::in>(
313 api::ipc::METHOD_SET_ACTIVE_ZONE,
314 Callback::getWrapper(callback));
317 void HostIPCConnection::setCreateZoneCallback(const Method<const api::CreateZoneIn>::type& callback)
319 typedef IPCMethodWrapper<const api::CreateZoneIn> Callback;
320 mService->setMethodHandler<Callback::out, Callback::in>(
321 api::ipc::METHOD_CREATE_ZONE,
322 Callback::getWrapper(callback));
325 void HostIPCConnection::setDestroyZoneCallback(const Method<const api::ZoneId>::type& callback)
327 typedef IPCMethodWrapper<const api::ZoneId> Callback;
328 mService->setMethodHandler<Callback::out, Callback::in>(
329 api::ipc::METHOD_DESTROY_ZONE,
330 Callback::getWrapper(callback));
333 void HostIPCConnection::setShutdownZoneCallback(const Method<const api::ZoneId>::type& callback)
335 typedef IPCMethodWrapper<const api::ZoneId> Callback;
336 mService->setMethodHandler<Callback::out, Callback::in>(
337 api::ipc::METHOD_SHUTDOWN_ZONE,
338 Callback::getWrapper(callback));
341 void HostIPCConnection::setStartZoneCallback(const Method<const api::ZoneId>::type& callback)
343 typedef IPCMethodWrapper<const api::ZoneId> Callback;
344 mService->setMethodHandler<Callback::out, Callback::in>(
345 api::ipc::METHOD_START_ZONE,
346 Callback::getWrapper(callback));
349 void HostIPCConnection::setLockZoneCallback(const Method<const api::ZoneId>::type& callback)
351 typedef IPCMethodWrapper<const api::ZoneId> Callback;
352 mService->setMethodHandler<Callback::out, Callback::in>(
353 api::ipc::METHOD_LOCK_ZONE,
354 Callback::getWrapper(callback));
357 void HostIPCConnection::setUnlockZoneCallback(const Method<const api::ZoneId>::type& callback)
359 typedef IPCMethodWrapper<const api::ZoneId> Callback;
360 mService->setMethodHandler<Callback::out, Callback::in>(
361 api::ipc::METHOD_UNLOCK_ZONE,
362 Callback::getWrapper(callback));
365 void HostIPCConnection::setGrantDeviceCallback(const Method<const api::GrantDeviceIn>::type& callback)
367 typedef IPCMethodWrapper<const api::GrantDeviceIn> Callback;
368 mService->setMethodHandler<Callback::out, Callback::in>(
369 api::ipc::METHOD_GRANT_DEVICE,
370 Callback::getWrapper(callback));
373 void HostIPCConnection::setRevokeDeviceCallback(const Method<const api::RevokeDeviceIn>::type& callback)
375 typedef IPCMethodWrapper<const api::RevokeDeviceIn> Callback;
376 mService->setMethodHandler<Callback::out, Callback::in>(
377 api::ipc::METHOD_REVOKE_DEVICE,
378 Callback::getWrapper(callback));
381 void HostIPCConnection::setSwitchToDefaultCallback(const Method<api::Void>::type& callback)
383 typedef IPCMethodWrapper<api::Void> Callback;
384 mService->setMethodHandler<Callback::out, Callback::in>(
385 api::ipc::METHOD_SWITCH_TO_DEFAULT,
386 Callback::getWrapper(callback));
389 void HostIPCConnection::setCreateFileCallback(const Method<const api::CreateFileIn,
390 api::CreateFileOut>::type& callback)
392 typedef IPCMethodWrapper<const api::CreateFileIn, api::CreateFileOut> Method;
393 mService->setMethodHandler<Method::out, Method::in>(
394 api::ipc::METHOD_CREATE_FILE,
395 Method::getWrapper(callback));
398 void HostIPCConnection::setCleanUpZonesRootCallback(const Method<api::Void>::type& callback)
400 typedef IPCMethodWrapper<api::Void> Callback;
401 mService->setMethodHandler<Callback::out, Callback::in>(
402 api::ipc::METHOD_CLEAN_UP_ZONES_ROOT,
403 Callback::getWrapper(callback));