VirtualBox

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

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

GuestCtrl: Added APIs for guest directory enumeration, guest file existence and copy from guest support, some API renaming/cleanup (work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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#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 // Misc stuff
110 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
111 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
112 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
113 STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
114
115 // Public methods that are not in IDL (only called internally).
116 HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
117 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
118 IN_BSTR aUserName, IN_BSTR aPassword,
119 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
120 HRESULT directoryCreateInternal(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword,
121 ULONG aMode, ULONG aFlags, int *pRC);
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# ifdef VBOX_WITH_GUEST_CONTROL
131 /** Static callback for handling guest notifications. */
132 static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
133# endif
134 static HRESULT setErrorStatic(HRESULT aResultCode,
135 const Utf8Str &aText)
136 {
137 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
138 }
139
140private:
141#ifdef VBOX_WITH_GUEST_CONTROL
142 // Internal tasks.
143 struct TaskGuest; /* Worker thread helper. */
144 HRESULT taskCopyFileToGuest(TaskGuest *aTask);
145 HRESULT taskCopyFileFromGuest(TaskGuest *aTask);
146 HRESULT taskUpdateGuestAdditions(TaskGuest *aTask);
147
148 // Internal callback context handling.
149 struct CallbackContext
150 {
151 eVBoxGuestCtrlCallbackType mType;
152 /** Pointer to user-supplied data. */
153 void *pvData;
154 /** Size of user-supplied data. */
155 uint32_t cbData;
156 /** Pointer to user-supplied IProgress. */
157 ComObjPtr<Progress> pProgress;
158 };
159 /*
160 * The map key is the context ID.
161 */
162 typedef std::map< uint32_t, CallbackContext > CallbackMap;
163 typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
164 typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
165
166 struct GuestProcess
167 {
168 ExecuteProcessStatus_T mStatus;
169 uint32_t mFlags;
170 uint32_t mExitCode;
171 };
172 /*
173 * The map key is the PID (process identifier).
174 */
175 typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
176 typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
177 typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
178
179 int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
180 int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
181
182 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
183 /** Handler for guest execution control notifications. */
184 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
185 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
186 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
187 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
188 CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
189 GuestProcessMapIter getProcessByPID(uint32_t u32PID);
190 void notifyCtrlCallbackContext(Guest::CallbackMapIter it, const char *pszText);
191 void destroyCtrlCallbackContext(CallbackMapIter it);
192 uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
193 HRESULT waitForProcessStatusChange(ULONG uPID, ExecuteProcessStatus_T *pRetStatus, ULONG *puRetExitCode, ULONG uTimeoutMS);
194# endif
195
196 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
197 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
198 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
199
200 struct Data
201 {
202 Data() : mAdditionsRunLevel (AdditionsRunLevelType_None) {}
203
204 Bstr mOSTypeId;
205 FacilityMap mFacilityMap;
206 AdditionsRunLevelType_T mAdditionsRunLevel;
207 Bstr mAdditionsVersion;
208 Bstr mInterfaceVersion;
209 };
210
211 ULONG mMemoryBalloonSize;
212 ULONG mStatUpdateInterval;
213 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
214 BOOL mfPageFusionEnabled;
215
216 Console *mParent;
217 Data mData;
218
219# ifdef VBOX_WITH_GUEST_CONTROL
220 /** General extension callback for guest control. */
221 HGCMSVCEXTHANDLE mhExtCtrl;
222
223 volatile uint32_t mNextContextID;
224 CallbackMap mCallbackMap;
225 GuestProcessMap mGuestProcessMap;
226# endif
227};
228
229#endif // ____H_GUESTIMPL
230/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette