2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jan Olszak <j.olszak@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 Jan Olszak (j.olszak@samsung.com)
22 * @brief Processor's request to call a method
25 #ifndef COMMON_IPC_INTERNALS_METHOD_REQUEST_HPP
26 #define COMMON_IPC_INTERNALS_METHOD_REQUEST_HPP
28 #include "ipc/types.hpp"
29 #include "logger/logger-scope.hpp"
30 #include "config/manager.hpp"
37 MethodRequest(const MethodRequest&) = delete;
38 MethodRequest& operator=(const MethodRequest&) = delete;
40 template<typename SentDataType, typename ReceivedDataType>
41 static std::shared_ptr<MethodRequest> create(const MethodID methodID,
42 const FileDescriptor peerFD,
43 const std::shared_ptr<SentDataType>& data,
44 const typename ResultHandler<ReceivedDataType>::type& process);
47 FileDescriptor peerFD;
49 std::shared_ptr<void> data;
50 SerializeCallback serialize;
52 ResultHandler<void>::type process;
55 MethodRequest(const MethodID methodID, const FileDescriptor peerFD)
58 messageID(getNextMessageID())
63 template<typename SentDataType, typename ReceivedDataType>
64 std::shared_ptr<MethodRequest> MethodRequest::create(const MethodID methodID,
65 const FileDescriptor peerFD,
66 const std::shared_ptr<SentDataType>& data,
67 const typename ResultHandler<ReceivedDataType>::type& process)
69 std::shared_ptr<MethodRequest> request(new MethodRequest(methodID, peerFD));
73 request->serialize = [](const int fd, std::shared_ptr<void>& data)->void {
74 LOGS("Method serialize, peerFD: " << fd);
75 config::saveToFD<SentDataType>(fd, *std::static_pointer_cast<SentDataType>(data));
78 request->parse = [](const int fd)->std::shared_ptr<void> {
79 LOGS("Method parse, peerFD: " << fd);
80 std::shared_ptr<ReceivedDataType> data(new ReceivedDataType());
81 config::loadFromFD<ReceivedDataType>(fd, *data);
85 request->process = [process](Status status, std::shared_ptr<void>& data)->void {
86 LOGS("Method process, status: " << toString(status));
87 std::shared_ptr<ReceivedDataType> tmpData = std::static_pointer_cast<ReceivedDataType>(data);
88 return process(status, tmpData);
97 #endif // COMMON_IPC_INTERNALS_METHOD_REQUEST_HPP