VirtualBox

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

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

Comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 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
84/**
85 * Input status, reported by the client.
86 */
87enum eInputStatus
88{
89 /** Input is in an undefined state. */
90 INPUT_STS_UNDEFINED = 0,
91 /** Input was written (partially, see cbProcessed). */
92 INPUT_STS_WRITTEN = 1,
93 /** Input failed with an error (see flags for rc). */
94 INPUT_STS_ERROR = 20,
95 /** Process has abandoned / terminated input handling. */
96 INPUT_STS_TERMINATED = 21,
97 /** Too much input data. */
98 INPUT_STS_OVERFLOW = 30
99};
100
101typedef struct _VBoxGuestCtrlCallbackHeader
102{
103 /** Magic number to identify the structure. */
104 uint32_t u32Magic;
105 /** Context ID to identify callback data. */
106 uint32_t u32ContextID;
107} CALLBACKHEADER, *PCALLBACKHEADER;
108
109/**
110 * Data structure to pass to the service extension callback. We use this to
111 * notify the host of changes to properties.
112 */
113typedef struct _VBoxGuestCtrlCallbackDataExecStatus
114{
115 /** Callback data header. */
116 CALLBACKHEADER hdr;
117 /** The process ID (PID). */
118 uint32_t u32PID;
119 /* The process status. */
120 uint32_t u32Status;
121 /** Optional flags, varies, based on u32Status. */
122 uint32_t u32Flags;
123 /** Optional data buffer (not used atm). */
124 void *pvData;
125 /** Size of optional data buffer (not used atm). */
126 uint32_t cbData;
127} CALLBACKDATAEXECSTATUS, *PCALLBACKDATAEXECSTATUS;
128
129typedef struct _VBoxGuestCtrlCallbackDataExecOut
130{
131 /** Callback data header. */
132 CALLBACKHEADER hdr;
133 /** The process ID (PID). */
134 uint32_t u32PID;
135 /* The handle ID (stdout/stderr). */
136 uint32_t u32HandleId;
137 /** Optional flags (not used atm). */
138 uint32_t u32Flags;
139 /** Optional data buffer. */
140 void *pvData;
141 /** Size (in bytes) of optional data buffer. */
142 uint32_t cbData;
143} CALLBACKDATAEXECOUT, *PCALLBACKDATAEXECOUT;
144
145typedef struct _VBoxGuestCtrlCallbackDataExecInStatus
146{
147 /** Callback data header. */
148 CALLBACKHEADER hdr;
149 /** The process ID (PID). */
150 uint32_t u32PID;
151 /** Current input status. */
152 uint32_t u32Status;
153 /** Optional flags. */
154 uint32_t u32Flags;
155 /** Size (in bytes) of processed input data. */
156 uint32_t cbProcessed;
157} CALLBACKDATAEXECINSTATUS, *PCALLBACKDATAEXECINSTATUS;
158
159typedef struct _VBoxGuestCtrlCallbackDataClientDisconnected
160{
161 /** Callback data header. */
162 CALLBACKHEADER hdr;
163} CALLBACKDATACLIENTDISCONNECTED, *PCALLBACKDATACLIENTDISCONNECTED;
164
165enum
166{
167 /** Magic number for sanity checking the CALLBACKDATACLIENTDISCONNECTED structure. */
168 CALLBACKDATAMAGICCLIENTDISCONNECTED = 0x08041984,
169 /** Magic number for sanity checking the CALLBACKDATAEXECSTATUS structure. */
170 CALLBACKDATAMAGICEXECSTATUS = 0x26011982,
171 /** Magic number for sanity checking the CALLBACKDATAEXECOUT structure. */
172 CALLBACKDATAMAGICEXECOUT = 0x11061949,
173 /** Magic number for sanity checking the CALLBACKDATAEXECIN structure. */
174 CALLBACKDATAMAGICEXECINSTATUS = 0x19091951
175};
176
177enum eVBoxGuestCtrlCallbackType
178{
179 VBOXGUESTCTRLCALLBACKTYPE_UNKNOWN = 0,
180 VBOXGUESTCTRLCALLBACKTYPE_EXEC_START = 1,
181 VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT = 2,
182 VBOXGUESTCTRLCALLBACKTYPE_EXEC_INPUT_STATUS = 3
183};
184
185/**
186 * The service functions which are callable by host.
187 */
188enum eHostFn
189{
190 /**
191 * The host asks the client to cancel all pending waits and exit.
192 */
193 HOST_CANCEL_PENDING_WAITS = 0,
194 /**
195 * The host wants to execute something in the guest. This can be a command line
196 * or starting a program.
197 */
198 HOST_EXEC_CMD = 100,
199 /**
200 * Sends input data for stdin to a running process executed by HOST_EXEC_CMD.
201 */
202 HOST_EXEC_SET_INPUT = 101,
203 /**
204 * Gets the current status of a running process, e.g.
205 * new data on stdout/stderr, process terminated etc.
206 */
207 HOST_EXEC_GET_OUTPUT = 102
208};
209
210/**
211 * The service functions which are called by guest. The numbers may not change,
212 * so we hardcode them.
213 */
214enum eGuestFn
215{
216 /**
217 * Guest waits for a new message the host wants to process on the guest side.
218 * This is a blocking call and can be deferred.
219 */
220 GUEST_GET_HOST_MSG = 1,
221 /**
222 * Guest asks the host to cancel all pending waits the guest itself waits on.
223 * This becomes necessary when the guest wants to quit but still waits for
224 * commands from the host.
225 */
226 GUEST_CANCEL_PENDING_WAITS = 2,
227 /**
228 * Guest disconnected (terminated normally or due to a crash HGCM
229 * detected when calling service::clientDisconnect().
230 */
231 GUEST_DISCONNECTED = 3,
232 /**
233 * Guests sends output from an executed process.
234 */
235 GUEST_EXEC_SEND_OUTPUT = 100,
236 /**
237 * Guest sends a status update of an executed process to the host.
238 */
239 GUEST_EXEC_SEND_STATUS = 101,
240 /**
241 * Guests sends an input status notification to the host.
242 */
243 GUEST_EXEC_SEND_INPUT_STATUS = 102
244};
245
246/*
247 * HGCM parameter structures.
248 */
249#pragma pack (1)
250typedef struct _VBoxGuestCtrlHGCMMsgType
251{
252 VBoxGuestHGCMCallInfo hdr;
253
254 /**
255 * The returned command the host wants to
256 * run on the guest.
257 */
258 HGCMFunctionParameter msg; /* OUT uint32_t */
259 /** Number of parameters the message needs. */
260 HGCMFunctionParameter num_parms; /* OUT uint32_t */
261
262} VBoxGuestCtrlHGCMMsgType;
263
264/**
265 * Asks the guest control host service to cancel all pending
266 * (outstanding) waits which were not processed yet. This is
267 * handy for a graceful shutdown.
268 */
269typedef struct _VBoxGuestCtrlHGCMMsgCancelPendingWaits
270{
271 VBoxGuestHGCMCallInfo hdr;
272} VBoxGuestCtrlHGCMMsgCancelPendingWaits;
273
274/**
275 * Executes a command inside the guest.
276 */
277typedef struct _VBoxGuestCtrlHGCMMsgExecCmd
278{
279 VBoxGuestHGCMCallInfo hdr;
280 /** Context ID. */
281 HGCMFunctionParameter context;
282 /** The command to execute on the guest. */
283 HGCMFunctionParameter cmd;
284 /** Execution flags (see IGuest::ExecuteProcessFlag_*). */
285 HGCMFunctionParameter flags;
286 /** Number of arguments. */
287 HGCMFunctionParameter num_args;
288 /** The actual arguments. */
289 HGCMFunctionParameter args;
290 /** Number of environment value pairs. */
291 HGCMFunctionParameter num_env;
292 /** Size (in bytes) of environment block, including terminating zeros. */
293 HGCMFunctionParameter cb_env;
294 /** The actual environment block. */
295 HGCMFunctionParameter env;
296 /** The user name to run the executed command under. */
297 HGCMFunctionParameter username;
298 /** The user's password. */
299 HGCMFunctionParameter password;
300 /** Timeout (in msec) which either specifies the
301 * overall lifetime of the process or how long it
302 * can take to bring the process up and running -
303 * (depends on the IGuest::ExecuteProcessFlag_*). */
304 HGCMFunctionParameter timeout;
305
306} VBoxGuestCtrlHGCMMsgExecCmd;
307
308/**
309 * Injects input to a previously executed process via
310 * stdin.
311 */
312typedef struct _VBoxGuestCtrlHGCMMsgExecIn
313{
314 VBoxGuestHGCMCallInfo hdr;
315 /** Context ID. */
316 HGCMFunctionParameter context;
317 /** The process ID (PID) to send the input to. */
318 HGCMFunctionParameter pid;
319 /** Input flags (see IGuest::ProcessInputFlag_*). */
320 HGCMFunctionParameter flags;
321 /** Data buffer. */
322 HGCMFunctionParameter data;
323 /** Actual size of data (in bytes). */
324 HGCMFunctionParameter size;
325
326} VBoxGuestCtrlHGCMMsgExecIn;
327
328typedef struct _VBoxGuestCtrlHGCMMsgExecOut
329{
330 VBoxGuestHGCMCallInfo hdr;
331 /** Context ID. */
332 HGCMFunctionParameter context;
333 /** The process ID (PID). */
334 HGCMFunctionParameter pid;
335 /** The pipe handle ID (stdout/stderr). */
336 HGCMFunctionParameter handle;
337 /** Optional flags. */
338 HGCMFunctionParameter flags;
339 /** Data buffer. */
340 HGCMFunctionParameter data;
341
342} VBoxGuestCtrlHGCMMsgExecOut;
343
344typedef struct _VBoxGuestCtrlHGCMMsgExecStatus
345{
346 VBoxGuestHGCMCallInfo hdr;
347 /** Context ID. */
348 HGCMFunctionParameter context;
349 /** The process ID (PID). */
350 HGCMFunctionParameter pid;
351 /** The process status. */
352 HGCMFunctionParameter status;
353 /** Optional flags (based on status). */
354 HGCMFunctionParameter flags;
355 /** Optional data buffer (not used atm). */
356 HGCMFunctionParameter data;
357
358} VBoxGuestCtrlHGCMMsgExecStatus;
359
360typedef struct _VBoxGuestCtrlHGCMMsgExecStatusIn
361{
362 VBoxGuestHGCMCallInfo hdr;
363 /** Context ID. */
364 HGCMFunctionParameter context;
365 /** The process ID (PID). */
366 HGCMFunctionParameter pid;
367 /** Status of the operation. */
368 HGCMFunctionParameter status;
369 /** Optional flags. */
370 HGCMFunctionParameter flags;
371 /** Data written. */
372 HGCMFunctionParameter written;
373
374} VBoxGuestCtrlHGCMMsgExecStatusIn;
375#pragma pack ()
376
377/* Structure for buffering execution requests in the host service. */
378typedef struct _VBoxGuestCtrlParamBuffer
379{
380 uint32_t uMsg;
381 uint32_t uParmCount;
382 VBOXHGCMSVCPARM *pParms;
383} VBOXGUESTCTRPARAMBUFFER, *PVBOXGUESTCTRPARAMBUFFER;
384
385} /* namespace guestControl */
386
387#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