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 | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 13 | #include "absl/strings/string_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/arraysize.h" |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 15 | |
| 16 | namespace { |
| 17 | |
Mirko Bonadei | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 18 | const absl::string_view kRTCErrorTypeNames[] = { |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 19 | "NONE", |
| 20 | "UNSUPPORTED_OPERATION", |
| 21 | "UNSUPPORTED_PARAMETER", |
| 22 | "INVALID_PARAMETER", |
| 23 | "INVALID_RANGE", |
| 24 | "SYNTAX_ERROR", |
| 25 | "INVALID_STATE", |
| 26 | "INVALID_MODIFICATION", |
| 27 | "NETWORK_ERROR", |
| 28 | "RESOURCE_EXHAUSTED", |
| 29 | "INTERNAL_ERROR", |
| 30 | }; |
| 31 | static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) == |
| 32 | (arraysize(kRTCErrorTypeNames) - 1), |
| 33 | "kRTCErrorTypeNames must have as many strings as RTCErrorType " |
| 34 | "has values."); |
| 35 | |
| 36 | } // namespace |
| 37 | |
| 38 | namespace webrtc { |
| 39 | |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 40 | RTCError::RTCError(RTCError&& other) = default; |
| 41 | RTCError& RTCError::operator=(RTCError&& other) = default; |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 42 | |
| 43 | // static |
| 44 | RTCError RTCError::OK() { |
| 45 | return RTCError(); |
| 46 | } |
| 47 | |
| 48 | const char* RTCError::message() const { |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 49 | return message_.c_str(); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 52 | void RTCError::set_message(std::string message) { |
| 53 | message_ = std::move(message); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Mirko Bonadei | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 56 | absl::string_view ToString(RTCErrorType error) { |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 57 | int index = static_cast<int>(error); |
Mirko Bonadei | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 58 | return kRTCErrorTypeNames[index]; |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace webrtc |