PrivMX Endpoint v2.8.0
Loading...
Searching...
No Matches
StreamException.hpp
1/*
2PrivMX Endpoint.
3Copyright © 2024 Simplito sp. z o.o.
4
5This file is part of the PrivMX Platform (https://privmx.dev).
6This software is Licensed under the PrivMX Free License.
7
8See the License for the specific language governing permissions and
9limitations under the License.
10*/
11
12#ifndef _PRIVMXLIB_ENDPOINT_STREAM_EXT_EXCEPTION_HPP_
13#define _PRIVMXLIB_ENDPOINT_STREAM_EXT_EXCEPTION_HPP_
14
15#include "privmx/endpoint/core/Exception.hpp"
16
17#define DECLARE_SCOPE_ENDPOINT_EXCEPTION(NAME, MSG, SCOPE, CODE, ...) \
18 class NAME : public privmx::endpoint::core::Exception { \
19 public: \
20 static constexpr unsigned int SCOPE_CODE = (CODE); \
21 NAME() : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16)) {} \
22 NAME(const std::string& msg, const std::string& name, unsigned int code) \
23 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, std::string()) {} \
24 NAME(const std::string& msg, const std::string& name, unsigned int code, const std::string& description) \
25 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, description) {} \
26 void rethrow() const override; \
27 }; \
28 inline void NAME::rethrow() const { \
29 throw *this; \
30 };
31
32#define DECLARE_ENDPOINT_EXCEPTION(BASE_SCOPED, NAME, MSG, CODE, ...) \
33 class NAME : public BASE_SCOPED { \
34 public: \
35 static constexpr unsigned int FULL_CODE = (BASE_SCOPED::SCOPE_CODE << 16) | (CODE); \
36 NAME() : BASE_SCOPED(MSG, #NAME, CODE) {} \
37 NAME(const std::string& new_of_description) : BASE_SCOPED(MSG, #NAME, CODE, new_of_description) {} \
38 void rethrow() const override; \
39 }; \
40 inline void NAME::rethrow() const { \
41 throw *this; \
42 };
43
44namespace privmx {
45namespace endpoint {
46namespace stream {
47// clang-format off
48#define ENDPOINT_STREAM_EXCEPTION_CODE 0x00080000
49
50DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointStreamException, "Unknown endpoint stream exception", "StreamRoom", 0x0008)
51
52#define STREAM_EXCEPTIONS(X) \
53 X(UnknowStreamRoomFormatException, "Unknown stream room format", 0x0005) \
54 X(WebRTCException, "WebRTC error", 0x0009) \
55 X(IncorrectStreamHandleException, "Incorrect stream handle", 0x000A) \
56 X(IncorrectTrackIdException, "Incorrect track id", 0x000C) \
57 X(CannotExtractStreamRoomCreatedEventException, "Cannot extract StreamRoomCreatedEvent", 0x000F) \
58 X(CannotExtractStreamRoomUpdatedEventException, "Cannot extract StreamRoomUpdatedEvent", 0x0010) \
59 X(CannotExtractStreamRoomDeletedEventException, "Cannot extract StreamRoomDeletedEvent", 0x0011) \
60 X(CannotExtractStreamPublishedEventException, "Cannot extract StreamPublishedEvent", 0x0012) \
61 X(CannotExtractStreamRoomJoinedEventException, "Cannot extract StreamRoomJoinedEvent", 0x0013) \
62 X(CannotExtractStreamUnpublishedEventException, "Cannot extract StreamUnpublishedEvent", 0x0014) \
63 X(CannotExtractStreamRoomLeftEventException, "Cannot extract StreamRoomLeftEvent", 0x0015) \
64 X(StreamRoomDataIntegrityException, "Failed StreamRoom data integrity check", 0x0018) \
65 X(CannotExtractStreamSubscribedEventException, "Cannot extract StreamSubscribedEvent", 0x001B) \
66 X(CannotExtractStreamUnsubscribedEventException, "Cannot extract StreamUnsubscribedEvent", 0x001C) \
67 X(InvalidTurnServerURIException, "Invalid turn server URI", 0x001D) \
68 X(StreamRoomConnectionNotInitialized, "StreamRoom connection not initialized", 0x0020) \
69 X(StreamHandleNotInitialized, "StreamHandle not initialized", 0x0021) \
70 X(StreamAlreadyPublishedException, "Stream is already published", 0x0022) \
71 X(CannotExtractStreamUpdatedEventException, "Cannot extract StreamUpdatedEvent", 0x0023) \
72 X(NullCallbackException, "Callback must not be null", 0x0024) \
73 X(UnknownTypeException, "Unknown type encountered", 0x0025) \
74 X(ThereCanBeOnlyOneDataTrackException, "There can be only one dataTrack per user in StreamRoom", 0x0026) \
75 X(DataTrackNotInitializedException, "Data track not initialized", 0x0027) \
76 X(NoStreamEncryptionKeyException, "No stream encryption key", 0x0028) \
77 X(NoStreamDecryptionKeyException, "No stream decryption key", 0x0029) \
78 X(InvalidEncryptionKeyIdLengthException, "Invalid encryption key id length", 0x002A) \
79 X(InvalidMessageHeaderLengthException, "Invalid message header length", 0x002B) \
80 X(UnsupportedMessageFormatVersionException, "Unsupported message format version length", 0x002C) \
81 X(AlreadyJoinedStreamRoomException, "StreamRoom already joined", 0x002D) \
82 X(InvalidDataChannelSeqException, "Invalid data channel sequence number", 0x002E) \
83 X(StreamHandleNotPublishedException, "StreamHandle not published", 0x002F) \
84 X(SubscriberStreamAlreadyCreatedException, "Subscriber stream is already created", 0x0030) \
85 X(SubscriberStreamHandleNotInitialized, "SubscriberStreamHandle not initialized", 0x0031)
86
87#define PRIVMX_STREAM_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointStreamException, NAME, MSG, CODE)
88STREAM_EXCEPTIONS(PRIVMX_STREAM_DECLARE)
89#undef PRIVMX_STREAM_DECLARE
90
91// compile-time guard: codes are collected from the list above, never retyped
92#define PRIVMX_STREAM_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
93static_assert(
94 privmx::endpoint::core::exceptionCodesUnique({STREAM_EXCEPTIONS(PRIVMX_STREAM_CODE)}),
95 "Duplicate exception code in stream scope"
96);
97#undef PRIVMX_STREAM_CODE
98#undef STREAM_EXCEPTIONS
99// clang-format on
100} // namespace stream
101} // namespace endpoint
102} // namespace privmx
103
104#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
105#undef DECLARE_ENDPOINT_EXCEPTION
106
107#endif // _PRIVMXLIB_ENDPOINT_STREAM_EXT_EXCEPTION_HPP_