blob: 8764f720f306c3c9155ec4da2e5f06c2c74280d1 [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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000018#include "webrtc/base/scoped_ptr.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010019#include "webrtc/system_wrappers/include/file_wrapper.h"
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000020
niklase@google.com470e71d2011-07-07 08:21:25 +000021namespace webrtc {
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000022
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000023class RWLockWrapper;
24
phoglund@webrtc.org740be442012-12-12 12:52:15 +000025class FileWrapperImpl : public FileWrapper {
26 public:
27 FileWrapperImpl();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000028 ~FileWrapperImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000030 int FileName(char* file_name_utf8, size_t size) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000032 bool Open() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000034 int OpenFile(const char* file_name_utf8,
35 bool read_only,
36 bool loop = false,
37 bool text = false) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000039 int OpenFromFileHandle(FILE* handle,
40 bool manage_file,
41 bool read_only,
42 bool loop = false) override;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000043
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000044 int CloseFile() override;
45 int SetMaxFileSize(size_t bytes) override;
46 int Flush() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000047
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000048 int Read(void* buf, size_t length) override;
49 bool Write(const void* buf, size_t length) override;
50 int WriteText(const char* format, ...) override;
51 int Rewind() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
phoglund@webrtc.org740be442012-12-12 12:52:15 +000053 private:
54 int CloseFileImpl();
55 int FlushImpl();
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000056
kwibergbfefb032016-05-01 14:53:46 -070057 std::unique_ptr<RWLockWrapper> rw_lock_;
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000058
phoglund@webrtc.org740be442012-12-12 12:52:15 +000059 FILE* id_;
henrikg@webrtc.org863b5362013-12-06 16:05:17 +000060 bool managed_file_handle_;
phoglund@webrtc.org740be442012-12-12 12:52:15 +000061 bool open_;
62 bool looping_;
63 bool read_only_;
64 size_t max_size_in_bytes_; // -1 indicates file size limitation is off
65 size_t size_in_bytes_;
66 char file_name_utf8_[kMaxFileNameSize];
niklase@google.com470e71d2011-07-07 08:21:25 +000067};
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000068
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000069} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000070
phoglund@webrtc.org740be442012-12-12 12:52:15 +000071#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_