1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_
12 #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_
13 
14 #include <stdio.h>
15 
16 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/system_wrappers/include/file_wrapper.h"
18 
19 namespace webrtc {
20 
21 class RWLockWrapper;
22 
23 class FileWrapperImpl : public FileWrapper {
24  public:
25   FileWrapperImpl();
26   ~FileWrapperImpl() override;
27 
28   int FileName(char* file_name_utf8, size_t size) const override;
29 
30   bool Open() const override;
31 
32   int OpenFile(const char* file_name_utf8,
33                bool read_only,
34                bool loop = false,
35                bool text = false) override;
36 
37   int OpenFromFileHandle(FILE* handle,
38                          bool manage_file,
39                          bool read_only,
40                          bool loop = false) override;
41 
42   int CloseFile() override;
43   int SetMaxFileSize(size_t bytes) override;
44   int Flush() override;
45 
46   int Read(void* buf, size_t length) override;
47   bool Write(const void* buf, size_t length) override;
48   int WriteText(const char* format, ...) override;
49   int Rewind() override;
50 
51  private:
52   int CloseFileImpl();
53   int FlushImpl();
54 
55   rtc::scoped_ptr<RWLockWrapper> rw_lock_;
56 
57   FILE* id_;
58   bool managed_file_handle_;
59   bool open_;
60   bool looping_;
61   bool read_only_;
62   size_t max_size_in_bytes_;  // -1 indicates file size limitation is off
63   size_t size_in_bytes_;
64   char file_name_utf8_[kMaxFileNameSize];
65 };
66 
67 }  // namespace webrtc
68 
69 #endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_
70