VirtualBox

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

Last change on this file since 38038 was 37863, checked in by vboxsync, 14 years ago

Main: Add interface for IGuest::FileQuerySize().

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 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#ifdef VBOX_WITH_GUEST_CONTROL
27# include <VBox/HostServices/GuestControlSvc.h>
28# include "HGCM.h"
29using namespace guestControl;
30#endif
31
32typedef enum
33{
34 GUESTSTATTYPE_CPUUSER = 0,
35 GUESTSTATTYPE_CPUKERNEL = 1,
36 GUESTSTATTYPE_CPUIDLE = 2,
37 GUESTSTATTYPE_MEMTOTAL = 3,
38 GUESTSTATTYPE_MEMFREE = 4,
39 GUESTSTATTYPE_MEMBALLOON = 5,
40 GUESTSTATTYPE_MEMCACHE = 6,
41 GUESTSTATTYPE_PAGETOTAL = 7,
42 GUESTSTATTYPE_PAGEFREE = 8,
43 GUESTSTATTYPE_MAX = 9
44} GUESTSTATTYPE;
45
46class Console;
47#ifdef VBOX_WITH_GUEST_CONTROL
48class Progress;
49#endif
50
51class ATL_NO_VTABLE Guest :
52 public VirtualBoxBase,
53 VBOX_SCRIPTABLE_IMPL(IGuest)
54{
55public:
56 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
57
58 DECLARE_NOT_AGGREGATABLE(Guest)
59
60 DECLARE_PROTECT_FINAL_CONSTRUCT()
61
62 BEGIN_COM_MAP(Guest)
63 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
64 END_COM_MAP()
65
66 DECLARE_EMPTY_CTOR_DTOR (Guest)
67
68 HRESULT FinalConstruct();
69 void FinalRelease();
70
71 // Public initializer/uninitializer for internal purposes only
72 HRESULT init (Console *aParent);
73 void uninit();
74
75 // IGuest properties
76 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
77 STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
78 STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
79 STDMETHOD(COMGETTER(Facilities)) (ComSafeArrayOut(IAdditionsFacility*, aFacilities));
80 STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
81 STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
82 STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
83 STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
84
85 // IGuest methods
86 STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
87 STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
88 STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
89 IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
90 // Process execution
91 STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
92 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
93 IN_BSTR aUserName, IN_BSTR aPassword,
94 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
95 STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
96 STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
97 STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ExecuteProcessStatus_T *aStatus);
98 // File copying
99 STDMETHOD(CopyFromGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
100 STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
101 // Directory handling
102 STDMETHOD(DirectoryClose)(ULONG aHandle);
103 STDMETHOD(DirectoryCreate)(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aMode, ULONG aFlags);
104 STDMETHOD(DirectoryOpen)(IN_BSTR aDirectory, IN_BSTR aFilter,
105 ULONG aFlags, IN_BSTR aUserName, IN_BSTR aPassword, ULONG *aHandle);
106 STDMETHOD(DirectoryRead)(ULONG aHandle, IGuestDirEntry **aDirEntry);
107 // File handling
108 STDMETHOD(FileExists)(IN_BSTR aFile, IN_BSTR aUserName, IN_BSTR aPassword, BOOL *aExists);
109 STDMETHOD(FileQuerySize)(IN_BSTR aFile, IN_BSTR aUserName, IN_BSTR aPassword, LONG64 *aSize);
110 // Misc stuff
111 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
112 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
113 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
114 STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
115
116 // Public methods that are not in IDL (only called internally).
117 HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
118 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
119 IN_BSTR aUserName, IN_BSTR aPassword,
120 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
121 HRESULT directoryCreateInternal(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword,
122 ULONG aMode, ULONG aFlags, int *pRC);
123 void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
124 void setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision);
125 bool facilityIsActive(VBoxGuestFacilityType enmFacility);
126 HRESULT facilityUpdate(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus);
127 void setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags);
128 void setSupportedFeatures(uint32_t aCaps);
129 HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
130 BOOL isPageFusionEnabled();
131# ifdef VBOX_WITH_GUEST_CONTROL
132 /** Static callback for handling guest notifications. */
133 static DECLCALLBACK(int) notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
134# endif
135 static HRESULT setErrorStatic(HRESULT aResultCode,
136 const Utf8Str &aText)
137 {
138 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
139 }
140
141private:
142#ifdef VBOX_WITH_GUEST_CONTROL
143 // Internal tasks.
144 struct TaskGuest; /* Worker thread helper. */
145 HRESULT taskCopyFileToGuest(TaskGuest *aTask);
146 HRESULT taskCopyFileFromGuest(TaskGuest *aTask);
147 HRESULT taskUpdateGuestAdditions(TaskGuest *aTask);
148
149 // Internal guest callback representation.
150 typedef struct VBOXGUESTCTRL_CALLBACK
151 {
152 eVBoxGuestCtrlCallbackType mType;
153 /** Pointer to user-supplied data. */
154 void *pvData;
155 /** Size of user-supplied data. */
156 uint32_t cbData;
157 /** Pointer to user-supplied IProgress. */
158 ComObjPtr<Progress> pProgress;
159 } VBOXGUESTCTRL_CALLBACK, *PVBOXGUESTCTRL_CALLBACK;
160 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK > CallbackMap;
161 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::iterator CallbackMapIter;
162 typedef std::map< uint32_t, VBOXGUESTCTRL_CALLBACK >::const_iterator CallbackMapIterConst;
163
164 int callbackAdd(const PVBOXGUESTCTRL_CALLBACK pCallbackData, uint32_t *puContextID);
165 void callbackDestroy(uint32_t uContextID);
166 bool callbackExists(uint32_t uContextID);
167 void callbackFreeUserData(void *pvData);
168 int callbackGetUserData(uint32_t uContextID, eVBoxGuestCtrlCallbackType *pEnmType, void **ppvData, size_t *pcbData);
169 void* callbackGetUserDataMutableRaw(uint32_t uContextID, size_t *pcbData);
170 bool callbackIsCanceled(uint32_t uContextID);
171 bool callbackIsComplete(uint32_t uContextID);
172 int callbackMoveForward(uint32_t uContextID, const char *pszMessage);
173 int callbackNotifyEx(uint32_t uContextID, int iRC, const char *pszMessage);
174 int callbackNotifyComplete(uint32_t uContextID);
175 int callbackNotifyAllForPID(uint32_t uPID, int iRC, const char *pszMessage);
176 int callbackWaitForCompletion(uint32_t uContextID, LONG lStage, LONG lTimeout);
177
178 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
179 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
180 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
181 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
182
183 // Internal guest process representation.
184 typedef struct VBOXGUESTCTRL_PROCESS
185 {
186 ExecuteProcessStatus_T mStatus;
187 uint32_t mFlags;
188 uint32_t mExitCode;
189 } VBOXGUESTCTRL_PROCESS, *PVBOXGUESTCTRL_PROCESS;
190 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS > GuestProcessMap;
191 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::iterator GuestProcessMapIter;
192 typedef std::map< uint32_t, VBOXGUESTCTRL_PROCESS >::const_iterator GuestProcessMapIterConst;
193
194 int processAdd(uint32_t u32PID, ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags);
195 int processGetByPID(uint32_t u32PID, PVBOXGUESTCTRL_PROCESS pProcess);
196 int processSetStatus(uint32_t u32PID, ExecuteProcessStatus_T enmStatus, uint32_t uExitCode, uint32_t uFlags);
197
198 // Utility functions.
199 int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
200 int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
201 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
202
203 /*
204 * Handler for guest execution control notifications.
205 */
206 HRESULT handleErrorCompletion(int rc);
207 HRESULT handleErrorHGCM(int rc);
208
209 HRESULT waitForProcessStatusChange(ULONG uPID, ExecuteProcessStatus_T *pRetStatus, ULONG *puRetExitCode, ULONG uTimeoutMS);
210 HRESULT executeProcessResult(const char *pszCommand, const char *pszUser, ULONG ulTimeout, PCALLBACKDATAEXECSTATUS pExecStatus, ULONG *puPID);
211# endif
212
213 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
214 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
215 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
216
217 struct Data
218 {
219 Data() : mAdditionsRunLevel (AdditionsRunLevelType_None) {}
220
221 Bstr mOSTypeId;
222 FacilityMap mFacilityMap;
223 AdditionsRunLevelType_T mAdditionsRunLevel;
224 Bstr mAdditionsVersion;
225 Bstr mInterfaceVersion;
226 };
227
228 ULONG mMemoryBalloonSize;
229 ULONG mStatUpdateInterval;
230 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
231 BOOL mfPageFusionEnabled;
232
233 Console *mParent;
234 Data mData;
235
236# ifdef VBOX_WITH_GUEST_CONTROL
237 /** General extension callback for guest control. */
238 HGCMSVCEXTHANDLE mhExtCtrl;
239 /** Next upcoming context ID. */
240 volatile uint32_t mNextContextID;
241 CallbackMap mCallbackMap;
242 GuestProcessMap mGuestProcessMap;
243# endif
244};
245
246#endif // ____H_GUESTIMPL
247/* 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