Debian Codegraph @

terps/tads/tads3/vmhost.h

raw symbols SCIP
1 /* $Header$ */
2
3 /*
4 * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
5 *
6 * Please see the accompanying license file, LICENSE.TXT, for information
7 * on using and copying this software.
8 */
9 /*
10 Name
11 vmhost.h - T3 VM host interface
12 Function
13 The host interface defines a set of services that the VM obtains from
14 its host application environment. The VM uses the host interface to
15 obtain these services so that the VM doesn't have to make too many
16 assumptions about the larger application of which it is a subsystem.
17 Every application containing the VM must provide the VM with an
18 implementation of this interface.
19 Notes
20
21 Modified
22 07/29/99 MJRoberts - Creation
23 */
24
25 #ifndef VMHOST_H
26 #define VMHOST_H
27
28 #include "os.h"
29
30 /* ------------------------------------------------------------------------ */
31 /*
32 * I/O Safety Levels. These are defined as integers, not an enum, because
33 * they form a hierarchy; a higher value imposes all of the restrictions of
34 * all lower values, plus additional restrictions of its own.
35 *
36 * In the past, there was a single safety level that controlled both read
37 * and write. In 3.1 we separated the read and write levels. Because
38 * of the history, each level specifies separate read and write permissions
39 * that were formerly combined in that level. The descriptions still apply
40 * even though we track the levels separately - some levels must be
41 * interpreted differently for reading vs writing. For example, if the
42 * read level is 3, it allows current-directory reading, but if the write
43 * level is 3, it denies all write access. Separating the levels allows
44 * for combinations that weren't formerly possible: for exmaple, -s04 (read
45 * 0, write 4) allows reading anywhere but writing nowhere.
46 */
47
48 /* level 0: minimum safety; read/write any file */
49 const int VM_IO_SAFETY_MINIMUM = 0;
50
51 /* level 1: read any file, write only to files in the current directory */
52 const int VM_IO_SAFETY_READ_ANY_WRITE_CUR = 1;
53
54 /* level 2: read/write in current directory only */
55 const int VM_IO_SAFETY_READWRITE_CUR = 2;
56
57 /* level 3: read from current directory only, no writing allowed */
58 const int VM_IO_SAFETY_READ_CUR = 3;
59
60 /* level 4: maximum safety; no file reading or writing allowed */
61 const int VM_IO_SAFETY_MAXIMUM = 4;
62
63
64 /* ------------------------------------------------------------------------ */
65 /*
66 * Network safety levels.
67 */
68
69 /* level 0: minimum safety; all network access */
70 const int VM_NET_SAFETY_MINIMUM = 0;
71
72 /* level 1: localhost access only */
73 const int VM_NET_SAFETY_LOCALHOST = 1;
74
75 /* level 2: no network access */
76 const int VM_NET_SAFETY_MAXIMUM = 2;
77
78
79 /* ------------------------------------------------------------------------ */
80 /*
81 * get_image_name return codes
82 */
83 enum vmhost_gin_t
84 {
85 /*
86 * get_image_name() call ignored - this is returned if the host
87 * system doesn't have a way of asking the user for an image name,
88 * so the caller must rely on whatever other way it has of finding
89 * the image name (which usually means that it can't find a image
90 * name at all, given that it would only call get_image_name() when
91 * it can't otherwise find the name)
92 */
93 VMHOST_GIN_IGNORED,
94
95 /*
96 * user chose not to supply an image name - this is returned when,
97 * for example, the user cancelled out of a file selector dialog
98 */
99 VMHOST_GIN_CANCEL,
100
101 /*
102 * error - the host system can't prompt for a filename because of
103 * some kind of error (not enough memory to load a dialog, for
104 * example)
105 */
106 VMHOST_GIN_ERROR,
107
108 /* success */
109 VMHOST_GIN_SUCCESS
110 };
111
112 /* ------------------------------------------------------------------------ */
113 /*
114 * T3 VM Host Application Interface. This is an abstract class; it must
115 * be implemented by each application that embeds the VM.
116 */
117 class CVmHostIfc
118 {
119 public:
120 virtual ~CVmHostIfc() { }
121
122 /*
123 * Get the file I/O safety read and write levels. These allow the host
124 * application to control the file operations that a program running
125 * under the VM may perform. See the VM_IO_SAFETY_xxx values above.
126 */
127 virtual int get_io_safety_read() = 0;
128 virtual int get_io_safety_write() = 0;
129
130 /*
131 * set the I/O safety level - this should only be done in response
132 * to a user preference setting (such as via a command-line option),
133 * never as a result of some programmatic operation by the executing
134 * image
135 */
136 virtual void set_io_safety(int read_level, int write_level) = 0;
137
138 /*
139 * Get the network safety level settings. This works like the I/O
140 * safety level, but applies to network access. The client level
141 * controls the game's access to network services as a client, such as
142 * the game making http requests of a web server. The server level
143 * controls the game's ability to create network services that accept
144 * incoming connections from other processes and machines.
145 */
146 virtual void get_net_safety(int *client_level, int *server_level) = 0;
147
148 /*
149 * Set the network safety level.
150 */
151 virtual void set_net_safety(int client_level, int server_level) = 0;
152
153 /*
154 * Get the resource loader for system resources (character mapping
155 * tables, the timezone database, etc). This resource loader should be
156 * set up to load resources out of the VM executable or out of the
157 * directory containing the VM executable, since these resources are
158 * associated with the VM itself, not the T3 program executing under
159 * the VM.
160 */
161 virtual class CResLoader *get_sys_res_loader() = 0;
162
163 /*
164 * Set the image file name. The VM calls this after it learns the
165 * name of the image file so that the host system can access the
166 * file if necessary.
167 */
168 virtual void set_image_name(const char *fname) = 0;
169
170 /*
171 * Set the root directory path for individual resources (such as
172 * individual image and sound resources) that we don't find in the
173 * image file or any attached resource collection file. If this is
174 * never called, the directory containing the image file should be used
175 * as the resource root directory.
176 */
177 virtual void set_res_dir(const char *fname) = 0;
178
179 /*
180 * Add a resource collection file. The return value is a non-zero file
181 * number assigned by the host system; the VM uses this number in
182 * subsequent calls to add_resource() to add resources from this file.
183 * The VM cannot add any resources for a file until it first adds the
184 * file with this routine.
185 */
186 virtual int add_resfile(const char *fname) = 0;
187
188 /*
189 * Determine if additional resource files are supported - if this
190 * returns true, add_resfile() can be used, otherwise add_resfile()
191 * will have no effect.
192 */
193 virtual int can_add_resfiles() = 0;
194
195 /*
196 * Add a resource map entry. 'ofs' is the byte offset of the start
197 * of the resource within the file, and 'siz' is the size in bytes
198 * of the resource data. The resource is stored as contiguous bytes
199 * starting at the given file offset and running for the given size.
200 * The 'fileno' is zero for the image file, or the number assigned
201 * by the host system in add_resfile() for other resource files.
202 */
203 virtual void add_resource(unsigned long ofs, unsigned long siz,
204 const char *res_name, size_t res_name_len,
205 int fileno) = 0;
206
207 /*
208 * Add a resource link map entry. This creates an association between
209 * a compiled resource name and a filename in the local file system.
210 * This is used primarily for debugging purposes, so that the compiler
211 * can avoid copying the resource data, instead simply placing a link
212 * for each resource to its local file copy.
213 */
214 virtual void add_resource(const char *fname, size_t fnamelen,
215 const char *res_name, size_t res_name_len) = 0;
216
217 /*
218 * Find a resource. Returns an osfildef* handle to the open resource
219 * file if the resource can be found; the file on return will have its
220 * seek position set to the first byte of the resource in the file,
221 * and *res_size will be set to the size in bytes of the resource
222 * data. If there is no such resource, returns null.
223 */
224 virtual osfildef *find_resource(const char *resname, size_t resname_len,
225 unsigned long *res_size) = 0;
226
227 /*
228 * Get the external resource file path. If we should look for
229 * resource files in a different location than the image file, the
230 * host system can set this to a path that we should use to look for
231 * resource files. If this is null, the VM should simply look in
232 * the same directory that contains the image file. If the host
233 * system provides a path via this routine, the path string must
234 * have a trailing separator character if required, so that we can
235 * directly append a name to this path to form a valid
236 * fully-qualified filename.
237 */
238 virtual const char *get_res_path() = 0;
239
240 /*
241 * Determine if a resource exists. Returns true if so, false if
242 * not.
243 */
244 virtual int resfile_exists(const char *res_name, size_t res_name_len) = 0;
245
246 /*
247 * Ask the user to supply an image file name. We'll call this
248 * routine only if we can't obtain an image file from command line
249 * arguments or from an attachment to the executable.
250 */
251 virtual vmhost_gin_t get_image_name(char *buf, size_t buflen) = 0;
252
253 /*
254 * Get a special system filename path. This is essentially a wrapper
255 * for os_get_special_path() that encapsulates the information needed
256 * for that function. The 'id' value has the same meaning as in
257 * os_get_special_path() (see tads2/osifc.h).
258 */
259 virtual void get_special_file_path(char *buf, size_t buflen, int id) = 0;
260 };
261
262 #endif /* VMHOST_H */
263