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 IPCSignalWrapper and IPCMethodWrapper classes used to hide IPC specifics
26 #ifndef SERVER_IPC_CALLBACK_WRAPPER_HPP
27 #define SERVER_IPC_CALLBACK_WRAPPER_HPP
29 #include "api/messages.hpp"
30 #include "api/method-result-builder.hpp"
31 #include "api/ipc-method-result-builder.hpp"
37 template<typename ArgIn>
38 class IPCSignalWrapper {
40 typedef typename std::remove_cv<ArgIn>::type in;
41 typedef std::function<void(const in&)> type;
43 static typename ipc::SignalHandler<in>::type
44 getWrapper(const type& callback) {
45 return [callback](const ipc::PeerID, const std::shared_ptr<in>& argIn)
53 class IPCSignalWrapper<const api::Void> {
56 typedef std::function<void()> type;
58 static typename ipc::SignalHandler<in>::type
59 getWrapper(const type& callback) {
60 return [callback](const ipc::PeerID, const std::shared_ptr<in>& /* argIn */)
67 template<typename ArgIn = const api::Void, typename ArgOut = api::Void>
68 class IPCMethodWrapper {
70 typedef typename std::remove_cv<ArgIn>::type in;
72 typedef std::function<void(const in&, api::MethodResultBuilder::Pointer)> type;
74 static typename ipc::MethodHandler<out, in>::type
75 getWrapper(const type& callback) {
76 return [callback](const ipc::PeerID,
77 const std::shared_ptr<in>& argIn,
78 ipc::MethodResult::Pointer&& argOut)
80 auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
86 template<typename ArgOut>
87 class IPCMethodWrapper<ArgOut, typename std::enable_if<!std::is_const<ArgOut>::value, api::Void>::type> {
91 typedef std::function<void(api::MethodResultBuilder::Pointer)> type;
93 static typename ipc::MethodHandler<out, in>::type
94 getWrapper(const type& callback) {
95 return [callback](const ipc::PeerID,
96 const std::shared_ptr<in>& /* argIn */,
97 ipc::MethodResult::Pointer&& argOut)
99 auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
107 #endif // SERVER_IPC_CALLBACK_WRAPPER_HPP