VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h@ 37423

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

GuestCtrl: Added APIs for guest directory enumeration, guest file existence and copy from guest support, some API renaming/cleanup (work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1/* $Id: VBoxServiceInternal.h 37375 2011-06-08 10:51:26Z vboxsync $ */
2/** @file
3 * VBoxService - Guest Additions Services.
4 */
5
6/*
7 * Copyright (C) 2007-2011 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
18#ifndef ___VBoxServiceInternal_h
19#define ___VBoxServiceInternal_h
20
21#include <stdio.h>
22#ifdef RT_OS_WINDOWS
23# include <Windows.h>
24# include <process.h> /* Needed for file version information. */
25#endif
26
27#include <iprt/list.h>
28#include <iprt/critsect.h>
29
30#include <VBox/VBoxGuestLib.h>
31
32/**
33 * A service descriptor.
34 */
35typedef struct
36{
37 /** The short service name. */
38 const char *pszName;
39 /** The longer service name. */
40 const char *pszDescription;
41 /** The usage options stuff for the --help screen. */
42 const char *pszUsage;
43 /** The option descriptions for the --help screen. */
44 const char *pszOptions;
45
46 /**
47 * Called before parsing arguments.
48 * @returns VBox status code.
49 */
50 DECLCALLBACKMEMBER(int, pfnPreInit)(void);
51
52 /**
53 * Tries to parse the given command line option.
54 *
55 * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
56 * @param ppszShort If not NULL it points to the short option iterator. a short argument.
57 * If NULL examine argv[*pi].
58 * @param argc The argument count.
59 * @param argv The argument vector.
60 * @param pi The argument vector index. Update if any value(s) are eaten.
61 */
62 DECLCALLBACKMEMBER(int, pfnOption)(const char **ppszShort, int argc, char **argv, int *pi);
63
64 /**
65 * Called before parsing arguments.
66 * @returns VBox status code.
67 */
68 DECLCALLBACKMEMBER(int, pfnInit)(void);
69
70 /** Called from the worker thread.
71 *
72 * @returns VBox status code.
73 * @retval VINF_SUCCESS if exitting because *pfTerminate was set.
74 * @param pfTerminate Pointer to a per service termination flag to check
75 * before and after blocking.
76 */
77 DECLCALLBACKMEMBER(int, pfnWorker)(bool volatile *pfTerminate);
78
79 /**
80 * Stop an service.
81 */
82 DECLCALLBACKMEMBER(void, pfnStop)(void);
83
84 /**
85 * Does termination cleanups.
86 *
87 * @remarks This may be called even if pfnInit hasn't been called!
88 */
89 DECLCALLBACKMEMBER(void, pfnTerm)(void);
90} VBOXSERVICE;
91/** Pointer to a VBOXSERVICE. */
92typedef VBOXSERVICE *PVBOXSERVICE;
93/** Pointer to a const VBOXSERVICE. */
94typedef VBOXSERVICE const *PCVBOXSERVICE;
95
96/** The service name.
97 * @note Used on windows to name the service as well as the global mutex. */
98#define VBOXSERVICE_NAME "VBoxService"
99
100#ifdef RT_OS_WINDOWS
101/** The friendly service name. */
102# define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service"
103/** The service description (only W2K+ atm) */
104# define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems."
105/** The following constant may be defined by including NtStatus.h. */
106# define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
107#endif /* RT_OS_WINDOWS */
108
109#ifdef VBOX_WITH_GUEST_CONTROL
110typedef enum VBOXSERVICECTRLTHREADDATATYPE
111{
112 kVBoxServiceCtrlThreadDataUnknown = 0,
113 kVBoxServiceCtrlThreadDataExec
114} VBOXSERVICECTRLTHREADDATATYPE;
115
116typedef enum VBOXSERVICECTRLPIPEID
117{
118 VBOXSERVICECTRLPIPEID_STDIN_ERROR = 0,
119 VBOXSERVICECTRLPIPEID_STDIN_WRITABLE,
120 VBOXSERVICECTRLPIPEID_STDIN_INPUT_NOTIFY,
121 VBOXSERVICECTRLPIPEID_STDOUT,
122 VBOXSERVICECTRLPIPEID_STDERR
123} VBOXSERVICECTRLPIPEID;
124
125/**
126 * Structure for holding buffered pipe data.
127 */
128typedef struct
129{
130 /** The data buffer. */
131 uint8_t *pbData;
132 /** The amount of allocated buffer space. */
133 uint32_t cbAllocated;
134 /** The actual used/occupied buffer space. */
135 uint32_t cbSize;
136 /** Helper variable for keeping track of what
137 * already was processed and what not. */
138 uint32_t cbOffset;
139 /** Critical section protecting this buffer structure. */
140 RTCRITSECT CritSect;
141 /** Flag indicating whether this pipe buffer accepts new
142 * data to be written to or not. If not enabled, already
143 * (allocated) buffered data still can be read out. */
144 bool fEnabled;
145 /** Set if it's necessary to write to the notification pipe. */
146 bool fNeedNotification;
147 /** Set if the pipe needs to be closed after the next read/write. */
148 bool fPendingClose;
149 /** The notification pipe associated with this buffer.
150 * This is NIL_RTPIPE for output pipes. */
151 RTPIPE hNotificationPipeW;
152 /** The other end of hNotificationPipeW. */
153 RTPIPE hNotificationPipeR;
154 /** The event semaphore for getting notified whether something
155 * has changed, e.g. written or read from this buffer. */
156 RTSEMEVENT hEventSem;
157} VBOXSERVICECTRLEXECPIPEBUF;
158/** Pointer to buffered pipe data. */
159typedef VBOXSERVICECTRLEXECPIPEBUF *PVBOXSERVICECTRLEXECPIPEBUF;
160
161/**
162 * Structure for holding guest exection relevant data.
163 */
164typedef struct
165{
166 uint32_t uPID;
167 char *pszCmd;
168 uint32_t uFlags;
169 char **papszArgs;
170 uint32_t uNumArgs;
171 char **papszEnv;
172 uint32_t uNumEnvVars;
173 char *pszUser;
174 char *pszPassword;
175 uint32_t uTimeLimitMS;
176
177 RTPIPE pipeStdInW;
178 VBOXSERVICECTRLEXECPIPEBUF stdIn;
179 VBOXSERVICECTRLEXECPIPEBUF stdOut;
180 VBOXSERVICECTRLEXECPIPEBUF stdErr;
181
182} VBOXSERVICECTRLTHREADDATAEXEC;
183/** Pointer to thread data. */
184typedef VBOXSERVICECTRLTHREADDATAEXEC *PVBOXSERVICECTRLTHREADDATAEXEC;
185
186/* Structure for holding thread relevant data. */
187typedef struct VBOXSERVICECTRLTHREAD
188{
189 /** Node. */
190 RTLISTNODE Node;
191 /** The worker thread. */
192 RTTHREAD Thread;
193 /** Shutdown indicator. */
194 bool volatile fShutdown;
195 /** Indicator set by the service thread exiting. */
196 bool volatile fStopped;
197 /** Whether the service was started or not. */
198 bool fStarted;
199 /** Client ID. */
200 uint32_t uClientID;
201 /** Context ID. */
202 uint32_t uContextID;
203 /** Type of thread. See VBOXSERVICECTRLTHREADDATATYPE for more info. */
204 VBOXSERVICECTRLTHREADDATATYPE enmType;
205 /** Pointer to actual thread data, depending on enmType. */
206 void *pvData;
207} VBOXSERVICECTRLTHREAD;
208/** Pointer to thread data. */
209typedef VBOXSERVICECTRLTHREAD *PVBOXSERVICECTRLTHREAD;
210#endif /* VBOX_WITH_GUEST_CONTROL */
211#ifdef VBOX_WITH_GUEST_PROPS
212
213/**
214 * A guest property cache.
215 */
216typedef struct VBOXSERVICEVEPROPCACHE
217{
218 /** The client ID for HGCM communication. */
219 uint32_t uClientID;
220 /** Head in a list of VBOXSERVICEVEPROPCACHEENTRY nodes. */
221 RTLISTNODE NodeHead;
222 /** Critical section for thread-safe use. */
223 RTCRITSECT CritSect;
224} VBOXSERVICEVEPROPCACHE;
225/** Pointer to a guest property cache. */
226typedef VBOXSERVICEVEPROPCACHE *PVBOXSERVICEVEPROPCACHE;
227
228/**
229 * An entry in the property cache (VBOXSERVICEVEPROPCACHE).
230 */
231typedef struct VBOXSERVICEVEPROPCACHEENTRY
232{
233 /** Node to successor.
234 * @todo r=bird: This is not really the node to the successor, but
235 * rather the OUR node in the list. If it helps, remember that
236 * its a doubly linked list. */
237 RTLISTNODE NodeSucc;
238 /** Name (and full path) of guest property. */
239 char *pszName;
240 /** The last value stored (for reference). */
241 char *pszValue;
242 /** Reset value to write if property is temporary. If NULL, it will be
243 * deleted. */
244 char *pszValueReset;
245 /** Flags. */
246 uint32_t fFlags;
247} VBOXSERVICEVEPROPCACHEENTRY;
248/** Pointer to a cached guest property. */
249typedef VBOXSERVICEVEPROPCACHEENTRY *PVBOXSERVICEVEPROPCACHEENTRY;
250
251#endif /* VBOX_WITH_GUEST_PROPS */
252
253RT_C_DECLS_BEGIN
254
255extern char *g_pszProgName;
256extern int g_cVerbosity;
257extern uint32_t g_DefaultInterval;
258extern VBOXSERVICE g_TimeSync;
259extern VBOXSERVICE g_Clipboard;
260extern VBOXSERVICE g_Control;
261extern VBOXSERVICE g_VMInfo;
262extern VBOXSERVICE g_CpuHotPlug;
263#ifdef VBOXSERVICE_MANAGEMENT
264extern VBOXSERVICE g_MemBalloon;
265extern VBOXSERVICE g_VMStatistics;
266#endif
267#ifdef VBOX_WITH_PAGE_SHARING
268extern VBOXSERVICE g_PageSharing;
269#endif
270#ifdef VBOX_WITH_SHARED_FOLDERS
271extern VBOXSERVICE g_AutoMount;
272#endif
273
274extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...);
275extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...);
276extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);
277extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
278 uint32_t u32Min, uint32_t u32Max);
279extern int VBoxServiceStartServices(void);
280extern int VBoxServiceStopServices(void);
281extern void VBoxServiceMainWait(void);
282extern int VBoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus);
283#ifdef RT_OS_WINDOWS
284extern RTEXITCODE VBoxServiceWinInstall(void);
285extern RTEXITCODE VBoxServiceWinUninstall(void);
286extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void);
287extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint);
288#endif
289
290#ifdef VBOXSERVICE_TOOLBOX
291extern bool VBoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit);
292#endif
293
294#ifdef RT_OS_WINDOWS
295# ifdef VBOX_WITH_GUEST_PROPS
296extern int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList);
297extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
298# endif /* VBOX_WITH_GUEST_PROPS */
299#endif /* RT_OS_WINDOWS */
300
301#ifdef VBOX_WITH_GUEST_CONTROL
302extern int VBoxServiceGCtrlDirClose(uint32_t u32ClientId, uint32_t uNumParms);
303extern int VBoxServiceGCtrlDirOpen(uint32_t u32ClientId, uint32_t uNumParms);
304extern int VBoxServiceGCtrlDirRead(uint32_t u32ClientId, uint32_t uNumParms);
305
306extern int VBoxServiceControlExecHandleCmdStartProcess(uint32_t u32ClientId, uint32_t uNumParms);
307extern int VBoxServiceControlExecHandleCmdSetInput(uint32_t u32ClientId, uint32_t uNumParms, size_t cbMaxBufSize);
308extern int VBoxServiceControlExecHandleCmdGetOutput(uint32_t u32ClientId, uint32_t uNumParms);
309extern int VBoxServiceControlExecProcess(uint32_t uContext, const char *pszCmd, uint32_t uFlags,
310 const char *pszArgs, uint32_t uNumArgs,
311 const char *pszEnv, uint32_t cbEnv, uint32_t uNumEnvVars,
312 const char *pszUser, const char *pszPassword, uint32_t uTimeLimitMS);
313extern void VBoxServiceControlExecThreadDestroy(PVBOXSERVICECTRLTHREADDATAEXEC pThread);
314#endif /* VBOX_WITH_GUEST_CONTROL */
315
316#ifdef VBOXSERVICE_MANAGEMENT
317extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
318#endif
319#if defined(VBOX_WITH_PAGE_SHARING) && defined(RT_OS_WINDOWS)
320extern RTEXITCODE VBoxServicePageSharingInitFork(void);
321#endif
322
323RT_C_DECLS_END
324
325#endif
326
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