blob: 06ba58200bb909e91bfb5797fe347bd00da00f63 [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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000016#include "webrtc/base/scoped_ptr.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010017#include "webrtc/system_wrappers/include/file_wrapper.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();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000026 ~FileWrapperImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000028 int FileName(char* file_name_utf8, size_t size) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000030 bool Open() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000032 int OpenFile(const char* file_name_utf8,
33 bool read_only,
34 bool loop = false,
35 bool text = false) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000037 int OpenFromFileHandle(FILE* handle,
38 bool manage_file,
39 bool read_only,
40 bool loop = false) override;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000041
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000042 int CloseFile() override;
43 int SetMaxFileSize(size_t bytes) override;
44 int Flush() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 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;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
phoglund@webrtc.org740be442012-12-12 12:52:15 +000051 private:
52 int CloseFileImpl();
53 int FlushImpl();
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000054
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000055 rtc::scoped_ptr<RWLockWrapper> rw_lock_;
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000056
phoglund@webrtc.org740be442012-12-12 12:52:15 +000057 FILE* id_;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000058 bool managed_file_handle_;
phoglund@webrtc.org740be442012-12-12 12:52:15 +000059 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];
niklase@google.com470e71d2011-07-07 08:21:25 +000065};
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000066
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000067} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000068
phoglund@webrtc.org740be442012-12-12 12:52:15 +000069#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_