bd9d10f218a0db8bdb20ba923f04799b65bf9541
[platform/core/security/vasum.git] / libs / ipc / method-result.hpp
1 /*
2 *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 *  Contact: Jan Olszak <j.olszak@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
19 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Class for sending the result of a method
23  */
24
25 #ifndef COMMON_IPC_METHOD_RESULT_HPP
26 #define COMMON_IPC_METHOD_RESULT_HPP
27
28 #include "ipc/types.hpp"
29 #include "logger/logger.hpp"
30 #include <memory>
31
32 namespace ipc {
33
34 class Processor;
35
36 class MethodResult {
37 public:
38     typedef std::shared_ptr<MethodResult> Pointer;
39
40     MethodResult(Processor& processor,
41                  const MethodID methodID,
42                  const MessageID messageID,
43                  const PeerID peerID);
44
45
46     template<typename Data>
47     void set(const std::shared_ptr<Data>& data)
48     {
49         setInternal(data);
50     }
51
52     void setVoid();
53     void setError(const int code, const std::string& message);
54
55 private:
56     Processor& mProcessor;
57     MethodID mMethodID;
58     PeerID mPeerID;
59     MessageID mMessageID;
60
61     void setInternal(const std::shared_ptr<void>& data);
62 };
63
64 template<typename SentDataType, typename ReceivedDataType>
65 struct MethodHandler {
66     typedef std::function < void(PeerID peerID,
67                                  std::shared_ptr<ReceivedDataType>& data,
68                                  MethodResult::Pointer&& methodResult) > type;
69 };
70
71 } // namespace ipc
72
73 #endif // COMMON_IPC_METHOD_RESULT_HPP