errors.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Can-lab Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #pragma once
19 
20 #include <system_error>
21 
22 namespace clpe
23 {
24 static const std::error_code kNoError(0, std::generic_category());
25 
26 class ConnectionError : public std::error_category
27 {
28 public:
29  static constexpr int CannotProbeDriver = -1;
30  static constexpr int CannotFindNetwork = -2;
31  static constexpr int CannotSetAddress = -3;
32  static constexpr int CannotPing = -4;
33  static constexpr int CannotCreateSocket = -5;
34  static constexpr int CannotConnectSocket = -6;
35 
36  static const ConnectionError& get()
37  {
38  static const ConnectionError inst;
39  return inst;
40  }
41 
42  const char* name() const noexcept override
43  {
44  return "ConnectionError";
45  }
46 
47  std::string message(int code) const override
48  {
49  switch (code)
50  {
51  case CannotProbeDriver:
52  return "cannot probe driver";
53  case CannotFindNetwork:
54  return "cannot find network";
55  case CannotSetAddress:
56  return "cannot set address";
57  case CannotPing:
58  return "cannot ping";
59  case CannotCreateSocket:
60  return "cannot create socket";
62  return "cannot connect socket";
63  default:
64  return std::to_string(code);
65  }
66  }
67 };
68 
69 class StartStreamError : public std::error_category
70 {
71 public:
72  static constexpr int FailToCreateTask = -1;
73 
74  static const StartStreamError& get()
75  {
76  static const StartStreamError inst;
77  return inst;
78  }
79 
80  const char* name() const noexcept override
81  {
82  return "StartStreamError";
83  }
84 
85  std::string message(int code) const override
86  {
87  switch (code)
88  {
89  case FailToCreateTask:
90  return "failed to create task";
91  default:
92  return std::to_string(code);
93  }
94  }
95 };
96 
97 class GetFrameError : public std::error_category
98 {
99 public:
100  static constexpr int FrameNotReady = -2;
101  static constexpr int InvalidCamId = -3;
102 
103  static const GetFrameError& get()
104  {
105  static const GetFrameError inst;
106  return inst;
107  }
108 
109  const char* name() const noexcept override
110  {
111  return "GetFrameError";
112  }
113 
114  std::string message(int code) const override
115  {
116  switch (code)
117  {
118  case FrameNotReady:
119  return "frame not ready";
120  case InvalidCamId:
121  return "invalid camera id";
122  default:
123  return std::to_string(code);
124  }
125  }
126 };
127 
128 class GetEepromDataError : public std::error_category
129 {
130 public:
131  static constexpr int InvalidCamId = -1;
132  static constexpr int FailedCommunication = -3;
133  static constexpr int BadChecksum = -4;
134 
135  static const GetEepromDataError& get()
136  {
137  static const GetEepromDataError inst;
138  return inst;
139  }
140 
141  const char* name() const noexcept override
142  {
143  return "GetEepromDataError";
144  }
145 
146  std::string message(int code) const override
147  {
148  switch (code)
149  {
150  case InvalidCamId:
151  return "invalid camera id";
152  case FailedCommunication:
153  return "read failed";
154  case BadChecksum:
155  return "bad checksum";
156  default:
157  return std::to_string(code);
158  }
159  }
160 };
161 } // namespace clpe
clpe::GetFrameError::get
static const GetFrameError & get()
Definition: errors.hpp:103
clpe::StartStreamError::get
static const StartStreamError & get()
Definition: errors.hpp:74
clpe::StartStreamError::name
const char * name() const noexcept override
Definition: errors.hpp:80
clpe::GetEepromDataError::name
const char * name() const noexcept override
Definition: errors.hpp:141
clpe::StartStreamError
Definition: errors.hpp:69
clpe::ConnectionError
Definition: errors.hpp:26
clpe::GetFrameError::name
const char * name() const noexcept override
Definition: errors.hpp:109
clpe::GetEepromDataError
Definition: errors.hpp:128
clpe::ConnectionError::get
static const ConnectionError & get()
Definition: errors.hpp:36
clpe::kNoError
static const std::error_code kNoError(0, std::generic_category())
clpe::GetEepromDataError::BadChecksum
static constexpr int BadChecksum
Definition: errors.hpp:133
clpe::ConnectionError::CannotProbeDriver
static constexpr int CannotProbeDriver
Definition: errors.hpp:29
clpe::GetFrameError::message
std::string message(int code) const override
Definition: errors.hpp:114
clpe::GetEepromDataError::message
std::string message(int code) const override
Definition: errors.hpp:146
clpe::ConnectionError::CannotCreateSocket
static constexpr int CannotCreateSocket
Definition: errors.hpp:33
clpe::GetFrameError
Definition: errors.hpp:97
clpe::GetEepromDataError::FailedCommunication
static constexpr int FailedCommunication
Definition: errors.hpp:132
clpe::GetEepromDataError::get
static const GetEepromDataError & get()
Definition: errors.hpp:135
clpe::GetFrameError::FrameNotReady
static constexpr int FrameNotReady
Definition: errors.hpp:100
clpe::ConnectionError::CannotSetAddress
static constexpr int CannotSetAddress
Definition: errors.hpp:31
clpe
Definition: ClpeNode.hpp:35
clpe::ConnectionError::message
std::string message(int code) const override
Definition: errors.hpp:47
clpe::GetEepromDataError::InvalidCamId
static constexpr int InvalidCamId
Definition: errors.hpp:131
clpe::ConnectionError::CannotConnectSocket
static constexpr int CannotConnectSocket
Definition: errors.hpp:34
clpe::GetFrameError::InvalidCamId
static constexpr int InvalidCamId
Definition: errors.hpp:101
clpe::ConnectionError::CannotPing
static constexpr int CannotPing
Definition: errors.hpp:32
clpe::ConnectionError::name
const char * name() const noexcept override
Definition: errors.hpp:42
clpe::ConnectionError::CannotFindNetwork
static constexpr int CannotFindNetwork
Definition: errors.hpp:30
clpe::StartStreamError::FailToCreateTask
static constexpr int FailToCreateTask
Definition: errors.hpp:72
clpe::StartStreamError::message
std::string message(int code) const override
Definition: errors.hpp:85


clpe_ros
Author(s): Teo Koon Peng
autogenerated on Thu Dec 19 2024 03:50:23