OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 FILE_INTERFACES_H | |
6 #define FILE_INTERFACES_H | |
7 | |
8 #include <errno.h> | |
9 #include <fcntl.h> | |
10 #include <stdarg.h> | |
11 #include <string.h> | |
12 #include <sys/dir.h> | |
13 #include <sys/ioctl.h> | |
14 #include <sys/types.h> | |
15 #include <termios.h> | |
16 #include <unistd.h> | |
17 | |
18 #include "../base/nacl_dirent.h" | |
19 | |
20 class FileStream { | |
21 public: | |
22 virtual ~FileStream() {} | |
23 | |
24 virtual void addref() = 0; | |
25 virtual void release() = 0; | |
26 | |
27 virtual void close() = 0; | |
28 virtual int read(char* buf, size_t count, size_t* nread) = 0; | |
29 virtual int write(const char* buf, size_t count, size_t* nwrote) = 0; | |
30 virtual int seek(nacl_abi_off_t offset, int whence, | |
31 nacl_abi_off_t* new_offset) { | |
32 return ESPIPE; | |
33 } | |
34 virtual int fstat(nacl_abi_stat* out) { | |
35 memset(out, 0, sizeof(nacl_abi_stat)); | |
36 return 0; | |
37 } | |
38 virtual int getdents(dirent* buf, size_t count, size_t* nread) { | |
39 return ENOTDIR; | |
40 } | |
41 | |
42 virtual int isatty() { | |
43 errno = EINVAL; | |
44 return 0; | |
45 } | |
46 virtual int tcgetattr(termios* termios_p) { | |
47 errno = EINVAL; | |
48 return -1; | |
49 } | |
50 virtual int tcsetattr(int optional_actions, const termios* termios_p) { | |
51 errno = EINVAL; | |
52 return -1; | |
53 } | |
54 virtual int fcntl(int cmd, va_list ap) { | |
55 errno = EINVAL; | |
56 return -1; | |
57 } | |
58 virtual int ioctl(int request, va_list ap) { | |
59 errno = EINVAL; | |
60 return -1; | |
61 } | |
62 | |
63 virtual bool is_read_ready() { | |
64 return true; | |
65 } | |
66 virtual bool is_write_ready() { | |
67 return true; | |
68 } | |
69 virtual bool is_exception() { | |
70 return false; | |
71 } | |
72 }; | |
73 | |
74 class PathHandler { | |
75 public: | |
76 virtual ~PathHandler() {} | |
77 | |
78 virtual void addref() = 0; | |
79 virtual void release() = 0; | |
80 | |
81 virtual FileStream* open(int fd, const char* pathname, int oflag) = 0; | |
82 virtual int stat(const char* pathname, nacl_abi_stat* out) = 0; | |
83 }; | |
84 | |
85 class InputInterface { | |
Evgeniy Stepanov
2012/05/28 14:55:12
This seems unused atm? Remove from the CL.
vissi
2012/05/28 15:20:21
Done.
| |
86 public: | |
87 virtual ~InputInterface() {} | |
88 | |
89 virtual void OnOpen(bool success) = 0; | |
90 virtual void OnRead(const char* buf, size_t size) = 0; | |
91 virtual void OnClose() = 0; | |
92 }; | |
93 | |
94 class OutputInterface { | |
95 public: | |
96 virtual ~OutputInterface() {} | |
97 | |
98 virtual bool OpenFile(int fd, const char* name, int mode, | |
99 InputInterface* stream) = 0; | |
100 virtual bool OpenSocket(int fd, const char* host, uint16_t port, | |
101 InputInterface* stream) = 0; | |
102 virtual bool Write(int fd, const char* data, size_t size) = 0; | |
103 virtual bool Read(int fd, size_t size) = 0; | |
104 virtual bool Close(int fd) = 0; | |
105 }; | |
106 | |
107 #endif // FILE_INTERFACES_H | |
108 | |
OLD | NEW |