blob: 5dbbcfb0067f7d90cc5b4b83764b2b0f643255aa [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,
29 size_t size) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
phoglund@webrtc.org740be442012-12-12 12:52:15 +000031 virtual bool Open() const;
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,
36 bool text = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
phoglund@webrtc.org740be442012-12-12 12:52:15 +000038 virtual int CloseFile();
39 virtual int SetMaxFileSize(size_t bytes);
40 virtual int Flush();
niklase@google.com470e71d2011-07-07 08:21:25 +000041
phoglund@webrtc.org740be442012-12-12 12:52:15 +000042 virtual int Read(void* buf, int length);
43 virtual bool Write(const void* buf, int length);
44 virtual int WriteText(const char* format, ...);
45 virtual int Rewind();
niklase@google.com470e71d2011-07-07 08:21:25 +000046
phoglund@webrtc.org740be442012-12-12 12:52:15 +000047 private:
48 int CloseFileImpl();
49 int FlushImpl();
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000050
phoglund@webrtc.org740be442012-12-12 12:52:15 +000051 scoped_ptr<RWLockWrapper> rw_lock_;
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000052
phoglund@webrtc.org740be442012-12-12 12:52:15 +000053 FILE* id_;
54 bool open_;
55 bool looping_;
56 bool read_only_;
57 size_t max_size_in_bytes_; // -1 indicates file size limitation is off
58 size_t size_in_bytes_;
59 char file_name_utf8_[kMaxFileNameSize];
niklase@google.com470e71d2011-07-07 08:21:25 +000060};
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000061
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000062} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000063
phoglund@webrtc.org740be442012-12-12 12:52:15 +000064#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_