duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
result.cpp
Go to the documentation of this file.
1
7
8namespace duvc {
9
10const char *to_string(ErrorCode code) {
11 switch (code) {
13 return "Success";
15 return "Device not found or disconnected";
17 return "Device is busy or in use";
19 return "Property not supported by device";
21 return "Property value out of range";
23 return "Insufficient permissions";
25 return "System/platform error";
27 return "Invalid function argument";
29 return "Feature not implemented on this platform";
30 default:
31 return "Unknown error";
32 }
33}
34
35Error::Error(ErrorCode code, std::string message)
36 : code_(code), message_(std::move(message)) {}
37
38Error::Error(std::error_code code, std::string message)
39 : code_(ErrorCode::SystemError), message_(std::move(message)) {
40 if (message_.empty()) {
41 message_ = code.message();
42 } else {
43 message_ += ": " + code.message();
44 }
45}
46
47std::string Error::description() const {
48 std::string desc = to_string(code_);
49 if (!message_.empty()) {
50 desc += ": " + message_;
51 }
52 return desc;
53}
54
55} // namespace duvc
Error(ErrorCode code, std::string message="")
Create error with code and message.
Definition result.cpp:35
ErrorCode code() const
Get error code.
Definition result.h:58
std::string description() const
Get full error description.
Definition result.cpp:47
Result type that can contain either a value or an error.
Definition result.h:75
Definition core.h:13
ErrorCode
Error codes for duvc operations.
Definition result.h:19
@ InvalidValue
Property value out of range.
@ InvalidArgument
Invalid function argument.
@ DeviceBusy
Device is busy or in use.
@ PermissionDenied
Insufficient permissions.
@ Success
Operation succeeded.
@ PropertyNotSupported
Property not supported by device.
@ NotImplemented
Feature not implemented on this platform.
@ SystemError
System/platform error.
@ DeviceNotFound
Device not found or disconnected.
const char * to_string(CamProp)
Convert camera property enum to string.
Definition core.cpp:678
Result/Error type system for duvc-ctl.