blob: c6881df3b9363c70423bc2538ab8810a8ad9afc4 [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
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000014#include "system_wrappers/interface/file_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16#include <stdio.h>
17
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000018#include "system_wrappers/interface/scoped_ptr.h"
19
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
niklase@google.com470e71d2011-07-07 08:21:25 +000024class FileWrapperImpl : public FileWrapper
25{
26public:
27 FileWrapperImpl();
28 virtual ~FileWrapperImpl();
29
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000030 virtual int FileName(char* fileNameUTF8,
31 size_t size) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
33 virtual bool Open() const;
34
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000035 virtual int OpenFile(const char* fileNameUTF8,
36 bool readOnly,
37 bool loop = false,
38 bool text = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000039
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000040 virtual int CloseFile();
41 virtual int SetMaxFileSize(size_t bytes);
42 virtual int Flush();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
andrew@webrtc.org986fab12011-12-15 19:11:41 +000044 virtual int Read(void* buf, int length);
45 virtual bool Write(const void *buf, int length);
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000046 virtual int WriteText(const char* format, ...);
niklase@google.com470e71d2011-07-07 08:21:25 +000047 virtual int Rewind();
48
niklase@google.com470e71d2011-07-07 08:21:25 +000049private:
henrike@webrtc.org9a6dac42012-09-27 22:20:34 +000050 int CloseFileImpl();
51 int FlushImpl();
52
53 scoped_ptr<RWLockWrapper> _rwLock;
54
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000055 FILE* _id;
56 bool _open;
57 bool _looping;
58 bool _readOnly;
59 size_t _maxSizeInBytes; // -1 indicates file size limitation is off
60 size_t _sizeInBytes;
61 char _fileNameUTF8[kMaxFileNameSize];
niklase@google.com470e71d2011-07-07 08:21:25 +000062};
andrew@webrtc.org5ae19de2011-12-13 22:59:33 +000063
niklase@google.com470e71d2011-07-07 08:21:25 +000064} // namespace webrtc
65
66#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_