VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestImpl.h@ 42105

Last change on this file since 42105 was 42105, checked in by vboxsync, 13 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 KB
Line 
1/** @file
2 * VirtualBox COM class implementation
3 */
4
5/*
6 * Copyright (C) 2006-2011 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
17#ifndef ____H_GUESTIMPL
18#define ____H_GUESTIMPL
19
20#include "VirtualBoxBase.h"
21#include <iprt/list.h>
22#include <iprt/time.h>
23#include <VBox/ostypes.h>
24
25#include "AdditionsFacilityImpl.h"
26#include "GuestCtrlImplPrivate.h"
27#include "GuestSessionImpl.h"
28#include "HGCM.h"
29#ifdef VBOX_WITH_GUEST_CONTROL
30# include <iprt/fs.h>
31# include <VBox/HostServices/GuestControlSvc.h>
32using namespace guestControl;
33#endif
34
35#ifdef VBOX_WITH_DRAG_AND_DROP
36class GuestDnD;
37#endif
38
39typedef enum
40{
41 GUESTSTATTYPE_CPUUSER = 0,
42 GUESTSTATTYPE_CPUKERNEL = 1,
43 GUESTSTATTYPE_CPUIDLE = 2,
44 GUESTSTATTYPE_MEMTOTAL = 3,
45 GUESTSTATTYPE_MEMFREE = 4,
46 GUESTSTATTYPE_MEMBALLOON = 5,
47 GUESTSTATTYPE_MEMCACHE = 6,
48 GUESTSTATTYPE_PAGETOTAL = 7,
49 GUESTSTATTYPE_PAGEFREE = 8,
50 GUESTSTATTYPE_MAX = 9
51} GUESTSTATTYPE;
52
53class Console;
54#ifdef VBOX_WITH_GUEST_CONTROL
55class Progress;
56#endif
57
58class ATL_NO_VTABLE Guest :
59 public VirtualBoxBase,
60 VBOX_SCRIPTABLE_IMPL(IGuest)
61{
62public:
63 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
64
65 DECLARE_NOT_AGGREGATABLE(Guest)
66
67 DECLARE_PROTECT_FINAL_CONSTRUCT()
68
69 BEGIN_COM_MAP(Guest)
70 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
71 END_COM_MAP()
72
73 DECLARE_EMPTY_CTOR_DTOR (Guest)
74
75 HRESULT FinalConstruct();
76 void FinalRelease();
77
78 // Public initializer/uninitializer for internal purposes only
79 HRESULT init (Console *aParent);
80 void uninit();
81
82 // IGuest properties
83 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
84 STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
85 STDMETHOD(COMGETTER(AdditionsVersion))(BSTR *a_pbstrAdditionsVersion);
86 STDMETHOD(COMGETTER(AdditionsRevision))(ULONG *a_puAdditionsRevision);
87 STDMETHOD(COMGETTER(Facilities)) (ComSafeArrayOut(IAdditionsFacility *, aFacilities));
88 STDMETHOD(COMGETTER(Sessions)) (ComSafeArrayOut(IGuestSession *, aSessions));
89 STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
90 STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
91 STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
92 STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
93
94 // IGuest methods
95 STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
96 STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
97 STDMETHOD(SetCredentials)(IN_BSTR aUsername, IN_BSTR aPassword,
98 IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
99 STDMETHOD(DragHGEnter)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
100 STDMETHOD(DragHGMove)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
101 STDMETHOD(DragHGLeave)(ULONG uScreenId);
102 STDMETHOD(DragHGDrop)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction);
103 STDMETHOD(DragHGPutData)(ULONG uScreenId, IN_BSTR strFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress);
104 STDMETHOD(DragGHPending)(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction);
105 STDMETHOD(DragGHDropped)(IN_BSTR strFormat, DragAndDropAction_T action, IProgress **ppProgress);
106 STDMETHOD(DragGHGetData)(ComSafeArrayOut(BYTE, data));
107 // Process execution
108 STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
109 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
110 IN_BSTR aUsername, IN_BSTR aPassword,
111 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
112 STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
113 STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
114 STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ExecuteProcessStatus_T *aStatus);
115 // File copying
116 STDMETHOD(CopyFromGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUsername, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
117 STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUsername, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
118 // Directory handling
119 STDMETHOD(DirectoryClose)(ULONG aHandle);
120 STDMETHOD(DirectoryCreate)(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, ULONG aMode, ULONG aFlags);
121#if 0
122 STDMETHOD(DirectoryExists)(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists);
123#endif
124 STDMETHOD(DirectoryOpen)(IN_BSTR aDirectory, IN_BSTR aFilter,
125 ULONG aFlags, IN_BSTR aUsername, IN_BSTR aPassword, ULONG *aHandle);
126 STDMETHOD(DirectoryRead)(ULONG aHandle, IGuestDirEntry **aDirEntry);
127 // File handling
128 STDMETHOD(FileExists)(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists);
129 STDMETHOD(FileQuerySize)(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, LONG64 *aSize);
130 // Misc stuff
131 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
132 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
133 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
134 STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
135 STDMETHOD(CreateSession)(IN_BSTR aUser, IN_BSTR aPassword, IN_BSTR aDomain, IN_BSTR aSessionName, IGuestSession **aGuestSession);
136
137 // Public methods that are not in IDL (only called internally).
138 void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
139 void setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures);
140 bool facilityIsActive(VBoxGuestFacilityType enmFacility);
141 void facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
142 void setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
143 void setSupportedFeatures(uint32_t aCaps);
144 HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
145 BOOL isPageFusionEnabled();
146 static HRESULT setErrorStatic(HRESULT aResultCode,
147 const Utf8Str &aText)
148 {
149 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
150 }
151
152# ifdef VBOX_WITH_GUEST_CONTROL
153 // Internal guest directory functions
154 int directoryCreateHandle(ULONG *puHandle, ULONG uPID, IN_BSTR aDirectory, IN_BSTR aFilter, ULONG uFlags);
155 HRESULT directoryCreateInternal(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword,
156 ULONG aMode, ULONG aFlags, int *pRC);
157 void directoryDestroyHandle(uint32_t uHandle);
158 HRESULT directoryExistsInternal(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists);
159 uint32_t directoryGetPID(uint32_t uHandle);
160 int directoryGetNextEntry(uint32_t uHandle, GuestProcessStreamBlock &streamBlock);
161 bool directoryHandleExists(uint32_t uHandle);
162 HRESULT directoryOpenInternal(IN_BSTR aDirectory, IN_BSTR aFilter,
163 ULONG aFlags,
164 IN_BSTR aUsername, IN_BSTR aPassword,
165 ULONG *aHandle, int *pRC);
166 HRESULT directoryQueryInfoInternal(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, PRTFSOBJINFO aObjInfo, RTFSOBJATTRADD enmAddAttribs, int *pRC);
167 // Internal guest execution functions
168 HRESULT executeAndWaitForTool(IN_BSTR aTool, IN_BSTR aDescription,
169 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
170 IN_BSTR aUsername, IN_BSTR aPassword,
171 ULONG uFlagsToAdd,
172 GuestCtrlStreamObjects *pObjStdOut, GuestCtrlStreamObjects *pObjStdErr,
173 IProgress **aProgress, ULONG *aPID);
174 HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
175 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
176 IN_BSTR aUsername, IN_BSTR aPassword,
177 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
178 HRESULT getProcessOutputInternal(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS,
179 LONG64 aSize, ComSafeArrayOut(BYTE, aData), int *pRC);
180 HRESULT executeSetResult(const char *pszCommand, const char *pszUser, ULONG ulTimeout, PCALLBACKDATAEXECSTATUS pExecStatus, ULONG *puPID);
181 int executeStreamQueryFsObjInfo(IN_BSTR aObjName,GuestProcessStreamBlock &streamBlock, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttribs);
182 int executeStreamDrain(ULONG aPID, ULONG ulFlags, GuestProcessStream *pStream);
183 int executeStreamGetNextBlock(ULONG ulPID, ULONG ulFlags, GuestProcessStream &stream, GuestProcessStreamBlock &streamBlock);
184 int executeStreamParseNextBlock(ULONG ulPID, ULONG ulFlags, GuestProcessStream &stream, GuestProcessStreamBlock &streamBlock);
185 HRESULT executeStreamParse(ULONG uPID, ULONG ulFlags, GuestCtrlStreamObjects &streamObjects);
186 HRESULT executeWaitForExit(ULONG uPID, ComPtr<IProgress> pProgress, ULONG uTimeoutMS);
187 // Internal guest file functions
188 HRESULT fileExistsInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists);
189 HRESULT fileQueryInfoInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, PRTFSOBJINFO aObjInfo, RTFSOBJATTRADD enmAddAttribs, int *pRC);
190 HRESULT fileQuerySizeInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, LONG64 *aSize);
191
192 // Guest control dispatcher.
193 /** Static callback for handling guest control notifications. */
194 static DECLCALLBACK(int) notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
195
196 // Internal tasks.
197 //extern struct GuestTask;
198 HRESULT taskCopyFileToGuest(GuestTask *aTask);
199 HRESULT taskCopyFileFromGuest(GuestTask *aTask);
200 HRESULT taskUpdateGuestAdditions(GuestTask *aTask);
201#endif
202 void enableVMMStatistics(BOOL aEnable) { mCollectVMMStats = aEnable; };
203
204public:
205 /** @name Public internal methods.
206 * @{ */
207 int sessionClose(ComObjPtr<GuestSession> pSession);
208 /** @} */
209
210private:
211
212#ifdef VBOX_WITH_GUEST_CONTROL
213 // Internal guest callback representation.
214 typedef struct VBOXGUESTCTRL_CALLBACK
215 {
216 eVBoxGuestCtrlCallbackType mType;
217 /** Pointer to user-supplied data. */
218 void *pvData;
219 /** Size of user-supplied data. */
220 uint32_t cbData;
221 /** The host PID. Needed for translating to
222 * a guest PID. */
223 uint32_t uHostPID;
224 /** Pointer to user-supplied IProgress. */
225 ComObjPtr<Progress> pProgress;
226 } VBOXGUESTCTRL_CALLBACK, *PVBOXGUESTCTRL_CALLBACK;
227 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK > CallbackMap;
228 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::iterator CallbackMapIter;
229 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::const_iterator CallbackMapIterConst;
230
231 int callbackAdd(const PVBOXGUESTCTRL_CALLBACK pCallbackData, uint32_t *puContextID);
232 int callbackAssignHostPID(uint32_t uContextID, uint32_t uHostPID);
233 void callbackDestroy(uint32_t uContextID);
234 void callbackRemove(uint32_t uContextID);
235 bool callbackExists(uint32_t uContextID);
236 void callbackFreeUserData(void *pvData);
237 uint32_t callbackGetHostPID(uint32_t uContextID);
238 int callbackGetUserData(uint32_t uContextID, eVBoxGuestCtrlCallbackType *pEnmType, void **ppvData, size_t *pcbData);
239 void* callbackGetUserDataMutableRaw(uint32_t uContextID, size_t *pcbData);
240 int callbackInit(PVBOXGUESTCTRL_CALLBACK pCallback, eVBoxGuestCtrlCallbackType enmType, ComPtr<Progress> pProgress);
241 bool callbackIsCanceled(uint32_t uContextID);
242 bool callbackIsComplete(uint32_t uContextID);
243 int callbackMoveForward(uint32_t uContextID, const char *pszMessage);
244 int callbackNotifyEx(uint32_t uContextID, int iRC, const char *pszMessage);
245 int callbackNotifyComplete(uint32_t uContextID);
246 int callbackNotifyAllForPID(uint32_t uGuestPID, int iRC, const char *pszMessage);
247 int callbackWaitForCompletion(uint32_t uContextID, LONG lStage, LONG lTimeout);
248
249 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
250 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
251 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
252 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
253
254 // Internal guest process representation.
255 typedef struct VBOXGUESTCTRL_PROCESS
256 {
257 /** The guest PID -- needed for controlling the actual guest
258 * process which has its own PID (generated by the guest OS). */
259 uint32_t mGuestPID;
260 /** The last reported process status. */
261 ExecuteProcessStatus_T mStatus;
262 /** The process execution flags. */
263 uint32_t mFlags;
264 /** The process' exit code. */
265 uint32_t mExitCode;
266 } VBOXGUESTCTRL_PROCESS, *PVBOXGUESTCTRL_PROCESS;
267 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS > GuestProcessMap;
268 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::iterator GuestProcessMapIter;
269 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::const_iterator GuestProcessMapIterConst;
270
271 uint32_t processGetGuestPID(uint32_t uHostPID);
272 int processGetStatus(uint32_t uHostPID, PVBOXGUESTCTRL_PROCESS pProcess, bool fRemove);
273 int processSetStatus(uint32_t uHostPID, uint32_t uGuestPID,
274 ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags);
275
276 // Internal guest directory representation.
277 typedef struct VBOXGUESTCTRL_DIRECTORY
278 {
279 Bstr mDirectory;
280 Bstr mFilter;
281 ULONG mFlags;
282 /** Associated host PID of started vbox_ls tool. */
283 ULONG mPID;
284 GuestProcessStream mStream;
285 } VBOXGUESTCTRL_DIRECTORY, *PVBOXGUESTCTRL_DIRECTORY;
286 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY > GuestDirectoryMap;
287 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY >::iterator GuestDirectoryMapIter;
288 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY >::const_iterator GuestDirectoryMapIterConst;
289
290 // Utility functions.
291 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
292
293 /*
294 * Handler for guest execution control notifications.
295 */
296 HRESULT setErrorCompletion(int rc);
297 HRESULT setErrorFromProgress(ComPtr<IProgress> pProgress);
298 HRESULT setErrorHGCM(int rc);
299# endif
300
301 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
302 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
303 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
304
305 typedef std::list <ComObjPtr<GuestSession> > GuestSessions;
306
307 struct Data
308 {
309 Data() : mAdditionsRunLevel(AdditionsRunLevelType_None)
310 , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
311 { }
312
313 Bstr mOSTypeId;
314 FacilityMap mFacilityMap;
315 AdditionsRunLevelType_T mAdditionsRunLevel;
316 uint32_t mAdditionsVersionFull;
317 Bstr mAdditionsVersionNew;
318 uint32_t mAdditionsRevision;
319 uint32_t mAdditionsFeatures;
320 Bstr mInterfaceVersion;
321 GuestSessions mGuestSessions;
322 };
323
324 ULONG mMemoryBalloonSize;
325 ULONG mStatUpdateInterval;
326 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
327 ULONG mGuestValidStats;
328 BOOL mCollectVMMStats;
329 BOOL mfPageFusionEnabled;
330
331 Console *mParent;
332 Data mData;
333
334# ifdef VBOX_WITH_GUEST_CONTROL
335 /** General extension callback for guest control. */
336 HGCMSVCEXTHANDLE mhExtCtrl;
337 /** Next upcoming context ID. */
338 volatile uint32_t mNextContextID;
339 /** Next upcoming host PID */
340 volatile uint32_t mNextHostPID;
341 /** Next upcoming directory handle ID. */
342 volatile uint32_t mNextDirectoryID;
343 CallbackMap mCallbackMap;
344 GuestDirectoryMap mGuestDirectoryMap;
345 GuestProcessMap mGuestProcessMap;
346# endif
347
348#ifdef VBOX_WITH_DRAG_AND_DROP
349 GuestDnD *m_pGuestDnD;
350 friend class GuestDnD;
351 friend class GuestDnDPrivate;
352#endif
353 static void staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
354 void updateStats(uint64_t iTick);
355 RTTIMERLR mStatTimer;
356 uint32_t mMagic;
357};
358#define GUEST_MAGIC 0xCEED2006u
359
360#endif // ____H_GUESTIMPL
361
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