blob: 1abf01019407b52ead7be4279612ee3b6dd6881c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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.com470e71d2011-07-07 08:21:25 +000014#include <stdio.h>
15
phoglund@webrtc.org740be442012-12-12 12:52:15 +000016#include "webrtc/system_wrappers/interface/file_wrapper.h"
17#include "webrtc/system_wrappers/interface/scoped_ptr.h"
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000018
niklase@google.com470e71d2011-07-07 08:21:25 +000019namespace webrtc {
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000020
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000021class RWLockWrapper;
22
phoglund@webrtc.org740be442012-12-12 12:52:15 +000023class FileWrapperImpl : public FileWrapper {
24 public:
25 FileWrapperImpl();
26 virtual ~FileWrapperImpl();
niklase@google.com470e71d2011-07-07 08:21:25 +000027
phoglund@webrtc.org740be442012-12-12 12:52:15 +000028 virtual int FileName(char* file_name_utf8,
pbos@webrtc.orga2a27182013-08-01 17:26:15 +000029 size_t size) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
pbos@webrtc.orga2a27182013-08-01 17:26:15 +000031 virtual bool Open() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
phoglund@webrtc.org740be442012-12-12 12:52:15 +000033 virtual int OpenFile(const char* file_name_utf8,
34 bool read_only,
35 bool loop = false,
pbos@webrtc.orga2a27182013-08-01 17:26:15 +000036 bool text = false) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000038 virtual int OpenFromFileHandle(FILE* handle,
39 bool manage_file,
40 bool read_only,
41 bool loop = false) OVERRIDE;
42
pbos@webrtc.orga2a27182013-08-01 17:26:15 +000043 virtual int CloseFile() OVERRIDE;
44 virtual int SetMaxFileSize(size_t bytes) OVERRIDE;
45 virtual int Flush() OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.orga2a27182013-08-01 17:26:15 +000047 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;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
phoglund@webrtc.org740be442012-12-12 12:52:15 +000052 private:
53 int CloseFileImpl();
54 int FlushImpl();
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000055
phoglund@webrtc.org740be442012-12-12 12:52:15 +000056 scoped_ptr<RWLockWrapper> rw_lock_;
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000057
phoglund@webrtc.org740be442012-12-12 12:52:15 +000058 FILE* id_;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000059 bool managed_file_handle_;
phoglund@webrtc.org740be442012-12-12 12:52:15 +000060 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.com470e71d2011-07-07 08:21:25 +000066};
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000067
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000068} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000069
phoglund@webrtc.org740be442012-12-12 12:52:15 +000070#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_