VirtualBox

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

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

Main/Metrics: Guests now push collected metrics to VBoxSVC instead of being polled (#6029)

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