deadbeef | 6038e97 | 2017-02-17 07:31:33 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "api/rtcerror.h" |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 13 | #include "rtc_base/arraysize.h" |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 14 | |
| 15 | namespace { |
| 16 | |
| 17 | static const char* const kRTCErrorTypeNames[] = { |
| 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 08:07:07 | [diff] [blame] | 39 | RTCError::RTCError(RTCError&& other) = default; |
| 40 | RTCError& RTCError::operator=(RTCError&& other) = default; |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [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 08:07:07 | [diff] [blame] | 48 | return message_.c_str(); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 49 | } |
| 50 | |
Jonas Olsson | 941a07c | 2018-09-13 08:07:07 | [diff] [blame] | 51 | void RTCError::set_message(std::string message) { |
| 52 | message_ = std::move(message); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 53 | } |
| 54 | |
Jonas Olsson | 7439534 | 2018-04-03 10:22:07 | [diff] [blame] | 55 | // TODO(jonasolsson): Change to use absl::string_view when it's available. |
| 56 | std::string ToString(RTCErrorType error) { |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 57 | int index = static_cast<int>(error); |
Jonas Olsson | 7439534 | 2018-04-03 10:22:07 | [diff] [blame] | 58 | return std::string(kRTCErrorTypeNames[index]); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace webrtc |