Christopher Wiley | a59f7b9 | 2013-02-26 15:07:02 -0800 | [diff] [blame] | 1 | // 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 | |
| 10 | namespace shill { |
| 11 | |
| 12 | // A POSIX file IO wrapper to allow mocking in unit tests. |
| 13 | class FileIO { |
| 14 | public: |
| 15 | virtual ~FileIO(); |
| 16 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 17 | // This is a singleton -- use FileIO::GetInstance()->Foo(). |
Christopher Wiley | a59f7b9 | 2013-02-26 15:07:02 -0800 | [diff] [blame] | 18 | 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_ |