Make FileRotatingStream independent of StreamInterface

Bug: webrtc:7811
Change-Id: Ia5c07ad00e90d5b982750004eeb2c8e1cfbae4eb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212969
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33579}
This commit is contained in:
Niels Möller
2021-03-25 15:29:02 +01:00
committed by Commit Bot
parent a4b2c2b207
commit a9311b6761
4 changed files with 48 additions and 72 deletions

View File

@ -27,13 +27,8 @@ namespace rtc {
// constructor. It rotates the files once the current file is full. The
// individual file size and the number of files used is configurable in the
// constructor. Open() must be called before using this stream.
class FileRotatingStream : public StreamInterface {
class FileRotatingStream {
public:
// Use this constructor for reading a directory previously written to with
// this stream.
FileRotatingStream(const std::string& dir_path,
const std::string& file_prefix);
// Use this constructor for writing to a directory. Files in the directory
// matching the prefix will be deleted on open.
FileRotatingStream(const std::string& dir_path,
@ -41,20 +36,13 @@ class FileRotatingStream : public StreamInterface {
size_t max_file_size,
size_t num_files);
~FileRotatingStream() override;
virtual ~FileRotatingStream();
// StreamInterface methods.
StreamState GetState() const override;
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;
bool Flush() override;
void Close() override;
bool IsOpen() const;
bool Write(const void* data, size_t data_len);
bool Flush();
void Close();
// Opens the appropriate file(s). Call this before using the stream.
bool Open();
@ -63,6 +51,8 @@ class FileRotatingStream : public StreamInterface {
// enabled by default for performance.
bool DisableBuffering();
// Below two methods are public for testing only.
// Returns the path used for the i-th newest file, where the 0th file is the
// newest file. The file may or may not exist, this is just used for
// formatting. Index must be less than GetNumFiles().
@ -72,8 +62,6 @@ class FileRotatingStream : public StreamInterface {
size_t GetNumFiles() const { return file_names_.size(); }
protected:
size_t GetMaxFileSize() const { return max_file_size_; }
void SetMaxFileSize(size_t size) { max_file_size_ = size; }
size_t GetRotationIndex() const { return rotation_index_; }