• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/system_wrappers/interface/file_wrapper.h"
17 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
18 
19 namespace webrtc {
20 
21 class RWLockWrapper;
22 
23 class FileWrapperImpl : public FileWrapper {
24  public:
25   FileWrapperImpl();
26   virtual ~FileWrapperImpl();
27 
28   virtual int FileName(char* file_name_utf8,
29                        size_t size) const OVERRIDE;
30 
31   virtual bool Open() const OVERRIDE;
32 
33   virtual int OpenFile(const char* file_name_utf8,
34                        bool read_only,
35                        bool loop = false,
36                        bool text = false) OVERRIDE;
37 
38   virtual int OpenFromFileHandle(FILE* handle,
39                                  bool manage_file,
40                                  bool read_only,
41                                  bool loop = false) OVERRIDE;
42 
43   virtual int CloseFile() OVERRIDE;
44   virtual int SetMaxFileSize(size_t bytes) OVERRIDE;
45   virtual int Flush() OVERRIDE;
46 
47   virtual int Read(void* buf, int length) OVERRIDE;
48   virtual bool Write(const void* buf, int length) OVERRIDE;
49   virtual int WriteText(const char* format, ...) OVERRIDE;
50   virtual int Rewind() OVERRIDE;
51 
52  private:
53   int CloseFileImpl();
54   int FlushImpl();
55 
56   scoped_ptr<RWLockWrapper> rw_lock_;
57 
58   FILE* id_;
59   bool managed_file_handle_;
60   bool open_;
61   bool looping_;
62   bool read_only_;
63   size_t max_size_in_bytes_;  // -1 indicates file size limitation is off
64   size_t size_in_bytes_;
65   char file_name_utf8_[kMaxFileNameSize];
66 };
67 
68 }  // namespace webrtc
69 
70 #endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_
71