dpyError.h
1 /*
2  * dpyError.h
3  */
4 #pragma once
5 
6 #ifndef DPY_ERROR
7 #define DPY_ERROR
8 
9 #include <boost/system/error_code.hpp>
10 
14 enum dpy_errors
15 {
17  DPY_OK = 0,
18  DPY_NOT_FOUND = 1,
19  DPY_FORMAT_ERROR = 2,
20  DPY_OVERFLOW = 3,
21  DPY_UNAVAILABLE = 4,
22  DPY_TERMINATED = 5,
23  DPY_IO_ERROR = 6,
24  DPY_COMM_ERROR = 7,
25  DPY_TIMEOUT = 8,
26  DPY_OUT_OF_RANGE = 9,
27  DPY_NO_MEMORY = 10,
28  DPY_NOT_PERMITTED = 11,
29  DPY_DUPLICATE = 12,
30  DPY_BAD_PARAMETER = 13,
31  DPY_CLOSED = 14,
32  DPY_BUSY = 15,
33  DPY_UNSUPPORTED = 16,
34  DPY_NOT_IMPLEMENTED = 17,
35  DPY_NO_EFFECT = 18,
36  DPY_COULD_NOT_OBTAIN_VALUE = 19,
37  DPY_EMPTY_MESSAGE = 20,
38  DPY_PARSE_ERROR = 21,
39  DPY_COMMAND_ERROR = 22,
40  DPY_INVALID_VALUE = 23,
41  DPY_INCOMPLETE = 24,
42  DPY_CONFIG_ERROR = 25,
43  DPY_NOT_READY = 26,
44  DPY_INVALID_CHECKSUM = 27,
45  DPY_REQUEST_PROCESSED = 28,
46  DPY_REQUEST_DEFERRED = 29,
47 
49  DPY_FILE_COULD_NOT_BE_OPENED = 30,
50  DPY_FILE_DOES_NOT_EXIST = 31,
51  DPY_FILE_CORRUPTED = 32,
52  DPY_FILE_JSON_PARSE_ERROR = 33,
53 
55  DPY_PORT_OPEN_ERROR = 40,
56  DPY_PORT_CLOSE_ERROR = 41,
57  DPY_PORT_OPEN_LOCK_ERROR = 42,
58 
59 
61  DPY_EXCEPTION = 45,
62 
63 };
64 
65 #define ERROR_PARSE {ec=DPY_FILE_JSON_PARSE_ERROR;return false;}
66 
75 class dpyError: public boost::system::error_category
76 {
77 public:
82  virtual const char *name() const noexcept
83  {
84  return "DPY_ERRORS";
85  }
91  virtual std::string message(int e) const
92  {
93  switch (e) {
94  case DPY_OK:
95  return "Successful operation.";
96  case DPY_NOT_FOUND:
97  return "Referenced item does not exist or could not be found.";
98  case DPY_FORMAT_ERROR:
99  return "Format obtained does not meet the expected requirements";
100  case DPY_OVERFLOW:
101  return "An overflow occurred or would have occurred.";
102  case DPY_UNAVAILABLE:
103  return "A transient or temporary loss of a service or resource.";
104  case DPY_TERMINATED:
105  return "The process, operation, data stream, session, etc. has stopped.";
106  case DPY_IO_ERROR:
107  return "An IO operation failed.";
108  case DPY_COMM_ERROR:
109  return "Communications error.";
110  case DPY_TIMEOUT:
111  return "A time-out occurred.";
112  case DPY_OUT_OF_RANGE:
113  return "An index or other value is out of range.";
114  case DPY_NO_MEMORY:
115  return "Insufficient memory is available.";
116  case DPY_NOT_PERMITTED:
117  return "Requested action not permitted.";
118  case DPY_DUPLICATE:
119  return "Duplicate entry found or operation already performed.";
120  case DPY_BAD_PARAMETER:
121  return "Invalid parameter (out of range or invalid type).";
122  case DPY_CLOSED:
123  return "The resource is closed.";
124  case DPY_BUSY:
125  return "The resource is busy.";
126  case DPY_UNSUPPORTED:
127  return "The underlying resource does not support this operation.";
128  case DPY_NOT_IMPLEMENTED:
129  return "Unimplemented functionality.";
130  case DPY_NO_EFFECT:
131  return "Call has no effect.";
132  case DPY_COULD_NOT_OBTAIN_VALUE:
133  return "The value could not be obtained";
134  case DPY_EMPTY_MESSAGE:
135  return "The message is empty";
136  case DPY_PARSE_ERROR:
137  return "There was an error during parsing";
138  case DPY_COMMAND_ERROR:
139  return "Expected command response could not be received";
140  case DPY_INVALID_VALUE:
141  return "The value requested is not valid";
142  case DPY_INCOMPLETE:
143  return "The operation requested is missing one or more parameters";
144  case DPY_CONFIG_ERROR:
145  return "Configuration error occurred";
146  case DPY_NOT_READY:
147  return "The requested service is not ready yet";
148  case DPY_INVALID_CHECKSUM:
149  return "Checksum calculation has thrown an error";
150  case DPY_REQUEST_PROCESSED:
151  return "The request was processed but the result of the operation can't be known";
152  case DPY_REQUEST_DEFERRED:
153  return "The request was received and will be processed as soon as possible ";
154  case DPY_FILE_COULD_NOT_BE_OPENED:
155  return "File could not be opened.";
156  case DPY_FILE_DOES_NOT_EXIST:
157  return "File does not exist";
158  case DPY_FILE_CORRUPTED:
159  return "File is corrupted";
160  case DPY_FILE_JSON_PARSE_ERROR:
161  return "The json file could not be parsed";
162  case DPY_PORT_OPEN_ERROR:
163  return "Could not open the port";
164  case DPY_PORT_CLOSE_ERROR:
165  return "Could not close the port";
166  case DPY_PORT_OPEN_LOCK_ERROR:
167  return "Could not open the port, it is locked by another application";
168  case DPY_EXCEPTION:
169  return "Exception occurred while performing operation";
170  default:
171  return "unknown custom::category error";
172  }
173  return "unknown custom::category error";
174  }
175 };
176 
177 inline const boost::system::error_category& get_dpy_error_category();
178 static const boost::system::error_category& dpy_error_category = get_dpy_error_category();
179 
180 const boost::system::error_category& get_dpy_error_category()
181 {
182  static dpyError dpy_cat;
183  return dpy_cat;
184 }
185 
186 
187 inline boost::system::error_code make_error_code(dpy_errors e)
188 {
189  return boost::system::error_code(static_cast<int>(e), dpy_error_category);
190 }
191 
192 namespace boost
193 {
194 namespace system
195 {
199 template<>
200 struct is_error_code_enum<dpy_errors>
201 {
205  BOOST_STATIC_CONSTANT(bool, value = true);
206 };
207 }
208 } // namespaces
209 
210 #endif
Definition: dpyError.h:192
virtual const char * name() const noexcept
Returns the name of the category.
Definition: dpyError.h:82
Allows to categorize the errors.
Definition: dpyError.h:75
virtual std::string message(int e) const
Return the error message according to the error value.
Definition: dpyError.h:91