10b87dfdfe2d26f1b3e98970051a1cac58ebafa5
[platform/core/security/vasum.git] / common / ipc / types.hpp
1 /*
2 *  Copyright (c) 2014 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   Types definitions
23  */
24
25 #ifndef COMMON_IPC_HANDLERS_HPP
26 #define COMMON_IPC_HANDLERS_HPP
27
28 #include "ipc/exception.hpp"
29
30 #include <functional>
31 #include <memory>
32 #include <string>
33
34 namespace vasum {
35 namespace ipc {
36
37 typedef int FileDescriptor;
38 typedef unsigned int MethodID;
39 typedef unsigned int MessageID;
40
41 typedef std::function<void(FileDescriptor)> PeerCallback;
42 typedef std::function<void(int fd, std::shared_ptr<void>& data)> SerializeCallback;
43 typedef std::function<std::shared_ptr<void>(int fd)> ParseCallback;
44
45 enum class Status : int {
46     OK = 0,
47     PARSING_ERROR,
48     SERIALIZATION_ERROR,
49     PEER_DISCONNECTED,
50     NAUGHTY_PEER,
51     REMOVED_PEER,
52     CLOSING,
53     UNDEFINED
54 };
55
56 std::string toString(const Status status);
57 void throwOnError(const Status status);
58 MessageID getNextMessageID();
59
60
61 template<typename SentDataType, typename ReceivedDataType>
62 struct MethodHandler {
63     typedef std::function<std::shared_ptr<SentDataType>(FileDescriptor peerFD,
64                                                         std::shared_ptr<ReceivedDataType>& data)> type;
65 };
66
67 template<typename ReceivedDataType>
68 struct SignalHandler {
69     typedef std::function<void(FileDescriptor peerFD,
70                                std::shared_ptr<ReceivedDataType>& data)> type;
71 };
72
73 template <typename ReceivedDataType>
74 struct ResultHandler {
75     typedef std::function<void(Status status,
76                                std::shared_ptr<ReceivedDataType>& resultData)> type;
77 };
78
79 } // namespace ipc
80 } // namespace vasum
81
82 #endif // COMMON_IPC_HANDLERS_HPP