IPC unit tests and testing framework improvements
[platform/core/security/vasum.git] / libs / ipc / exception.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   Exceptions for the IPC
23  */
24
25
26 #ifndef COMMON_IPC_EXCEPTION_HPP
27 #define COMMON_IPC_EXCEPTION_HPP
28
29 #include <stdexcept>
30
31 namespace ipc {
32
33 /**
34  * @brief Base class for all exceptions in libIpc.
35  * @ingroup Types
36  * @defgroup IPCException   IPCException
37  */
38 struct IPCException: public std::runtime_error {
39     explicit IPCException(const std::string& message)
40         : std::runtime_error(message) {}
41 };
42
43 /**
44  * Exception to indicate error while reading/parsing data from the socket.
45  * @ingroup IPCException
46  */
47 struct IPCParsingException: public IPCException {
48     explicit IPCParsingException(const std::string& message = "Exception during reading/parsing data from the socket")
49         : IPCException(message) {}
50 };
51
52 /**
53  * Exception to indicate error while writing/serializing data to the socket.
54  * @ingroup IPCException
55  */
56 struct IPCSerializationException: public IPCException {
57     explicit IPCSerializationException(const std::string& message = "Exception during writing/serializing data to the socket")
58         : IPCException(message) {}
59 };
60
61 /**
62  * Exception to indicate that requested peer is not available, i.e. might got disconnected.
63  * @ingroup IPCException
64  */
65 struct IPCPeerDisconnectedException: public IPCException {
66     explicit IPCPeerDisconnectedException(const std::string& message = "No such peer. Might got disconnected.")
67         : IPCException(message) {}
68 };
69
70 /**
71  * Exception to indicate that peer performed a forbidden action.
72  * @ingroup IPCException
73  */
74 struct IPCNaughtyPeerException: public IPCException {
75     explicit IPCNaughtyPeerException(const std::string& message = "Peer performed a forbidden action.")
76         : IPCException(message) {}
77 };
78
79 /**
80  * Exception to indicate error while removing peer
81  * @ingroup IPCException
82  */
83 struct IPCRemovedPeerException: public IPCException {
84     explicit IPCRemovedPeerException(const std::string& message = "Removing peer")
85         : IPCException(message) {}
86 };
87
88 /**
89  * Exception to indicate error while closing IPC channel
90  * @ingroup IPCException
91  */
92 struct IPCClosingException: public IPCException {
93     explicit IPCClosingException(const std::string& message = "Closing IPC")
94         : IPCException(message) {}
95 };
96
97 /**
98  * Exception to indicate timeout event error
99  * @ingroup IPCException
100  */
101 struct IPCTimeoutException: public IPCException {
102     explicit IPCTimeoutException(const std::string& message)
103         : IPCException(message) {}
104 };
105
106 /**
107  * Exception to indicate socket error
108  * @ingroup IPCException
109  */
110 struct IPCSocketException: public IPCException {
111     IPCSocketException(const int code, const std::string& message)
112         : IPCException(message),
113           mCode(code)
114     {}
115
116     int getCode() const
117     {
118         return mCode;
119     }
120
121 private:
122     int mCode;
123 };
124
125 /**
126  * Exception to indicate user error
127  * @ingroup IPCException
128  */
129 struct IPCUserException: public IPCException {
130     IPCUserException(const int code, const std::string& message)
131         : IPCException(message),
132           mCode(code)
133     {}
134
135     int getCode() const
136     {
137         return mCode;
138     }
139
140 private:
141     int mCode;
142 };
143
144 } // namespace ipc
145
146 #endif // COMMON_IPC_EXCEPTION_HPP