Adding RTCErrorOr class to be used by ORTC APIs.

This utility class can be used to represent either an error or a
successful return value. Follows the pattern of StatusOr in the protobuf
library.

This will be used by ORTC factory methods; for instance, CreateRtpSender
will either return an RtpSender or an error if the parameters are
invalid or some other failure occurs.

This CL also moves RTCError classes to a separate file, and adds tests
that were missing before.

BUG=webrtc:7013

Review-Url: https://codereview.webrtc.org/2692723002
Cr-Commit-Position: refs/heads/master@{#16659}
This commit is contained in:
deadbeef
2017-02-16 23:31:33 -08:00
committed by Commit bot
parent 74520c6718
commit 6038e97e04
8 changed files with 662 additions and 85 deletions

View File

@ -78,6 +78,7 @@
#include "webrtc/api/dtmfsenderinterface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/mediastreaminterface.h"
#include "webrtc/api/rtcerror.h"
#include "webrtc/api/rtpreceiverinterface.h"
#include "webrtc/api/rtpsenderinterface.h"
#include "webrtc/api/stats/rtcstatscollectorcallback.h"
@ -133,62 +134,6 @@ class StatsObserver : public rtc::RefCountInterface {
virtual ~StatsObserver() {}
};
// Enumeration to represent distinct classes of errors that an application
// may wish to act upon differently. These roughly map to DOMExceptions or
// RTCError "errorDetailEnum" values in the web API, as described in the
// comments below.
enum class RTCErrorType {
// No error.
NONE,
// A supplied parameter is valid, but currently unsupported.
// Maps to InvalidAccessError DOMException.
UNSUPPORTED_PARAMETER,
// General error indicating that a supplied parameter is invalid.
// Maps to InvalidAccessError or TypeError DOMException depending on context.
INVALID_PARAMETER,
// Slightly more specific than INVALID_PARAMETER; a parameter's value was
// outside the allowed range.
// Maps to RangeError DOMException.
INVALID_RANGE,
// Slightly more specific than INVALID_PARAMETER; an error occurred while
// parsing string input.
// Maps to SyntaxError DOMException.
SYNTAX_ERROR,
// The object does not support this operation in its current state.
// Maps to InvalidStateError DOMException.
INVALID_STATE,
// An attempt was made to modify the object in an invalid way.
// Maps to InvalidModificationError DOMException.
INVALID_MODIFICATION,
// An error occurred within an underlying network protocol.
// Maps to NetworkError DOMException.
NETWORK_ERROR,
// The operation failed due to an internal error.
// Maps to OperationError DOMException.
INTERNAL_ERROR,
};
// Roughly corresponds to RTCError in the web api. Holds an error type and
// possibly additional information specific to that error.
//
// Doesn't contain anything beyond a type now, but will in the future as more
// errors are implemented.
class RTCError {
public:
RTCError() : type_(RTCErrorType::NONE) {}
explicit RTCError(RTCErrorType type) : type_(type) {}
RTCErrorType type() const { return type_; }
void set_type(RTCErrorType type) { type_ = type; }
private:
RTCErrorType type_;
};
// Outputs the error as a friendly string.
// Update this method when adding a new error type.
std::ostream& operator<<(std::ostream& stream, RTCErrorType error);
class PeerConnectionInterface : public rtc::RefCountInterface {
public:
// See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .