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", |
| 29 | }; |
| 30 | static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) == |
| 31 | (arraysize(kRTCErrorTypeNames) - 1), |
| 32 | "kRTCErrorTypeNames must have as many strings as RTCErrorType " |
| 33 | "has values."); |
| 34 | |
| 35 | } // namespace |
| 36 | |
| 37 | namespace webrtc { |
| 38 | |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 39 | RTCError::RTCError(RTCError&& other) = default; |
| 40 | RTCError& RTCError::operator=(RTCError&& other) = default; |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 41 | |
| 42 | // static |
| 43 | RTCError RTCError::OK() { |
| 44 | return RTCError(); |
| 45 | } |
| 46 | |
| 47 | const char* RTCError::message() const { |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 48 | return message_.c_str(); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Jonas Olsson | 941a07c | 2018-09-13 10:07:07 +0200 | [diff] [blame] | 51 | void RTCError::set_message(std::string message) { |
| 52 | message_ = std::move(message); |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Mirko Bonadei | fb59a6a | 2019-09-20 09:33:02 +0200 | [diff] [blame] | 55 | const char* ToString(RTCErrorType error) { |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 56 | int index = static_cast<int>(error); |
Mirko Bonadei | 254ecff | 2019-01-16 12:14:29 +0100 | [diff] [blame] | 57 | return kRTCErrorTypeNames[index]; |
deadbeef | 6038e97 | 2017-02-16 23:31:33 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace webrtc |