1/*
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
14#include "file_wrapper.h"
15
16#include <stdio.h>
17
18namespace webrtc {
19
20class FileWrapperImpl : public FileWrapper
21{
22public:
23    FileWrapperImpl();
24    virtual ~FileWrapperImpl();
25
26    virtual int FileName(char* fileNameUTF8,
27                         size_t size) const;
28
29    virtual bool Open() const;
30
31    virtual int OpenFile(const char* fileNameUTF8,
32                         bool readOnly,
33                         bool loop = false,
34                         bool text = false);
35
36    virtual int CloseFile();
37    virtual int SetMaxFileSize(size_t bytes);
38    virtual int Flush();
39
40    virtual int Read(void* buf, int length);
41    virtual bool Write(const void *buf, int length);
42    virtual int WriteText(const char* format, ...);
43    virtual int Rewind();
44
45private:
46    FILE* _id;
47    bool _open;
48    bool _looping;
49    bool _readOnly;
50    size_t _maxSizeInBytes; // -1 indicates file size limitation is off
51    size_t _sizeInBytes;
52    char _fileNameUTF8[kMaxFileNameSize];
53};
54
55} // namespace webrtc
56
57#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FILE_IMPL_H_
58