VirtualBox

source: vbox/trunk/include/VBox/HostServices/GuestControlSvc.h@ 34553

Last change on this file since 34553 was 34553, checked in by vboxsync, 14 years ago

Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/** @file
2 * Guest control service:
3 * Common header for host service and guest clients.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___VBox_HostService_GuestControlService_h
28#define ___VBox_HostService_GuestControlService_h
29
30#include <VBox/types.h>
31#include <VBox/VMMDev.h>
32#include <VBox/VBoxGuest2.h>
33#include <VBox/hgcmsvc.h>
34#include <VBox/log.h>
35#include <iprt/assert.h>
36#include <iprt/string.h>
37
38/** Everything defined in this file lives in this namespace. */
39namespace guestControl {
40
41/******************************************************************************
42* Typedefs, constants and inlines *
43******************************************************************************/
44
45/**
46 * Process status when executed in the guest.
47 */
48enum eProcessStatus
49{
50 /** Process is in an undefined state. */
51 PROC_STS_UNDEFINED = 0,
52 /** Process has been started. */
53 PROC_STS_STARTED = 1,
54 /** Process terminated normally. */
55 PROC_STS_TEN = 2,
56 /** Process terminated via signal. */
57 PROC_STS_TES = 3,
58 /** Process terminated abnormally. */
59 PROC_STS_TEA = 4,
60 /** Process timed out and was killed. */
61 PROC_STS_TOK = 5,
62 /** Process timed out and was not killed successfully. */
63 PROC_STS_TOA = 6,
64 /** Service/OS is stopping, process was killed. */
65 PROC_STS_DWN = 7,
66 /** Something went wrong (error code in flags). */
67 PROC_STS_ERROR = 8
68};
69
70/**
71 * Input flags, set by the host. This is needed for
72 * handling flags on the guest side.
73 * Note: Has to match Main's ProcessInputFlag_* flags!
74 */
75#define INPUT_FLAG_NONE 0
76#define INPUT_FLAG_EOF RT_BIT(0)
77
78/*
79 * Internal tools built into VBoxService which are
80 * used in order to accomplish tasks host<->guest.
81 */
82#define VBOXSERVICE_TOOL_CAT "vbox_cat"
83#define VBOXSERVICE_TOOL_MKDIR "vbox_mkdir"
84
85/**
86 * Input status, reported by the client.
87 */
88enum eInputStatus
89{
90 /** Input is in an undefined state. */
91 INPUT_STS_UNDEFINED = 0,
92 /** Input was written (partially, see cbProcessed). */
93 INPUT_STS_WRITTEN = 1,
94 /** Input failed with an error (see flags for rc). */
95 INPUT_STS_ERROR = 20,
96 /** Process has abandoned / terminated input handling. */
97 INPUT_STS_TERMINATED = 21,
98 /** Too much input data. */
99 INPUT_STS_OVERFLOW = 30
100};
101
102typedef struct _VBoxGuestCtrlCallbackHeader
103{
104 /** Magic number to identify the structure. */
105 uint32_t u32Magic;
106 /** Context ID to identify callback data. */
107 uint32_t u32ContextID;
108} CALLBACKHEADER, *PCALLBACKHEADER;
109
110/**
111 * Data structure to pass to the service extension callback. We use this to
112 * notify the host of changes to properties.
113 */
114typedef struct _VBoxGuestCtrlCallbackDataExecStatus
115{
116 /** Callback data header. */
117 CALLBACKHEADER hdr;
118 /** The process ID (PID). */
119 uint32_t u32PID;
120 /* The process status. */
121 uint32_t u32Status;
122 /** Optional flags, varies, based on u32Status. */
123 uint32_t u32Flags;
124 /** Optional data buffer (not used atm). */
125 void *pvData;
126 /** Size of optional data buffer (not used atm). */
127 uint32_t cbData;
128} CALLBACKDATAEXECSTATUS, *PCALLBACKDATAEXECSTATUS;
129
130typedef struct _VBoxGuestCtrlCallbackDataExecOut
131{
132 /** Callback data header. */
133 CALLBACKHEADER hdr;
134 /** The process ID (PID). */
135 uint32_t u32PID;
136 /* The handle ID (stdout/stderr). */
137 uint32_t u32HandleId;
138 /** Optional flags (not used atm). */
139 uint32_t u32Flags;
140 /** Optional data buffer. */
141 void *pvData;
142 /** Size (in bytes) of optional data buffer. */
143 uint32_t cbData;
144} CALLBACKDATAEXECOUT, *PCALLBACKDATAEXECOUT;
145
146typedef struct _VBoxGuestCtrlCallbackDataExecInStatus
147{
148 /** Callback data header. */
149 CALLBACKHEADER hdr;
150 /** The process ID (PID). */
151 uint32_t u32PID;
152 /** Current input status. */
153 uint32_t u32Status;
154 /** Optional flags. */
155 uint32_t u32Flags;
156 /** Size (in bytes) of processed input data. */
157 uint32_t cbProcessed;
158} CALLBACKDATAEXECINSTATUS, *PCALLBACKDATAEXECINSTATUS;
159
160typedef struct _VBoxGuestCtrlCallbackDataClientDisconnected
161{
162 /** Callback data header. */
163 CALLBACKHEADER hdr;
164} CALLBACKDATACLIENTDISCONNECTED, *PCALLBACKDATACLIENTDISCONNECTED;
165
166enum
167{
168 /** Magic number for sanity checking the CALLBACKDATACLIENTDISCONNECTED structure. */
169 CALLBACKDATAMAGICCLIENTDISCONNECTED = 0x08041984,
170 /** Magic number for sanity checking the CALLBACKDATAEXECSTATUS structure. */
171 CALLBACKDATAMAGICEXECSTATUS = 0x26011982,
172 /** Magic number for sanity checking the CALLBACKDATAEXECOUT structure. */
173 CALLBACKDATAMAGICEXECOUT = 0x11061949,
174 /** Magic number for sanity checking the CALLBACKDATAEXECIN structure. */
175 CALLBACKDATAMAGICEXECINSTATUS = 0x19091951
176};
177
178enum eVBoxGuestCtrlCallbackType
179{
180 VBOXGUESTCTRLCALLBACKTYPE_UNKNOWN = 0,
181 VBOXGUESTCTRLCALLBACKTYPE_EXEC_START = 1,
182 VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT = 2,
183 VBOXGUESTCTRLCALLBACKTYPE_EXEC_INPUT_STATUS = 3
184};
185
186/**
187 * The service functions which are callable by host.
188 */
189enum eHostFn
190{
191 /**
192 * The host asks the client to cancel all pending waits and exit.
193 */
194 HOST_CANCEL_PENDING_WAITS = 0,
195 /**
196 * The host wants to execute something in the guest. This can be a command line
197 * or starting a program.
198 */
199 HOST_EXEC_CMD = 100,
200 /**
201 * Sends input data for stdin to a running process executed by HOST_EXEC_CMD.
202 */
203 HOST_EXEC_SET_INPUT = 101,
204 /**
205 * Gets the current status of a running process, e.g.
206 * new data on stdout/stderr, process terminated etc.
207 */
208 HOST_EXEC_GET_OUTPUT = 102
209};
210
211/**
212 * The service functions which are called by guest. The numbers may not change,
213 * so we hardcode them.
214 */
215enum eGuestFn
216{
217 /**
218 * Guest waits for a new message the host wants to process on the guest side.
219 * This is a blocking call and can be deferred.
220 */
221 GUEST_GET_HOST_MSG = 1,
222 /**
223 * Guest asks the host to cancel all pending waits the guest itself waits on.
224 * This becomes necessary when the guest wants to quit but still waits for
225 * commands from the host.
226 */
227 GUEST_CANCEL_PENDING_WAITS = 2,
228 /**
229 * Guest disconnected (terminated normally or due to a crash HGCM
230 * detected when calling service::clientDisconnect().
231 */
232 GUEST_DISCONNECTED = 3,
233 /**
234 * Guests sends output from an executed process.
235 */
236 GUEST_EXEC_SEND_OUTPUT = 100,
237 /**
238 * Guest sends a status update of an executed process to the host.
239 */
240 GUEST_EXEC_SEND_STATUS = 101,
241 /**
242 * Guests sends an input status notification to the host.
243 */
244 GUEST_EXEC_SEND_INPUT_STATUS = 102
245};
246
247/*
248 * HGCM parameter structures.
249 */
250#pragma pack (1)
251typedef struct _VBoxGuestCtrlHGCMMsgType
252{
253 VBoxGuestHGCMCallInfo hdr;
254
255 /**
256 * The returned command the host wants to
257 * run on the guest.
258 */
259 HGCMFunctionParameter msg; /* OUT uint32_t */
260 /** Number of parameters the message needs. */
261 HGCMFunctionParameter num_parms; /* OUT uint32_t */
262
263} VBoxGuestCtrlHGCMMsgType;
264
265/**
266 * Asks the guest control host service to cancel all pending
267 * (outstanding) waits which were not processed yet. This is
268 * handy for a graceful shutdown.
269 */
270typedef struct _VBoxGuestCtrlHGCMMsgCancelPendingWaits
271{
272 VBoxGuestHGCMCallInfo hdr;
273} VBoxGuestCtrlHGCMMsgCancelPendingWaits;
274
275/**
276 * Executes a command inside the guest.
277 */
278typedef struct _VBoxGuestCtrlHGCMMsgExecCmd
279{
280 VBoxGuestHGCMCallInfo hdr;
281 /** Context ID. */
282 HGCMFunctionParameter context;
283 /** The command to execute on the guest. */
284 HGCMFunctionParameter cmd;
285 /** Execution flags (see IGuest::ExecuteProcessFlag_*). */
286 HGCMFunctionParameter flags;
287 /** Number of arguments. */
288 HGCMFunctionParameter num_args;
289 /** The actual arguments. */
290 HGCMFunctionParameter args;
291 /** Number of environment value pairs. */
292 HGCMFunctionParameter num_env;
293 /** Size (in bytes) of environment block, including terminating zeros. */
294 HGCMFunctionParameter cb_env;
295 /** The actual environment block. */
296 HGCMFunctionParameter env;
297 /** The user name to run the executed command under. */
298 HGCMFunctionParameter username;
299 /** The user's password. */
300 HGCMFunctionParameter password;
301 /** Timeout (in msec) which either specifies the
302 * overall lifetime of the process or how long it
303 * can take to bring the process up and running -
304 * (depends on the IGuest::ExecuteProcessFlag_*). */
305 HGCMFunctionParameter timeout;
306
307} VBoxGuestCtrlHGCMMsgExecCmd;
308
309/**
310 * Injects input to a previously executed process via
311 * stdin.
312 */
313typedef struct _VBoxGuestCtrlHGCMMsgExecIn
314{
315 VBoxGuestHGCMCallInfo hdr;
316 /** Context ID. */
317 HGCMFunctionParameter context;
318 /** The process ID (PID) to send the input to. */
319 HGCMFunctionParameter pid;
320 /** Input flags (see IGuest::ProcessInputFlag_*). */
321 HGCMFunctionParameter flags;
322 /** Data buffer. */
323 HGCMFunctionParameter data;
324 /** Actual size of data (in bytes). */
325 HGCMFunctionParameter size;
326
327} VBoxGuestCtrlHGCMMsgExecIn;
328
329typedef struct _VBoxGuestCtrlHGCMMsgExecOut
330{
331 VBoxGuestHGCMCallInfo hdr;
332 /** Context ID. */
333 HGCMFunctionParameter context;
334 /** The process ID (PID). */
335 HGCMFunctionParameter pid;
336 /** The pipe handle ID (stdout/stderr). */
337 HGCMFunctionParameter handle;
338 /** Optional flags. */
339 HGCMFunctionParameter flags;
340 /** Data buffer. */
341 HGCMFunctionParameter data;
342
343} VBoxGuestCtrlHGCMMsgExecOut;
344
345typedef struct _VBoxGuestCtrlHGCMMsgExecStatus
346{
347 VBoxGuestHGCMCallInfo hdr;
348 /** Context ID. */
349 HGCMFunctionParameter context;
350 /** The process ID (PID). */
351 HGCMFunctionParameter pid;
352 /** The process status. */
353 HGCMFunctionParameter status;
354 /** Optional flags (based on status). */
355 HGCMFunctionParameter flags;
356 /** Optional data buffer (not used atm). */
357 HGCMFunctionParameter data;
358
359} VBoxGuestCtrlHGCMMsgExecStatus;
360
361typedef struct _VBoxGuestCtrlHGCMMsgExecStatusIn
362{
363 VBoxGuestHGCMCallInfo hdr;
364 /** Context ID. */
365 HGCMFunctionParameter context;
366 /** The process ID (PID). */
367 HGCMFunctionParameter pid;
368 /** Status of the operation. */
369 HGCMFunctionParameter status;
370 /** Optional flags. */
371 HGCMFunctionParameter flags;
372 /** Data written. */
373 HGCMFunctionParameter written;
374
375} VBoxGuestCtrlHGCMMsgExecStatusIn;
376#pragma pack ()
377
378/* Structure for buffering execution requests in the host service. */
379typedef struct _VBoxGuestCtrlParamBuffer
380{
381 uint32_t uMsg;
382 uint32_t uParmCount;
383 VBOXHGCMSVCPARM *pParms;
384} VBOXGUESTCTRPARAMBUFFER, *PVBOXGUESTCTRPARAMBUFFER;
385
386} /* namespace guestControl */
387
388#endif /* ___VBox_HostService_GuestControlService_h defined */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette