-
Notifications
You must be signed in to change notification settings - Fork 33
/
file_interfaces.h
111 lines (95 loc) · 2.76 KB
/
file_interfaces.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2012 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FILE_INTERFACES_H
#define FILE_INTERFACES_H
#include <errno.h>
#include <fcntl.h>
#include <sys/dir.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "nacl-mounts/base/nacl_stat.h"
class FileStream {
public:
virtual ~FileStream() {}
virtual void addref() = 0;
virtual void release() = 0;
virtual FileStream* dup(int fd) = 0;
virtual void close() = 0;
virtual int read(char* buf, size_t count, size_t* nread) = 0;
virtual int write(const char* buf, size_t count, size_t* nwrote) = 0;
virtual int seek(nacl_abi_off_t offset, int whence,
nacl_abi_off_t* new_offset) {
return ESPIPE;
}
virtual int fstat(nacl_abi_stat* out) {
memset(out, 0, sizeof(nacl_abi_stat));
return 0;
}
virtual int isatty() {
errno = EINVAL;
return 0;
}
virtual int tcgetattr(termios* termios_p) {
errno = EINVAL;
return -1;
}
virtual int tcsetattr(int optional_actions, const termios* termios_p) {
errno = EINVAL;
return -1;
}
virtual int fcntl(int cmd, va_list ap) {
errno = EINVAL;
return -1;
}
virtual int ioctl(int request, va_list ap) {
errno = EINVAL;
return -1;
}
virtual bool is_read_ready() {
return true;
}
virtual bool is_write_ready() {
return true;
}
virtual bool is_exception() {
return false;
}
};
class PathHandler {
public:
virtual ~PathHandler() {}
virtual void addref() = 0;
virtual void release() = 0;
virtual FileStream* open(int fd, const char* pathname, int oflag,
int* err) = 0;
virtual int stat(const char* pathname, nacl_abi_stat* out) = 0;
};
class InputInterface {
public:
virtual ~InputInterface() {}
virtual void OnOpen(bool success, bool is_atty) = 0;
virtual void OnRead(const char* buf, size_t size) = 0;
virtual void OnWriteAcknowledge(uint64_t count) = 0;
virtual void OnClose() = 0;
virtual void OnReadReady(bool is_read_ready) = 0;
};
class OutputInterface {
public:
virtual ~OutputInterface() {}
virtual bool OpenFile(int fd, const char* name, int mode,
InputInterface* stream) = 0;
virtual bool OpenSocket(int fd, const char* host, uint16_t port,
InputInterface* stream) = 0;
virtual bool Write(int fd, const char* data, size_t size) = 0;
virtual bool Read(int fd, size_t size) = 0;
virtual bool Close(int fd) = 0;
virtual void ReadPass(const char* prompt, size_t size, bool echo) = 0;
virtual size_t GetWriteWindow() = 0;
virtual void SendExitCode(int error) = 0;
};
#endif // FILE_INTERFACES_H