niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/interface/file_wrapper.h" |
| 17 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
henrike@webrtc.org | 9a6dac4 | 2012-09-27 22:20:34 +0000 | [diff] [blame] | 18 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | namespace webrtc { |
andrew@webrtc.org | 5ae19de | 2011-12-13 22:59:33 +0000 | [diff] [blame] | 20 | |
henrike@webrtc.org | 9a6dac4 | 2012-09-27 22:20:34 +0000 | [diff] [blame] | 21 | class RWLockWrapper; |
| 22 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 23 | class FileWrapperImpl : public FileWrapper { |
| 24 | public: |
| 25 | FileWrapperImpl(); |
| 26 | virtual ~FileWrapperImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 28 | virtual int FileName(char* file_name_utf8, |
pbos@webrtc.org | a2a2718 | 2013-08-01 17:26:15 +0000 | [diff] [blame] | 29 | size_t size) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
pbos@webrtc.org | a2a2718 | 2013-08-01 17:26:15 +0000 | [diff] [blame] | 31 | virtual bool Open() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 33 | virtual int OpenFile(const char* file_name_utf8, |
| 34 | bool read_only, |
| 35 | bool loop = false, |
pbos@webrtc.org | a2a2718 | 2013-08-01 17:26:15 +0000 | [diff] [blame] | 36 | bool text = false) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 38 | virtual int OpenFromFileHandle(FILE* handle, |
| 39 | bool manage_file, |
| 40 | bool read_only, |
| 41 | bool loop = false) OVERRIDE; |
| 42 | |
pbos@webrtc.org | a2a2718 | 2013-08-01 17:26:15 +0000 | [diff] [blame] | 43 | virtual int CloseFile() OVERRIDE; |
| 44 | virtual int SetMaxFileSize(size_t bytes) OVERRIDE; |
| 45 | virtual int Flush() OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 47 | virtual int Read(void* buf, size_t length) OVERRIDE; |
| 48 | virtual bool Write(const void* buf, size_t length) OVERRIDE; |
pbos@webrtc.org | a2a2718 | 2013-08-01 17:26:15 +0000 | [diff] [blame] | 49 | virtual int WriteText(const char* format, ...) OVERRIDE; |
| 50 | virtual int Rewind() OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 52 | private: |
| 53 | int CloseFileImpl(); |
| 54 | int FlushImpl(); |
henrike@webrtc.org | 9a6dac4 | 2012-09-27 22:20:34 +0000 | [diff] [blame] | 55 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 56 | scoped_ptr<RWLockWrapper> rw_lock_; |
henrike@webrtc.org | 9a6dac4 | 2012-09-27 22:20:34 +0000 | [diff] [blame] | 57 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 58 | FILE* id_; |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 59 | bool managed_file_handle_; |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 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]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | }; |
andrew@webrtc.org | 5ae19de | 2011-12-13 22:59:33 +0000 | [diff] [blame] | 67 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 68 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
phoglund@webrtc.org | 740be44 | 2012-12-12 12:52:15 +0000 | [diff] [blame] | 70 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_ |