forked from bluerange-io/bluerange-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptions.h
197 lines (176 loc) · 10.4 KB
/
Exceptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
////////////////////////////////////////////////////////////////////////////////
// /****************************************************************************
// **
// ** Copyright (C) 2015-2022 M-Way Solutions GmbH
// ** Contact: https://www.blureange.io/licensing
// **
// ** This file is part of the Bluerange/FruityMesh implementation
// **
// ** $BR_BEGIN_LICENSE:GPL-EXCEPT$
// ** Commercial License Usage
// ** Licensees holding valid commercial Bluerange licenses may use this file in
// ** accordance with the commercial license agreement provided with the
// ** Software or, alternatively, in accordance with the terms contained in
// ** a written agreement between them and M-Way Solutions GmbH.
// ** For licensing terms and conditions see https://www.bluerange.io/terms-conditions. For further
// ** information use the contact form at https://www.bluerange.io/contact.
// **
// ** GNU General Public License Usage
// ** Alternatively, this file may be used under the terms of the GNU
// ** General Public License version 3 as published by the Free Software
// ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
// ** included in the packaging of this file. Please review the following
// ** information to ensure the GNU General Public License requirements will
// ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
// **
// ** $BR_END_LICENSE$
// **
// ****************************************************************************/
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <set>
#include <string>
#include <typeinfo>
#include <exception>
#include <typeindex>
#include "debugbreak.h"
//We accumulate exception for one simulation step when it is disabled and cleared at the start of next simulation step
extern void LogThrownCherrySimException(std::type_index index);
struct FruityMeshException : public std::exception {};
//LCOV_EXCL_START Debug Code
#define CREATEEXCEPTION(T) struct T : FruityMeshException{};
#define CREATEEXCEPTIONINHERITING(T, Parent) struct T : Parent{};
CREATEEXCEPTION(IllegalArgumentException);
CREATEEXCEPTIONINHERITING(CommandNotFoundException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(CRCMissingException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(CRCInvalidException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(WrongCommandParameterException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(TooFewParameterException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(MessageTooLongException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(MessageTooSmallException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(TooManyArgumentsException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(IndexOutOfBoundsException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(CommandTooLongException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(NotANumberStringException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(NumberStringNotInRangeException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(MoreThanOneTerminalCommandHandlerReactedOnCommandException, IllegalArgumentException);
CREATEEXCEPTIONINHERITING(UnknownJsonEntryException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(IllegalParameterException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(NotAValidMessageTypeException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(IllegalFruityMeshPacketException , IllegalArgumentException);
CREATEEXCEPTIONINHERITING(IntegerUnderflowException , IllegalArgumentException);
CREATEEXCEPTION(IllegalStateException);
CREATEEXCEPTIONINHERITING(ZeroOnNonPodTypeException , IllegalStateException);
CREATEEXCEPTIONINHERITING(UartNotSetException , IllegalStateException);
CREATEEXCEPTIONINHERITING(ReceivedWrongTimeSyncPacketException , IllegalStateException);
CREATEEXCEPTIONINHERITING(ModuleAllocatorMemoryAlreadySetException , IllegalStateException);
CREATEEXCEPTIONINHERITING(ErrorCodeUnknownException , IllegalStateException);
CREATEEXCEPTIONINHERITING(RecordStorageIsLockedDownException , IllegalStateException);
CREATEEXCEPTIONINHERITING(StackOverflowException , IllegalStateException);
CREATEEXCEPTIONINHERITING(AccessToRemovedConnectionException , IllegalStateException);
CREATEEXCEPTIONINHERITING(InternalTerminalCommandErrorException , IllegalStateException);
CREATEEXCEPTIONINHERITING(FileException , IllegalStateException);
CREATEEXCEPTIONINHERITING(SigProvisioningFailedException , IllegalStateException);
CREATEEXCEPTIONINHERITING(SigCreateElementFailedException , IllegalStateException);
CREATEEXCEPTIONINHERITING(IncorrectHopsToSinkException , IllegalStateException);
CREATEEXCEPTIONINHERITING(JsonParseException , IllegalStateException);
CREATEEXCEPTIONINHERITING(InvalidTerminalIdException , IllegalStateException);
CREATEEXCEPTIONINHERITING(NodeIdNotFoundException , IllegalStateException);
CREATEEXCEPTIONINHERITING(TerminalIdNotFoundException , IllegalStateException);
CREATEEXCEPTIONINHERITING(MulipleNodesHaveSameNodeIdException , IllegalStateException);
CREATEEXCEPTIONINHERITING(MulipleNodesHaveSameNodeAndNetworkIdException, IllegalStateException);
CREATEEXCEPTIONINHERITING(NoSinkConfiguredForMeshGatewayConfigurationException, IllegalStateException);
CREATEEXCEPTIONINHERITING(ImageNotLicenseCompatibleException , IllegalStateException);
CREATEEXCEPTIONINHERITING(LicenseMigrationFailedException , IllegalStateException);
CREATEEXCEPTIONINHERITING(DfuImageCrcException , IllegalStateException);
CREATEEXCEPTIONINHERITING(TransformationFailedException , IllegalStateException);
CREATEEXCEPTIONINHERITING(PreambleNotAtStartException , IllegalStateException);
CREATEEXCEPTIONINHERITING(DoubleDataOffsetException , IllegalStateException);
CREATEEXCEPTIONINHERITING(PinAlreadyInitializedException , IllegalStateException);
CREATEEXCEPTION(BufferException);
CREATEEXCEPTIONINHERITING(TriedToReadEmptyBufferException , BufferException);
CREATEEXCEPTIONINHERITING(BufferTooSmallException , BufferException);
CREATEEXCEPTIONINHERITING(TooManyTerminalCommandListenersException, BufferException);
CREATEEXCEPTIONINHERITING(TooManyTerminalJsonListenersException , BufferException);
CREATEEXCEPTIONINHERITING(TooManyModulesException , BufferException);
CREATEEXCEPTIONINHERITING(RequiredFlashTooBigException , BufferException);
CREATEEXCEPTIONINHERITING(DataToCacheTooBigException , BufferException);
CREATEEXCEPTIONINHERITING(PacketStatBufferSizeNotEnough, BufferException);
CREATEEXCEPTION(PacketException);
CREATEEXCEPTIONINHERITING(PacketTooSmallException , PacketException);
CREATEEXCEPTIONINHERITING(PacketTooBigException , PacketException);
CREATEEXCEPTIONINHERITING(IllegalSenderException , PacketException);
CREATEEXCEPTIONINHERITING(GotUnsupportedActionTypeException , PacketException);
CREATEEXCEPTIONINHERITING(SplitMissingException , PacketException);
CREATEEXCEPTIONINHERITING(SplitNotInMTUException , PacketException);
CREATEEXCEPTION(NodeDidNotRestartException);
CREATEEXCEPTION(BLEStackError);
CREATEEXCEPTION(HardfaultException);
CREATEEXCEPTION(NonCompatibleDataTypeException);
CREATEEXCEPTION(OutOfMemoryException);
CREATEEXCEPTION(AllocatorOutOfMemoryException);
CREATEEXCEPTION(MemoryCorruptionException);
CREATEEXCEPTION(NotFromThisAllocatorException);
CREATEEXCEPTION(TimeoutException);
CREATEEXCEPTION(MessageShouldNotOccurException)
CREATEEXCEPTION(WatchdogTriggeredException);
CREATEEXCEPTION(SafeBootTriggeredException);
CREATEEXCEPTION(MessageTypeInvalidException);
CREATEEXCEPTION(IllegalAdvertismentStateException);
CREATEEXCEPTION(MalformedPacketException);
CREATEEXCEPTION(NotImplementedException);
CREATEEXCEPTION(NotUsedException); //Not a typical use-case but can happen
CREATEEXCEPTION(CorruptOrOutdatedSavefile);
CREATEEXCEPTION(ZeroTimeoutNotSupportedException);
CREATEEXCEPTION(ErrorLoggedException);
CREATEEXCEPTION(InterruptDeadlockException);
CREATEEXCEPTION(DeviceNotAvailableException);
CREATEEXCEPTION(LicenseNotCreatedException);
CREATEEXCEPTION(LicenseNotValidException);
//LCOV_EXCL_STOP debug code
#undef CREATEEXCEPTION //Exceptions must be created above!
#undef CREATEEXCEPTIONINHERITING
namespace Exceptions {
void DisableExceptionByIndex(std::type_index index);
void EnableExceptionByIndex(std::type_index index);
bool IsExceptionEnabledByIndex(std::type_index index);
template<typename T>
bool IsExceptionEnabled() {
return IsExceptionEnabledByIndex(std::type_index(typeid(T)));
}
bool GetDebugBreakOnException();
class DisableDebugBreakOnException {
public:
DisableDebugBreakOnException();
~DisableDebugBreakOnException() noexcept(false);
};
template<typename T>
class ExceptionDisabler {
public:
ExceptionDisabler() {
DisableExceptionByIndex(std::type_index(typeid(T)));
}
~ExceptionDisabler() {
EnableExceptionByIndex(std::type_index(typeid(T)));
}
};
}
#define SIMEXCEPTIONFORCE(T) \
{\
printf("Exception occured: " #T " " __FILE__ " %d\n", __LINE__); \
if(Exceptions::GetDebugBreakOnException()) {\
debug_break(); \
}\
throw T(); \
}
#define SIMEXCEPTION(T) \
{\
if(Exceptions::IsExceptionEnabled<T>()) {\
SIMEXCEPTIONFORCE(T); \
}\
else \
{ \
printf("Exception occured but ignored: " #T " " __FILE__ " %d\n", __LINE__); \
LogThrownCherrySimException(typeid(T)); \
} \
}