VirtualBox

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

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

Main/VBoxManage: Added ExecuteProcessStatus, update on todos.

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