Delete unused classes from stream.cc
BUG=webrtc:6424 Review-Url: https://codereview.webrtc.org/2754033003 Cr-Commit-Position: refs/heads/master@{#17281}
This commit is contained in:
parent
c8a4c1f24c
commit
e9ad37ca06
@ -237,61 +237,6 @@ void StreamAdapterInterface::OnEvent(StreamInterface* stream,
|
||||
SignalEvent(this, events, err);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamTap
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
StreamTap::StreamTap(StreamInterface* stream, StreamInterface* tap)
|
||||
: StreamAdapterInterface(stream), tap_(), tap_result_(SR_SUCCESS),
|
||||
tap_error_(0) {
|
||||
AttachTap(tap);
|
||||
}
|
||||
|
||||
StreamTap::~StreamTap() = default;
|
||||
|
||||
void StreamTap::AttachTap(StreamInterface* tap) {
|
||||
tap_.reset(tap);
|
||||
}
|
||||
|
||||
StreamInterface* StreamTap::DetachTap() {
|
||||
return tap_.release();
|
||||
}
|
||||
|
||||
StreamResult StreamTap::GetTapResult(int* error) {
|
||||
if (error) {
|
||||
*error = tap_error_;
|
||||
}
|
||||
return tap_result_;
|
||||
}
|
||||
|
||||
StreamResult StreamTap::Read(void* buffer, size_t buffer_len,
|
||||
size_t* read, int* error) {
|
||||
size_t backup_read;
|
||||
if (!read) {
|
||||
read = &backup_read;
|
||||
}
|
||||
StreamResult res = StreamAdapterInterface::Read(buffer, buffer_len,
|
||||
read, error);
|
||||
if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) {
|
||||
tap_result_ = tap_->WriteAll(buffer, *read, nullptr, &tap_error_);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
StreamResult StreamTap::Write(const void* data, size_t data_len,
|
||||
size_t* written, int* error) {
|
||||
size_t backup_written;
|
||||
if (!written) {
|
||||
written = &backup_written;
|
||||
}
|
||||
StreamResult res = StreamAdapterInterface::Write(data, data_len,
|
||||
written, error);
|
||||
if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) {
|
||||
tap_result_ = tap_->WriteAll(data, *written, nullptr, &tap_error_);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NullStream
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -661,24 +606,6 @@ StreamResult MemoryStream::DoReserve(size_t size, int* error) {
|
||||
return SR_ERROR;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExternalMemoryStream::ExternalMemoryStream() {
|
||||
}
|
||||
|
||||
ExternalMemoryStream::ExternalMemoryStream(void* data, size_t length) {
|
||||
SetData(data, length);
|
||||
}
|
||||
|
||||
ExternalMemoryStream::~ExternalMemoryStream() {
|
||||
}
|
||||
|
||||
void ExternalMemoryStream::SetData(void* data, size_t length) {
|
||||
data_length_ = buffer_length_ = length;
|
||||
buffer_ = static_cast<char*>(data);
|
||||
seek_position_ = 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FifoBuffer
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -894,66 +821,6 @@ StreamResult FifoBuffer::WriteOffsetLocked(const void* buffer,
|
||||
return SR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LoggingAdapter
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LoggingAdapter::LoggingAdapter(StreamInterface* stream, LoggingSeverity level,
|
||||
const std::string& label, bool hex_mode)
|
||||
: StreamAdapterInterface(stream), level_(level), hex_mode_(hex_mode) {
|
||||
set_label(label);
|
||||
}
|
||||
|
||||
void LoggingAdapter::set_label(const std::string& label) {
|
||||
label_.assign("[");
|
||||
label_.append(label);
|
||||
label_.append("]");
|
||||
}
|
||||
|
||||
StreamResult LoggingAdapter::Read(void* buffer, size_t buffer_len,
|
||||
size_t* read, int* error) {
|
||||
size_t local_read; if (!read) read = &local_read;
|
||||
StreamResult result = StreamAdapterInterface::Read(buffer, buffer_len, read,
|
||||
error);
|
||||
if (result == SR_SUCCESS) {
|
||||
LogMultiline(level_, label_.c_str(), true, buffer, *read, hex_mode_, &lms_);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
StreamResult LoggingAdapter::Write(const void* data, size_t data_len,
|
||||
size_t* written, int* error) {
|
||||
size_t local_written;
|
||||
if (!written) written = &local_written;
|
||||
StreamResult result = StreamAdapterInterface::Write(data, data_len, written,
|
||||
error);
|
||||
if (result == SR_SUCCESS) {
|
||||
LogMultiline(level_, label_.c_str(), false, data, *written, hex_mode_,
|
||||
&lms_);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void LoggingAdapter::Close() {
|
||||
LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_);
|
||||
LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_);
|
||||
LOG_V(level_) << label_ << " Closed locally";
|
||||
StreamAdapterInterface::Close();
|
||||
}
|
||||
|
||||
void LoggingAdapter::OnEvent(StreamInterface* stream, int events, int err) {
|
||||
if (events & SE_OPEN) {
|
||||
LOG_V(level_) << label_ << " Open";
|
||||
} else if (events & SE_CLOSE) {
|
||||
LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_);
|
||||
LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_);
|
||||
LOG_V(level_) << label_ << " Closed with error: " << err;
|
||||
}
|
||||
StreamAdapterInterface::OnEvent(stream, events, err);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StringStream - Reads/Writes to an external std::string
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1032,31 +899,6 @@ bool StringStream::ReserveSize(size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamReference
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
StreamReference::StreamReference(StreamInterface* stream)
|
||||
: StreamAdapterInterface(stream, false) {
|
||||
// owner set to false so the destructor does not free the stream.
|
||||
stream_ref_count_ = new StreamRefCount(stream);
|
||||
}
|
||||
|
||||
StreamInterface* StreamReference::NewReference() {
|
||||
stream_ref_count_->AddReference();
|
||||
return new StreamReference(stream_ref_count_, stream());
|
||||
}
|
||||
|
||||
StreamReference::~StreamReference() {
|
||||
stream_ref_count_->Release();
|
||||
}
|
||||
|
||||
StreamReference::StreamReference(StreamRefCount* stream_ref_count,
|
||||
StreamInterface* stream)
|
||||
: StreamAdapterInterface(stream, false),
|
||||
stream_ref_count_(stream_ref_count) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
StreamResult Flow(StreamInterface* source,
|
||||
|
||||
@ -309,38 +309,6 @@ class StreamAdapterInterface : public StreamInterface,
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamAdapterInterface);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamTap is a non-modifying, pass-through adapter, which copies all data
|
||||
// in either direction to the tap. Note that errors or blocking on writing to
|
||||
// the tap will prevent further tap writes from occurring.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class StreamTap : public StreamAdapterInterface {
|
||||
public:
|
||||
explicit StreamTap(StreamInterface* stream, StreamInterface* tap);
|
||||
~StreamTap() override;
|
||||
|
||||
void AttachTap(StreamInterface* tap);
|
||||
StreamInterface* DetachTap();
|
||||
StreamResult GetTapResult(int* error);
|
||||
|
||||
// StreamAdapterInterface Interface
|
||||
StreamResult Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) override;
|
||||
StreamResult Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<StreamInterface> tap_;
|
||||
StreamResult tap_result_;
|
||||
int tap_error_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamTap);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NullStream gives errors on read, and silently discards all written data.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -480,18 +448,6 @@ class MemoryStream : public MemoryStreamBase {
|
||||
char* buffer_alloc_;
|
||||
};
|
||||
|
||||
// ExternalMemoryStream adapts an external memory buffer, so writes which would
|
||||
// extend past the end of the buffer will return end-of-stream.
|
||||
|
||||
class ExternalMemoryStream : public MemoryStreamBase {
|
||||
public:
|
||||
ExternalMemoryStream();
|
||||
ExternalMemoryStream(void* data, size_t length);
|
||||
~ExternalMemoryStream() override;
|
||||
|
||||
void SetData(void* data, size_t length);
|
||||
};
|
||||
|
||||
// FifoBuffer allows for efficient, thread-safe buffering of data between
|
||||
// writer and reader. As the data can wrap around the end of the buffer,
|
||||
// MemoryStreamBase can't help us here.
|
||||
@ -569,37 +525,6 @@ class FifoBuffer : public StreamInterface {
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(FifoBuffer);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class LoggingAdapter : public StreamAdapterInterface {
|
||||
public:
|
||||
LoggingAdapter(StreamInterface* stream, LoggingSeverity level,
|
||||
const std::string& label, bool hex_mode = false);
|
||||
|
||||
void set_label(const std::string& label);
|
||||
|
||||
StreamResult Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) override;
|
||||
StreamResult Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) override;
|
||||
void Close() override;
|
||||
|
||||
protected:
|
||||
void OnEvent(StreamInterface* stream, int events, int err) override;
|
||||
|
||||
private:
|
||||
LoggingSeverity level_;
|
||||
std::string label_;
|
||||
bool hex_mode_;
|
||||
LogMultilineState lms_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(LoggingAdapter);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StringStream - Reads/Writes to an external std::string
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -631,66 +556,6 @@ class StringStream : public StreamInterface {
|
||||
bool read_only_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamReference - A reference counting stream adapter
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Keep in mind that the streams and adapters defined in this file are
|
||||
// not thread-safe, so this has limited uses.
|
||||
|
||||
// A StreamRefCount holds the reference count and a pointer to the
|
||||
// wrapped stream. It deletes the wrapped stream when there are no
|
||||
// more references. We can then have multiple StreamReference
|
||||
// instances pointing to one StreamRefCount, all wrapping the same
|
||||
// stream.
|
||||
|
||||
class StreamReference : public StreamAdapterInterface {
|
||||
class StreamRefCount;
|
||||
public:
|
||||
// Constructor for the first reference to a stream
|
||||
// Note: get more references through NewReference(). Use this
|
||||
// constructor only once on a given stream.
|
||||
explicit StreamReference(StreamInterface* stream);
|
||||
StreamInterface* GetStream() { return stream(); }
|
||||
StreamInterface* NewReference();
|
||||
~StreamReference() override;
|
||||
|
||||
private:
|
||||
class StreamRefCount {
|
||||
public:
|
||||
explicit StreamRefCount(StreamInterface* stream)
|
||||
: stream_(stream), ref_count_(1) {
|
||||
}
|
||||
void AddReference() {
|
||||
CritScope lock(&cs_);
|
||||
++ref_count_;
|
||||
}
|
||||
void Release() {
|
||||
int ref_count;
|
||||
{ // Atomic ops would have been a better fit here.
|
||||
CritScope lock(&cs_);
|
||||
ref_count = --ref_count_;
|
||||
}
|
||||
if (ref_count == 0) {
|
||||
delete stream_;
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
private:
|
||||
StreamInterface* stream_;
|
||||
int ref_count_;
|
||||
CriticalSection cs_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamRefCount);
|
||||
};
|
||||
|
||||
// Constructor for adding references
|
||||
explicit StreamReference(StreamRefCount* stream_ref_count,
|
||||
StreamInterface* stream);
|
||||
|
||||
StreamRefCount* stream_ref_count_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamReference);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Flow attempts to move bytes from source to sink via buffer of size
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user