blob: dd4cd0c1c0cc3ab937c768c9035ddbf41bc566cb [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().
Paul Stewart8ae18742015-06-16 13:13:10 -070018 static FileIO* GetInstance();
Christopher Wileya59f7b92013-02-26 15:07:02 -080019
Paul Stewart8ae18742015-06-16 13:13:10 -070020 virtual ssize_t Write(int fd, const void* buf, size_t count);
21 virtual ssize_t Read(int fd, void* buf, size_t count);
Christopher Wileya59f7b92013-02-26 15:07:02 -080022 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_