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