VirtualBox

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

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

Burn fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 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.215389.xyz. 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#ifdef VBOX_WITH_GUEST_CONTROL
26# include <VBox/HostServices/GuestControlSvc.h>
27# include "HGCM.h"
28using namespace guestControl;
29#endif
30
31typedef enum
32{
33 GUESTSTATTYPE_CPUUSER = 0,
34 GUESTSTATTYPE_CPUKERNEL = 1,
35 GUESTSTATTYPE_CPUIDLE = 2,
36 GUESTSTATTYPE_MEMTOTAL = 3,
37 GUESTSTATTYPE_MEMFREE = 4,
38 GUESTSTATTYPE_MEMBALLOON = 5,
39 GUESTSTATTYPE_MEMCACHE = 6,
40 GUESTSTATTYPE_PAGETOTAL = 7,
41 GUESTSTATTYPE_PAGEFREE = 8,
42 GUESTSTATTYPE_MAX = 9
43} GUESTSTATTYPE;
44
45class Console;
46#ifdef VBOX_WITH_GUEST_CONTROL
47class Progress;
48#endif
49
50class ATL_NO_VTABLE Guest :
51 public VirtualBoxBase,
52 VBOX_SCRIPTABLE_IMPL(IGuest)
53{
54public:
55 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
56
57 DECLARE_NOT_AGGREGATABLE(Guest)
58
59 DECLARE_PROTECT_FINAL_CONSTRUCT()
60
61 BEGIN_COM_MAP(Guest)
62 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
63 END_COM_MAP()
64
65 DECLARE_EMPTY_CTOR_DTOR (Guest)
66
67 HRESULT FinalConstruct();
68 void FinalRelease();
69
70 // Public initializer/uninitializer for internal purposes only
71 HRESULT init (Console *aParent);
72 void uninit();
73
74 // IGuest properties
75 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
76 STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
77 STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
78 /** @todo Remove later by replacing it by AdditionsFeatureAvailable(). */
79 STDMETHOD(COMGETTER(SupportsSeamless)) (BOOL *aSupportsSeamless);
80 STDMETHOD(COMGETTER(SupportsGraphics)) (BOOL *aSupportsGraphics);
81#if 0
82 /** @todo Will replace SupportsSeamless, SupportsGraphics, ... */
83 STDMETHOD(COMGETTER(AdditionsFeatureAvailable)) (LONG64 aFeature, BOOL *aActive, BOOL *aAvailable);
84#endif
85 STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
86 STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
87 STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
88 STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
89
90 // IGuest methods
91 STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
92 STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
93 STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
94 IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
95 STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
96 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
97 IN_BSTR aUserName, IN_BSTR aPassword,
98 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
99 STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
100 STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
101 STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus);
102 STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
103 STDMETHOD(CreateDirectory)(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aMode, ULONG aFlags, IProgress **aProgress);
104 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
105 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
106 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
107 STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
108
109 // Public methods that are not in IDL (only called internally).
110 HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
111 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
112 IN_BSTR aUserName, IN_BSTR aPassword,
113 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
114 HRESULT createDirectoryInternal(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword,
115 ULONG aMode, ULONG aFlags, IProgress **aProgress, int *pRC);
116 void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
117 void setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision);
118 void setAdditionsStatus(VBoxGuestStatusFacility enmFacility, VBoxGuestStatusCurrent enmStatus, ULONG aFlags);
119 void setSupportedFeatures(uint32_t aCaps);
120 HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
121 BOOL isPageFusionEnabled();
122# ifdef VBOX_WITH_GUEST_CONTROL
123 /** Static callback for handling guest notifications. */
124 static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
125# endif
126 static HRESULT setErrorStatic(HRESULT aResultCode,
127 const Utf8Str &aText)
128 {
129 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
130 }
131
132private:
133#ifdef VBOX_WITH_GUEST_CONTROL
134 // Internal tasks.
135 struct TaskGuest; /* Worker thread helper. */
136 HRESULT taskCopyFile(TaskGuest *aTask);
137 HRESULT taskUpdateGuestAdditions(TaskGuest *aTask);
138
139 // Internal callback context handling.
140 struct CallbackContext
141 {
142 eVBoxGuestCtrlCallbackType mType;
143 /** Pointer to user-supplied data. */
144 void *pvData;
145 /** Size of user-supplied data. */
146 uint32_t cbData;
147 /** Pointer to user-supplied IProgress. */
148 ComObjPtr<Progress> pProgress;
149 };
150 /*
151 * The map key is the context ID.
152 */
153 typedef std::map< uint32_t, CallbackContext > CallbackMap;
154 typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
155 typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
156
157 struct GuestProcess
158 {
159 uint32_t mStatus;
160 uint32_t mFlags;
161 uint32_t mExitCode;
162 };
163 /*
164 * The map key is the PID (process identifier).
165 */
166 typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
167 typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
168 typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
169
170 int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
171 int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
172
173 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
174 /** Handler for guest execution control notifications. */
175 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
176 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
177 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
178 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
179 CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
180 GuestProcessMapIter getProcessByPID(uint32_t u32PID);
181 void notifyCtrlCallbackContext(Guest::CallbackMapIter it, const char *pszText);
182 void destroyCtrlCallbackContext(CallbackMapIter it);
183 uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
184 HRESULT waitForProcessStatusChange(ULONG uPID, ULONG *puRetStatus, ULONG *puRetExitCode, ULONG uTimeoutMS);
185# endif
186
187 struct FacilityData
188 {
189 RTTIMESPEC tsLastUpdated;
190 AdditionsFacilityStatus_T curStatus;
191 };
192 typedef std::map< AdditionsFacilityType_T, FacilityData > FacilityMap;
193 typedef std::map< AdditionsFacilityType_T, FacilityData >::iterator FacilityMapIter;
194
195 struct Data
196 {
197 Data() : mAdditionsRunLevel (AdditionsRunLevelType_None),
198 mSupportsSeamless (FALSE),
199 mSupportsGraphics (FALSE) {}
200
201 Bstr mOSTypeId;
202
203 FacilityMap mFacilityMap;
204 AdditionsRunLevelType_T mAdditionsRunLevel;
205 Bstr mAdditionsVersion;
206 Bstr mInterfaceVersion;
207 BOOL mSupportsSeamless;
208 BOOL mSupportsGraphics;
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