Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ipc-callback-wrapper.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Mateusz Malicki <m.malicki2@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 
26 #ifndef SERVER_IPC_CALLBACK_WRAPPER_HPP
27 #define SERVER_IPC_CALLBACK_WRAPPER_HPP
28 
29 #include "api/messages.hpp"
32 
33 #include <functional>
34 
35 namespace vasum {
36 
37 template<typename ArgIn>
39 public:
40  typedef typename std::remove_cv<ArgIn>::type in;
41  typedef std::function<void(const in&)> type;
42 
44  getWrapper(const type& callback) {
45  return [callback](const cargo::ipc::PeerID, const std::shared_ptr<in>& argIn)
46  {
47  callback(*argIn);
48  return true;
49  };
50  }
51 };
52 
53 template<>
54 class IPCSignalWrapper<const api::Void> {
55 public:
56  typedef api::Void in;
57  typedef std::function<void()> type;
58 
60  getWrapper(const type& callback) {
61  return [callback](const cargo::ipc::PeerID, const std::shared_ptr<in>& /* argIn */)
62  {
63  callback();
64  return true;
65  };
66  }
67 };
68 
69 template<typename ArgIn = const api::Void, typename ArgOut = api::Void>
71 public:
72  typedef typename std::remove_cv<ArgIn>::type in;
73  typedef ArgOut out;
74  typedef std::function<void(const in&, api::MethodResultBuilder::Pointer)> type;
75 
77  getWrapper(const type& callback) {
78  return [callback](const cargo::ipc::PeerID,
79  const std::shared_ptr<in>& argIn,
81  {
82  auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
83  callback(*argIn, rb);
84  return true;
85  };
86  }
87 };
88 
89 template<typename ArgOut>
90 class IPCMethodWrapper<ArgOut, typename std::enable_if<!std::is_const<ArgOut>::value, api::Void>::type> {
91 public:
92  typedef api::Void in;
93  typedef ArgOut out;
94  typedef std::function<void(api::MethodResultBuilder::Pointer)> type;
95 
97  getWrapper(const type& callback) {
98  return [callback](const cargo::ipc::PeerID,
99  const std::shared_ptr<in>& /* argIn */,
101  {
102  auto rb = std::make_shared<api::IPCMethodResultBuilder>(argOut);
103  callback(rb);
104  return true;
105  };
106  }
107 };
108 
109 } // namespace vasum
110 
111 #endif // SERVER_IPC_CALLBACK_WRAPPER_HPP
static cargo::ipc::MethodHandler< out, in >::type getWrapper(const type &callback)
Definition: ipc-callback-wrapper.hpp:97
std::shared_ptr< MethodResult > Pointer
Definition: method-result.hpp:47
static cargo::ipc::MethodHandler< out, in >::type getWrapper(const type &callback)
Definition: ipc-callback-wrapper.hpp:77
std::string PeerID
Definition: types.hpp:45
std::function< void(api::MethodResultBuilder::Pointer)> type
Definition: ipc-callback-wrapper.hpp:94
std::remove_cv< ArgIn >::type in
Definition: ipc-callback-wrapper.hpp:72
Definition: messages.hpp:36
static cargo::ipc::SignalHandler< in >::type getWrapper(const type &callback)
Definition: ipc-callback-wrapper.hpp:60
std::function< void(const in &)> type
Definition: ipc-callback-wrapper.hpp:41
std::function< bool(PeerID peerID, std::shared_ptr< ReceivedDataType > &data)> type
Definition: types.hpp:99
api::Void in
Definition: ipc-callback-wrapper.hpp:56
ArgOut out
Definition: ipc-callback-wrapper.hpp:73
std::function< void()> type
Definition: ipc-callback-wrapper.hpp:57
std::function< void(const in &, api::MethodResultBuilder::Pointer)> type
Definition: ipc-callback-wrapper.hpp:74
static cargo::ipc::SignalHandler< in >::type getWrapper(const type &callback)
Definition: ipc-callback-wrapper.hpp:44
std::remove_cv< ArgIn >::type in
Definition: ipc-callback-wrapper.hpp:40
Definition: ipc-callback-wrapper.hpp:38
Definition: ipc-callback-wrapper.hpp:70
Interface for result builders.
std::function< bool(PeerID peerID, std::shared_ptr< ReceivedDataType > &data, MethodResult::Pointer methodResult) > type
Definition: method-result.hpp:78
Interface for result builders.
Host's internal IPC messages declaration.