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
26 #ifndef SERVER_HOST_IPC_CONNECTION_HPP
27 #define SERVER_HOST_IPC_CONNECTION_HPP
29 #include "api/messages.hpp"
30 #include "api/method-result-builder.hpp"
31 #include "api/ipc-method-result-builder.hpp"
32 #include "epoll/thread-dispatcher.hpp"
33 #include "ipc/service.hpp"
41 class HostIPCConnection {
43 template<typename ArgIn, typename ArgOut = api::Void>
46 typedef typename std::remove_cv<ArgIn>::type in;
48 typedef std::function<void(const in&, api::MethodResultBuilder::Pointer)> type;
50 static typename ipc::MethodHandler<out, in>::type
51 getCallbackWrapper(const type& callback) {
52 return [callback](const ipc::PeerID,
53 const std::shared_ptr<in>& argIn,
54 ipc::MethodResult::Pointer&& argOut)
56 auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
62 template<typename ArgOut>
63 class Callback<ArgOut, typename std::enable_if<!std::is_const<ArgOut>::value, api::Void>::type> {
67 typedef std::function<void(api::MethodResultBuilder::Pointer)> type;
69 static typename ipc::MethodHandler<out, in>::type
70 getCallbackWrapper(const type& callback) {
71 return [callback](const ipc::PeerID,
72 const std::shared_ptr<in>& /* argIn */,
73 ipc::MethodResult::Pointer&& argOut)
75 auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
84 void setGetZoneDbusesCallback(const Callback<api::Dbuses>::type& callback);
85 void setGetZoneIdsCallback(const Callback<api::ZoneIds>::type& callback);
86 void setGetActiveZoneIdCallback(const Callback<api::ZoneId>::type& callback);
87 void setGetZoneInfoCallback(const Callback<const api::ZoneId, api::ZoneInfoOut>::type& callback);
88 void setSetNetdevAttrsCallback(const Callback<const api::SetNetDevAttrsIn>::type& callback);
89 void setGetNetdevAttrsCallback(const Callback<const api::GetNetDevAttrsIn, api::GetNetDevAttrs>::type& callback);
90 void setGetNetdevListCallback(const Callback<const api::ZoneId, api::NetDevList>::type& callback);
91 void setCreateNetdevVethCallback(const Callback<const api::CreateNetDevVethIn>::type& callback);
92 void setCreateNetdevMacvlanCallback(const Callback<const api::CreateNetDevMacvlanIn>::type& callback);
93 void setCreateNetdevPhysCallback(const Callback<const api::CreateNetDevPhysIn>::type& callback);
94 void setDestroyNetdevCallback(const Callback<const api::DestroyNetDevIn>::type& callback);
95 void setDeleteNetdevIpAddressCallback(const Callback<const api::DeleteNetdevIpAddressIn>::type& callback);
96 void setDeclareFileCallback(const Callback<const api::DeclareFileIn, api::Declaration>::type& callback);
97 void setDeclareMountCallback(const Callback<const api::DeclareMountIn, api::Declaration>::type& callback);
98 void setDeclareLinkCallback(const Callback<const api::DeclareLinkIn, api::Declaration>::type& callback);
99 void setGetDeclarationsCallback(const Callback<const api::ZoneId, api::Declarations>::type& callback);
100 void setRemoveDeclarationCallback(const Callback<const api::RemoveDeclarationIn>::type& callback);
101 void setSetActiveZoneCallback(const Callback<const api::ZoneId>::type& callback);
102 void setCreateZoneCallback(const Callback<const api::CreateZoneIn>::type& callback);
103 void setDestroyZoneCallback(const Callback<const api::ZoneId>::type& callback);
104 void setShutdownZoneCallback(const Callback<const api::ZoneId>::type& callback);
105 void setStartZoneCallback(const Callback<const api::ZoneId>::type& callback);
106 void setLockZoneCallback(const Callback<const api::ZoneId>::type& callback);
107 void setUnlockZoneCallback(const Callback<const api::ZoneId>::type& callback);
108 void setGrantDeviceCallback(const Callback<const api::GrantDeviceIn>::type& callback);
109 void setRevokeDeviceCallback(const Callback<const api::RevokeDeviceIn>::type& callback);
110 void signalZoneDbusState(const api::DbusState& dbusState);
113 epoll::ThreadDispatcher mDispatcher;
114 std::unique_ptr<ipc::Service> mService;
119 #endif // SERVER_HOST_IPC_CONNECTION_HPP