Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: webrtc/system_wrappers/include/file_wrapper.h

Issue 2054373002: FileWrapper[Impl] modifications and actually remove the "Impl" class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix use of ASSERT instead of ASSERT_TRUE in test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/system_wrappers/BUILD.gn ('k') | webrtc/system_wrappers/include/trace.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ 11 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ 12 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 #include <stdio.h> 15 #include <stdio.h>
16 16
17 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/common_types.h" 18 #include "webrtc/common_types.h"
18 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
19 20
20 // Implementation of an InStream and OutStream that can read (exclusive) or 21 // Implementation of an InStream and OutStream that can read (exclusive) or
21 // write from/to a file. 22 // write from/to a file.
22 23
23 namespace webrtc { 24 namespace webrtc {
24 25
26 // TODO(tommi): Remove the base classes, rename to rtc::File and move to base.
25 class FileWrapper : public InStream, public OutStream { 27 class FileWrapper : public InStream, public OutStream {
26 public: 28 public:
27 static const size_t kMaxFileNameSize = 1024; 29 static const size_t kMaxFileNameSize = 1024;
28 30
29 // Factory method. Constructor disabled. 31 // Factory methods.
32 // TODO(tommi): Remove Create().
30 static FileWrapper* Create(); 33 static FileWrapper* Create();
34 static FileWrapper Open(const char* file_name_utf8, bool read_only);
35
36 FileWrapper(FILE* file, size_t max_size);
37 ~FileWrapper() override;
38
39 // Support for move semantics.
40 FileWrapper(FileWrapper&& other);
41 FileWrapper& operator=(FileWrapper&& other);
31 42
32 // Returns true if a file has been opened. 43 // Returns true if a file has been opened.
33 virtual bool Open() const = 0; 44 bool is_open() const { return file_ != nullptr; }
34 45
35 // Opens a file in read or write mode, decided by the read_only parameter. 46 // Opens a file in read or write mode, decided by the read_only parameter.
36 virtual int OpenFile(const char* file_name_utf8, 47 bool OpenFile(const char* file_name_utf8, bool read_only);
37 bool read_only,
38 bool loop = false,
39 bool text = false) = 0;
40 48
41 // Initializes the wrapper from an existing handle. |read_only| must match in 49 // Initializes the wrapper from an existing handle. The wrapper
42 // the mode the file was opened in. If |manage_file| is true, the wrapper
43 // takes ownership of |handle| and closes it in CloseFile(). 50 // takes ownership of |handle| and closes it in CloseFile().
44 virtual int OpenFromFileHandle(FILE* handle, 51 bool OpenFromFileHandle(FILE* handle);
45 bool manage_file,
46 bool read_only,
47 bool loop = false) = 0;
48 52
49 virtual int CloseFile() = 0; 53 void CloseFile();
50 54
51 // Limits the file size to |bytes|. Writing will fail after the cap 55 // Limits the file size to |bytes|. Writing will fail after the cap
52 // is hit. Pass zero to use an unlimited size. 56 // is hit. Pass zero to use an unlimited size.
53 virtual int SetMaxFileSize(size_t bytes) = 0; 57 // TODO(tommi): Could we move this out into a separate class?
58 void SetMaxFileSize(size_t bytes);
54 59
55 // Flush any pending writes. 60 // Flush any pending writes. Note: Flushing when closing, is not required.
56 virtual int Flush() = 0; 61 int Flush();
57 62
58 // Returns the opened file's name in |file_name_utf8|. Provide the size of 63 // Rewinds the file to the start.
59 // the buffer in bytes in |size|. The name will be truncated if |size| is 64 int Rewind() override;
60 // too small. 65 int Read(void* buf, size_t length) override;
61 virtual int FileName(char* file_name_utf8, 66 bool Write(const void* buf, size_t length) override;
62 size_t size) const = 0;
63 67
64 // Write |format| to the opened file. Arguments are taken in the same manner 68 private:
65 // as printf. That is, supply a format string containing text and 69 FileWrapper();
66 // specifiers. Returns the number of characters written or -1 on error.
67 virtual int WriteText(const char* format, ...) = 0;
68 70
69 // Inherited from both Instream and OutStream. 71 void CloseFileImpl();
70 // Rewinds the file to the start. Only available when OpenFile() has been 72 int FlushImpl();
71 // called with |loop| == true or |readOnly| == true. 73
72 // virtual int Rewind() = 0; 74 // TODO(tommi): Remove the lock.
73 int Rewind() override; 75 rtc::CriticalSection lock_;
76
77 FILE* file_ = nullptr;
78 size_t position_ = 0;
79 size_t max_size_in_bytes_ = 0;
80
81 // Copying is not supported.
82 FileWrapper(const FileWrapper&) = delete;
83 FileWrapper& operator=(const FileWrapper&) = delete;
74 }; 84 };
75 85
76 } // namespace webrtc 86 } // namespace webrtc
77 87
78 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ 88 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/BUILD.gn ('k') | webrtc/system_wrappers/include/trace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698