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 "rtc_base/arraysize.h"
14 
15 namespace {
16 
17 const char* 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     "OPERATION_ERROR_WITH_DATA",
30 };
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.");
52 
53 }  // namespace
54 
55 namespace webrtc {
56 
57 // static
OK()58 RTCError RTCError::OK() {
59   return RTCError();
60 }
61 
message() const62 const char* RTCError::message() const {
63   return message_.c_str();
64 }
65 
set_message(std::string message)66 void RTCError::set_message(std::string message) {
67   message_ = std::move(message);
68 }
69 
ToString(RTCErrorType error)70 const char* ToString(RTCErrorType error) {
71   int index = static_cast<int>(error);
72   return kRTCErrorTypeNames[index];
73 }
74 
ToString(RTCErrorDetailType error)75 const char* ToString(RTCErrorDetailType error) {
76   int index = static_cast<int>(error);
77   return kRTCErrorDetailTypeNames[index];
78 }
79 
80 }  // namespace webrtc
81