VirtualBox

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

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

GuestCtrl: Removed dead code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 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
34typedef 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
48class Console;
49#ifdef VBOX_WITH_GUEST_CONTROL
50class Progress;
51#endif
52
53class ATL_NO_VTABLE Guest :
54 public VirtualBoxBase,
55 VBOX_SCRIPTABLE_IMPL(IGuest)
56{
57public:
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 int executeStreamGetNextBlock(ULONG aPID, GuestProcessStream &stream, GuestProcessStreamBlock &streamBlock);
164 HRESULT executeStreamParse(ULONG aPID, GuestCtrlStreamObjects &streamObjects);
165 HRESULT executeWaitForStatusChange(ULONG uPID, ULONG uTimeoutMS, ExecuteProcessStatus_T *pRetStatus, ULONG *puRetExitCode);
166 // Internal guest file functions
167 HRESULT fileExistsInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists);
168 HRESULT fileQueryInfoInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, PRTFSOBJINFO aObjInfo, RTFSOBJATTRADD enmAddAttribs, int *pRC);
169 HRESULT fileQuerySizeInternal(IN_BSTR aFile, IN_BSTR aUsername, IN_BSTR aPassword, LONG64 *aSize);
170
171 // Guest control dispatcher.
172 /** Static callback for handling guest notifications. */
173 static DECLCALLBACK(int) notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
174
175 // Internal tasks.
176 //extern struct GuestTask;
177 HRESULT taskCopyFileToGuest(GuestTask *aTask);
178 HRESULT taskCopyFileFromGuest(GuestTask *aTask);
179 HRESULT taskUpdateGuestAdditions(GuestTask *aTask);
180# endif
181
182private:
183
184#ifdef VBOX_WITH_GUEST_CONTROL
185 // Internal guest callback representation.
186 typedef struct VBOXGUESTCTRL_CALLBACK
187 {
188 eVBoxGuestCtrlCallbackType mType;
189 /** Pointer to user-supplied data. */
190 void *pvData;
191 /** Size of user-supplied data. */
192 uint32_t cbData;
193 /** Pointer to user-supplied IProgress. */
194 ComObjPtr<Progress> pProgress;
195 } VBOXGUESTCTRL_CALLBACK, *PVBOXGUESTCTRL_CALLBACK;
196 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK > CallbackMap;
197 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::iterator CallbackMapIter;
198 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::const_iterator CallbackMapIterConst;
199
200 int callbackAdd(const PVBOXGUESTCTRL_CALLBACK pCallbackData, uint32_t *puContextID);
201 void callbackDestroy(uint32_t uContextID);
202 bool callbackExists(uint32_t uContextID);
203 void callbackFreeUserData(void *pvData);
204 int callbackGetUserData(uint32_t uContextID, eVBoxGuestCtrlCallbackType *pEnmType, void **ppvData, size_t *pcbData);
205 void* callbackGetUserDataMutableRaw(uint32_t uContextID, size_t *pcbData);
206 int callbackInit(PVBOXGUESTCTRL_CALLBACK pCallback, eVBoxGuestCtrlCallbackType enmType, ComPtr<Progress> pProgress);
207 bool callbackIsCanceled(uint32_t uContextID);
208 bool callbackIsComplete(uint32_t uContextID);
209 int callbackMoveForward(uint32_t uContextID, const char *pszMessage);
210 int callbackNotifyEx(uint32_t uContextID, int iRC, const char *pszMessage);
211 int callbackNotifyComplete(uint32_t uContextID);
212 int callbackNotifyAllForPID(uint32_t uPID, int iRC, const char *pszMessage);
213 int callbackWaitForCompletion(uint32_t uContextID, LONG lStage, LONG lTimeout);
214
215 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
216 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
217 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
218 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
219
220 // Internal guest process representation.
221 typedef struct VBOXGUESTCTRL_PROCESS
222 {
223 ExecuteProcessStatus_T mStatus;
224 uint32_t mFlags;
225 uint32_t mExitCode;
226 } VBOXGUESTCTRL_PROCESS, *PVBOXGUESTCTRL_PROCESS;
227 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS > GuestProcessMap;
228 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::iterator GuestProcessMapIter;
229 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::const_iterator GuestProcessMapIterConst;
230
231 int processAdd(uint32_t u32PID, ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags);
232 int processGetByPID(uint32_t u32PID, PVBOXGUESTCTRL_PROCESS pProcess);
233 int processSetStatus(uint32_t u32PID, ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags);
234
235 // Internal guest directory representation.
236 typedef struct VBOXGUESTCTRL_DIRECTORY
237 {
238 Bstr mDirectory;
239 Bstr mFilter;
240 ULONG mFlags;
241 /** Associated PID of started vbox_ls tool. */
242 ULONG mPID;
243 GuestProcessStream mStream;
244#if 0
245 /** Next enetry in our stream objects vector
246 * to process. */
247 uint32_t mNextEntry;
248 /** The guest stream object containing all */
249 GuestCtrlStreamObjects mStream;
250#endif
251 } VBOXGUESTCTRL_DIRECTORY, *PVBOXGUESTCTRL_DIRECTORY;
252 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY > GuestDirectoryMap;
253 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY >::iterator GuestDirectoryMapIter;
254 typedef std::map< uint32_t, VBOXGUESTCTRL_DIRECTORY >::const_iterator GuestDirectoryMapIterConst;
255
256 // Utility functions.
257 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
258
259 /*
260 * Handler for guest execution control notifications.
261 */
262 HRESULT handleErrorCompletion(int rc);
263 HRESULT handleErrorHGCM(int rc);
264# endif
265
266 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
267 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
268 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
269
270 struct Data
271 {
272 Data() : mAdditionsRunLevel (AdditionsRunLevelType_None) {}
273
274 Bstr mOSTypeId;
275 FacilityMap mFacilityMap;
276 AdditionsRunLevelType_T mAdditionsRunLevel;
277 Bstr mAdditionsVersion;
278 Bstr mInterfaceVersion;
279 };
280
281 ULONG mMemoryBalloonSize;
282 ULONG mStatUpdateInterval;
283 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
284 BOOL mfPageFusionEnabled;
285
286 Console *mParent;
287 Data mData;
288
289# ifdef VBOX_WITH_GUEST_CONTROL
290 /** General extension callback for guest control. */
291 HGCMSVCEXTHANDLE mhExtCtrl;
292 /** Next upcoming context ID. */
293 volatile uint32_t mNextContextID;
294 /** Next upcoming directory handle ID. */
295 volatile uint32_t mNextDirectoryID;
296 CallbackMap mCallbackMap;
297 GuestDirectoryMap mGuestDirectoryMap;
298 GuestProcessMap mGuestProcessMap;
299# endif
300};
301
302#endif // ____H_GUESTIMPL
303/* 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