| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "api/rtc_error.h" |
| 12 |
| 13 | #include <iterator> |
| 14 |
| 15 | #include "absl/strings/string_view.h" |
| 16 |
| 17 | namespace { |
| 18 |
| 19 | absl::string_view kRTCErrorTypeNames[] = { |
| 20 | "NONE", |
| 21 | "UNSUPPORTED_OPERATION", |
| 22 | "UNSUPPORTED_PARAMETER", |
| 23 | "INVALID_PARAMETER", |
| 24 | "INVALID_RANGE", |
| 25 | "SYNTAX_ERROR", |
| 26 | "INVALID_STATE", |
| 27 | "INVALID_MODIFICATION", |
| 28 | "NETWORK_ERROR", |
| 29 | "RESOURCE_EXHAUSTED", |
| 30 | "INTERNAL_ERROR", |
| 31 | "OPERATION_ERROR_WITH_DATA", |
| 32 | }; |
| 33 | static_assert( |
| 34 | static_cast<int>(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA) == |
| 35 | (std::size(kRTCErrorTypeNames) - 1), |
| 36 | "kRTCErrorTypeNames must have as many strings as RTCErrorType " |
| 37 | "has values."); |
| 38 |
| 39 | absl::string_view kRTCErrorDetailTypeNames[] = { |
| 40 | "NONE", |
| 41 | "DATA_CHANNEL_FAILURE", |
| 42 | "DTLS_FAILURE", |
| 43 | "FINGERPRINT_FAILURE", |
| 44 | "SCTP_FAILURE", |
| 45 | "SDP_SYNTAX_ERROR", |
| 46 | "HARDWARE_ENCODER_NOT_AVAILABLE", |
| 47 | "HARDWARE_ENCODER_ERROR", |
| 48 | }; |
| 49 | static_assert( |
| 50 | static_cast<int>(webrtc::RTCErrorDetailType::HARDWARE_ENCODER_ERROR) == |
| 51 | (std::size(kRTCErrorDetailTypeNames) - 1), |
| 52 | "kRTCErrorDetailTypeNames must have as many strings as " |
| 53 | "RTCErrorDetailType has values."); |
| 54 |
| 55 | } // namespace |
| 56 |
| 57 | namespace webrtc { |
| 58 |
| 59 | // static |
| 60 | RTCError RTCError::OK() { |
| 61 | return RTCError(); |
| 62 | } |
| 63 |
| 64 | const char* RTCError::message() const { |
| 65 | return message_.c_str(); |
| 66 | } |
| 67 |
| 68 | void RTCError::set_message(absl::string_view message) { |
| 69 | message_ = std::string(message); |
| 70 | } |
| 71 |
| 72 | absl::string_view ToString(RTCErrorType error) { |
| 73 | int index = static_cast<int>(error); |
| 74 | return kRTCErrorTypeNames[index]; |
| 75 | } |
| 76 |
| 77 | absl::string_view ToString(RTCErrorDetailType error) { |
| 78 | int index = static_cast<int>(error); |
| 79 | return kRTCErrorDetailTypeNames[index]; |
| 80 | } |
| 81 |
| 82 | } // namespace webrtc |
| 83 |