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 Types definitions and helper functions
27 #include "ipc/types.hpp"
28 #include "logger/logger.hpp"
36 std::atomic<MessageID> gLastMessageID(0);
39 MessageID getNextMessageID()
41 return ++gLastMessageID;
44 std::string toString(const Status status)
47 case Status::OK: return "No error, everything is OK";
48 case Status::PARSING_ERROR: return "Exception during reading/parsing data from the socket";
49 case Status::SERIALIZATION_ERROR: return "Exception during writing/serializing data to the socket";
50 case Status::PEER_DISCONNECTED: return "No such peer. Might got disconnected.";
51 case Status::NAUGHTY_PEER: return "Peer performed a forbidden action.";
52 case Status::REMOVED_PEER: return "Removing peer";
53 case Status::CLOSING: return "Closing IPC";
54 case Status::UNDEFINED: return "Undefined state";
55 default: return "Unknown status";
59 void throwOnError(const Status status)
61 if (status == Status::OK) {
65 std::string message = toString(status);
69 case Status::PARSING_ERROR: throw IPCParsingException(message);
70 case Status::SERIALIZATION_ERROR: throw IPCSerializationException(message);
71 case Status::PEER_DISCONNECTED: throw IPCPeerDisconnectedException(message);
72 case Status::NAUGHTY_PEER: throw IPCNaughtyPeerException(message);
73 case Status::REMOVED_PEER: throw IPCException(message);
74 case Status::CLOSING: throw IPCException(message);
75 case Status::UNDEFINED: throw IPCException(message);
76 default: return throw IPCException(message);