deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "api/rtc_error.h" |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "rtc_base/arraysize.h" |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 14 | |
| 15 | namespace { |
| 16 | |
Mirko Bonadei | fb59a6a | 2019-09-20 09:33:02 +0200 | [diff] [blame] | 17 | const char* kRTCErrorTypeNames[] = { |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 18 | "NONE", |
| 19 | "UNSUPPORTED_OPERATION", |
| 20 | "UNSUPPORTED_PARAMETER", |
| 21 | "INVALID_PARAMETER", |
| 22 | "INVALID_RANGE", |
| 23 | "SYNTAX_ERROR", |
| 24 | "INVALID_STATE", |
| 25 | "INVALID_MODIFICATION", |
| 26 | "NETWORK_ERROR", |
| 27 | "RESOURCE_EXHAUSTED", |
| 28 | "INTERNAL_ERROR", |
Harald Alvestrand | dfbfb46 | 2019-12-08 05:55:43 +0100 | [diff] [blame] | 29 | "OPERATION_ERROR_WITH_DATA", |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 30 | }; |
Harald Alvestrand | dfbfb46 | 2019-12-08 05:55:43 +0100 | [diff] [blame] | 31 | static_assert( |
| 32 | static_cast<int>(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA) == |
| 33 | (arraysize(kRTCErrorTypeNames) - 1), |
| 34 | "kRTCErrorTypeNames must have as many strings as RTCErrorType " |
| 35 | "has values."); |
| 36 | |
| 37 | const char* kRTCErrorDetailTypeNames[] = { |
| 38 | "NONE", |
| 39 | "DATA_CHANNEL_FAILURE", |
| 40 | "DTLS_FAILURE", |
| 41 | "FINGERPRINT_FAILURE", |
| 42 | "SCTP_FAILURE", |
| 43 | "SDP_SYNTAX_ERROR", |
| 44 | "HARDWARE_ENCODER_NOT_AVAILABLE", |
| 45 | "HARDWARE_ENCODER_ERROR", |
| 46 | }; |
| 47 | static_assert( |
| 48 | static_cast<int>(webrtc::RTCErrorDetailType::HARDWARE_ENCODER_ERROR) == |
| 49 | (arraysize(kRTCErrorDetailTypeNames) - 1), |
| 50 | "kRTCErrorDetailTypeNames must have as many strings as " |
| 51 | "RTCErrorDetailType has values."); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | namespace webrtc { |
| 56 | |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 57 | // static |
| 58 | RTCError RTCError::OK() { |
| 59 | return RTCError(); |
| 60 | } |
| 61 | |
| 62 | const char* RTCError::message() const { |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 63 | return message_.c_str(); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 66 | void RTCError::set_message(std::string message) { |
| 67 | message_ = std::move(message); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Mirko Bonadei | fb59a6a | 2019-09-20 09:33:02 +0200 | [diff] [blame] | 70 | const char* ToString(RTCErrorType error) { |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 71 | int index = static_cast<int>(error); |
Mirko Bonadei | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 72 | return kRTCErrorTypeNames[index]; |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Harald Alvestrand | dfbfb46 | 2019-12-08 05:55:43 +0100 | [diff] [blame] | 75 | const char* ToString(RTCErrorDetailType error) { |
| 76 | int index = static_cast<int>(error); |
| 77 | return kRTCErrorDetailTypeNames[index]; |
| 78 | } |
| 79 | |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 80 | } // namespace webrtc |