2017-02-16 23:31:33 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/rtcerror.h"
|
2017-02-16 23:31:33 -08:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/arraysize.h"
|
2017-02-16 23:31:33 -08:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
static const char* const kRTCErrorTypeNames[] = {
|
|
|
|
|
"NONE",
|
|
|
|
|
"UNSUPPORTED_OPERATION",
|
|
|
|
|
"UNSUPPORTED_PARAMETER",
|
|
|
|
|
"INVALID_PARAMETER",
|
|
|
|
|
"INVALID_RANGE",
|
|
|
|
|
"SYNTAX_ERROR",
|
|
|
|
|
"INVALID_STATE",
|
|
|
|
|
"INVALID_MODIFICATION",
|
|
|
|
|
"NETWORK_ERROR",
|
|
|
|
|
"RESOURCE_EXHAUSTED",
|
|
|
|
|
"INTERNAL_ERROR",
|
|
|
|
|
};
|
|
|
|
|
static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) ==
|
|
|
|
|
(arraysize(kRTCErrorTypeNames) - 1),
|
|
|
|
|
"kRTCErrorTypeNames must have as many strings as RTCErrorType "
|
|
|
|
|
"has values.");
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
RTCError::RTCError(RTCError&& other)
|
|
|
|
|
: type_(other.type_), have_string_message_(other.have_string_message_) {
|
|
|
|
|
if (have_string_message_) {
|
|
|
|
|
new (&string_message_) std::string(std::move(other.string_message_));
|
|
|
|
|
} else {
|
|
|
|
|
static_message_ = other.static_message_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTCError& RTCError::operator=(RTCError&& other) {
|
|
|
|
|
type_ = other.type_;
|
|
|
|
|
if (other.have_string_message_) {
|
|
|
|
|
set_message(std::move(other.string_message_));
|
|
|
|
|
} else {
|
|
|
|
|
set_message(other.static_message_);
|
|
|
|
|
}
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTCError::~RTCError() {
|
|
|
|
|
// If we hold a message string that was built, rather than a static string,
|
|
|
|
|
// we need to delete it.
|
|
|
|
|
if (have_string_message_) {
|
|
|
|
|
string_message_.~basic_string();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
RTCError RTCError::OK() {
|
|
|
|
|
return RTCError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* RTCError::message() const {
|
|
|
|
|
if (have_string_message_) {
|
|
|
|
|
return string_message_.c_str();
|
|
|
|
|
} else {
|
|
|
|
|
return static_message_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTCError::set_message(const char* message) {
|
|
|
|
|
if (have_string_message_) {
|
|
|
|
|
string_message_.~basic_string();
|
|
|
|
|
have_string_message_ = false;
|
|
|
|
|
}
|
|
|
|
|
static_message_ = message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTCError::set_message(std::string&& message) {
|
|
|
|
|
if (!have_string_message_) {
|
|
|
|
|
new (&string_message_) std::string(std::move(message));
|
|
|
|
|
have_string_message_ = true;
|
|
|
|
|
} else {
|
|
|
|
|
string_message_ = message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Revert "Reland "Remove our stream << overloads from non-test build targets.""
This reverts commit d7ee72041f882c023c73e27a7436c626c4e43604.
Reason for revert: Broke downstream build which was using SdpAudioFormat operator<<
Original change's description:
> Reland "Remove our stream << overloads from non-test build targets."
>
> This is a reland of c841d18d257ba8e4ed7d77d105e3c46006bb1e7e
>
> Original change's description:
> > Remove our stream << overloads from non-test build targets.
> >
> > Most are removed entirely, but RtcErrorType, RtpTransceiverDirection, IPAddress and
> > SocketAddress are kept behind gtest's #ifdef UNIT_TEST.
> >
> > Bug: webrtc:8982
> > Change-Id: I36db19891e7d25aeacb08b9a08aa2b4004765e70
> > Reviewed-on: https://webrtc-review.googlesource.com/64143
> > Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
> > Reviewed-by: Benjamin Wright <benwright@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> > Reviewed-by: Åsa Persson <asapersson@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#22916}
>
> TBR=deadbeef@webrtc.org,kwiberg@webrtc.org,asapersson@webrtc.org,jonasolsson@webrtc.org,benwright@webrtc.org
>
> Bug: webrtc:8982
> Change-Id: Ibe08c6270e5e693eb661a6ce9e8f074b34ef8123
> Reviewed-on: https://webrtc-review.googlesource.com/71161
> Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22949}
TBR=deadbeef@webrtc.org,kwiberg@webrtc.org,asapersson@webrtc.org,jonasolsson@webrtc.org,benwright@webrtc.org
Change-Id: I3c2b18ec2877d68a522ecbae7a2955c4eecf36df
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8982
Reviewed-on: https://webrtc-review.googlesource.com/71446
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22963}
2018-04-20 15:58:11 +00:00
|
|
|
std::ostream& operator<<(std::ostream& stream, RTCErrorType error) {
|
|
|
|
|
return stream << ToString(error);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-03 12:22:07 +02:00
|
|
|
// TODO(jonasolsson): Change to use absl::string_view when it's available.
|
|
|
|
|
std::string ToString(RTCErrorType error) {
|
2017-02-16 23:31:33 -08:00
|
|
|
int index = static_cast<int>(error);
|
2018-04-03 12:22:07 +02:00
|
|
|
return std::string(kRTCErrorTypeNames[index]);
|
2017-02-16 23:31:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|