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