blob: 63bc6e899d04f57be5c084ed24a185ecde4fd2bd [file] [log] [blame]
Christopher Wileya59f7b92013-02-26 15:07:02 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_FILE_IO_H_
6#define SHILL_FILE_IO_H_
7
8#include <base/lazy_instance.h>
9
10namespace shill {
11
12// A POSIX file IO wrapper to allow mocking in unit tests.
13class FileIO {
14 public:
15 virtual ~FileIO();
16
mukesh agrawalf407d592013-07-31 11:37:57 -070017 // This is a singleton -- use FileIO::GetInstance()->Foo().
Christopher Wileya59f7b92013-02-26 15:07:02 -080018 static FileIO *GetInstance();
19
20 virtual ssize_t Write(int fd, const void *buf, size_t count);
21 virtual ssize_t Read(int fd, void *buf, size_t count);
22 virtual int Close(int fd);
23 virtual int SetFdNonBlocking(int fd);
24
25 protected:
26 FileIO();
27
28 private:
29 friend struct base::DefaultLazyInstanceTraits<FileIO>;
30
31 DISALLOW_COPY_AND_ASSIGN(FileIO);
32};
33
34} // namespace shill
35
36#endif // SHILL_FILE_IO_H_