blob: 51103d648bad730b4d92e09d289c39cd327948ed [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
kwibergbfefb032016-05-01 14:53:46 -070016#include <memory>
17
Henrik Kjellander98f53512015-10-28 18:17:40 +010018#include "webrtc/system_wrappers/include/file_wrapper.h"
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000019
niklase@google.com470e71d2011-07-07 08:21:25 +000020namespace webrtc {
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000021
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000022class RWLockWrapper;
23
phoglund@webrtc.org740be442012-12-12 12:52:15 +000024class FileWrapperImpl : public FileWrapper {
25 public:
26 FileWrapperImpl();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000027 ~FileWrapperImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000028
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000029 int FileName(char* file_name_utf8, size_t size) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000031 bool Open() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 int OpenFile(const char* file_name_utf8,
34 bool read_only,
35 bool loop = false,
36 bool text = false) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 int OpenFromFileHandle(FILE* handle,
39 bool manage_file,
40 bool read_only,
41 bool loop = false) override;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000042
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000043 int CloseFile() override;
44 int SetMaxFileSize(size_t bytes) override;
45 int Flush() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000047 int Read(void* buf, size_t length) override;
48 bool Write(const void* buf, size_t length) override;
49 int WriteText(const char* format, ...) override;
50 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
kwibergbfefb032016-05-01 14:53:46 -070056 std::unique_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_