VirtualBox

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

Last change on this file since 80828 was 80828, checked in by vboxsync, 5 years ago

Main/Guest*: Create enviornment blocks with RTENV_CREATE_F_ALLOW_EQUAL_FIRST_IN_VAR for windows guests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/* $Id: GuestImpl.h 80828 2019-09-16 14:05:09Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_GuestImpl_h
19#define MAIN_INCLUDED_GuestImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "GuestWrap.h"
25#include "VirtualBoxBase.h"
26#include <iprt/list.h>
27#include <iprt/time.h>
28#include <VBox/ostypes.h>
29#include <VBox/param.h>
30#include <VBox/vmm/stam.h>
31
32#include "AdditionsFacilityImpl.h"
33#ifdef VBOX_WITH_GUEST_CONTROL
34# include "GuestCtrlImplPrivate.h"
35# include "GuestSessionImpl.h"
36#endif
37#ifdef VBOX_WITH_DRAG_AND_DROP
38# include "GuestDnDSourceImpl.h"
39# include "GuestDnDTargetImpl.h"
40#endif
41#include "EventImpl.h"
42#include "HGCM.h"
43
44typedef enum
45{
46 GUESTSTATTYPE_CPUUSER = 0,
47 GUESTSTATTYPE_CPUKERNEL = 1,
48 GUESTSTATTYPE_CPUIDLE = 2,
49 GUESTSTATTYPE_MEMTOTAL = 3,
50 GUESTSTATTYPE_MEMFREE = 4,
51 GUESTSTATTYPE_MEMBALLOON = 5,
52 GUESTSTATTYPE_MEMCACHE = 6,
53 GUESTSTATTYPE_PAGETOTAL = 7,
54 GUESTSTATTYPE_PAGEFREE = 8,
55 GUESTSTATTYPE_MAX = 9
56} GUESTSTATTYPE;
57
58class Console;
59
60class ATL_NO_VTABLE Guest :
61 public GuestWrap
62{
63public:
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
75public:
76 /** @name Static internal methods.
77 * @{ */
78#ifdef VBOX_WITH_GUEST_CONTROL
79 /** Static callback for handling guest control notifications. */
80 static DECLCALLBACK(int) i_notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvData, uint32_t cbData);
81#endif
82 static DECLCALLBACK(void) i_staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
83 /** @} */
84
85public:
86 /** @name Public internal methods.
87 * @{ */
88 void i_enableVMMStatistics(BOOL aEnable) { mCollectVMMStats = aEnable; };
89 void i_setAdditionsInfo(const com::Utf8Str &aInterfaceVersion, VBOXOSTYPE aOsType);
90 void i_setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures);
91 bool i_facilityIsActive(VBoxGuestFacilityType enmFacility);
92 bool i_facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
93 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
94 ComObjPtr<Console> i_getConsole(void) { return mParent; }
95 void i_setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
96 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
97 void i_onUserStateChange(Bstr aUser, Bstr aDomain, VBoxGuestUserState enmState, const uint8_t *puDetails, uint32_t cbDetails);
98 void i_setSupportedFeatures(uint32_t aCaps);
99 HRESULT i_setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
100 BOOL i_isPageFusionEnabled();
101 void i_setCpuCount(uint32_t aCpus) { mCpus = aCpus; }
102 static HRESULT i_setErrorStatic(HRESULT aResultCode, const Utf8Str &aText)
103 {
104 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
105 }
106 uint32_t i_getAdditionsRevision(void) { return mData.mAdditionsRevision; }
107 uint32_t i_getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
108 VBOXOSTYPE i_getGuestOSType(void) const { return mData.mOSType; }
109 /** Checks if the guest OS type is part of the windows NT family. */
110 bool i_isGuestInWindowsNtFamily(void) const
111 {
112 return mData.mOSType < VBOXOSTYPE_OS2 && mData.mOSType >= VBOXOSTYPE_WinNT;
113 }
114#ifdef VBOX_WITH_GUEST_CONTROL
115 int i_dispatchToSession(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
116 int i_sessionRemove(uint32_t uSessionID);
117 int i_sessionCreate(const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds,
118 ComObjPtr<GuestSession> &pGuestSession);
119 inline bool i_sessionExists(uint32_t uSessionID);
120 /** Returns the VBOX_GUESTCTRL_GF_0_XXX mask reported by the guest. */
121 uint64_t i_getGuestControlFeatures0() const { return mData.mfGuestFeatures0; }
122 /** Returns the VBOX_GUESTCTRL_GF_1_XXX mask reported by the guest. */
123 uint64_t i_getGuestControlFeatures1() const { return mData.mfGuestFeatures1; }
124#endif
125 /** @} */
126
127private:
128
129 // wrapped IGuest properties
130 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
131 HRESULT getAdditionsRunLevel(AdditionsRunLevelType_T *aAdditionsRunLevel);
132 HRESULT getAdditionsVersion(com::Utf8Str &aAdditionsVersion);
133 HRESULT getAdditionsRevision(ULONG *aAdditionsRevision);
134 HRESULT getDnDSource(ComPtr<IGuestDnDSource> &aDnDSource);
135 HRESULT getDnDTarget(ComPtr<IGuestDnDTarget> &aDnDTarget);
136 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
137 HRESULT getFacilities(std::vector<ComPtr<IAdditionsFacility> > &aFacilities);
138 HRESULT getSessions(std::vector<ComPtr<IGuestSession> > &aSessions);
139 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
140 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
141 HRESULT getStatisticsUpdateInterval(ULONG *aStatisticsUpdateInterval);
142 HRESULT setStatisticsUpdateInterval(ULONG aStatisticsUpdateInterval);
143 HRESULT internalGetStatistics(ULONG *aCpuUser,
144 ULONG *aCpuKernel,
145 ULONG *aCpuIdle,
146 ULONG *aMemTotal,
147 ULONG *aMemFree,
148 ULONG *aMemBalloon,
149 ULONG *aMemShared,
150 ULONG *aMemCache,
151 ULONG *aPagedTotal,
152 ULONG *aMemAllocTotal,
153 ULONG *aMemFreeTotal,
154 ULONG *aMemBalloonTotal,
155 ULONG *aMemSharedTotal);
156 HRESULT getFacilityStatus(AdditionsFacilityType_T aFacility,
157 LONG64 *aTimestamp,
158 AdditionsFacilityStatus_T *aStatus);
159 HRESULT getAdditionsStatus(AdditionsRunLevelType_T aLevel,
160 BOOL *aActive);
161 HRESULT setCredentials(const com::Utf8Str &aUserName,
162 const com::Utf8Str &aPassword,
163 const com::Utf8Str &aDomain,
164 BOOL aAllowInteractiveLogon);
165
166 // wrapped IGuest methods
167 HRESULT createSession(const com::Utf8Str &aUser,
168 const com::Utf8Str &aPassword,
169 const com::Utf8Str &aDomain,
170 const com::Utf8Str &aSessionName,
171 ComPtr<IGuestSession> &aGuestSession);
172
173 HRESULT findSession(const com::Utf8Str &aSessionName,
174 std::vector<ComPtr<IGuestSession> > &aSessions);
175 HRESULT updateGuestAdditions(const com::Utf8Str &aSource,
176 const std::vector<com::Utf8Str> &aArguments,
177 const std::vector<AdditionsUpdateFlag_T> &aFlags,
178 ComPtr<IProgress> &aProgress);
179
180
181 /** @name Private internal methods.
182 * @{ */
183 void i_updateStats(uint64_t iTick);
184 static DECLCALLBACK(int) i_staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample,
185 STAMUNIT enmUnit, STAMVISIBILITY enmVisiblity,
186 const char *pszDesc, void *pvUser);
187
188 /** @} */
189
190 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
191 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
192 typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
193
194#ifdef VBOX_WITH_GUEST_CONTROL
195 /** Map for keeping the guest sessions. The primary key marks the guest session ID. */
196 typedef std::map <uint32_t, ComObjPtr<GuestSession> > GuestSessions;
197#endif
198
199 struct Data
200 {
201 Data() : mOSType(VBOXOSTYPE_Unknown), mAdditionsRunLevel(AdditionsRunLevelType_None)
202 , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
203#ifdef VBOX_WITH_GUEST_CONTROL
204 , mfGuestFeatures0(0), mfGuestFeatures1(0)
205#endif
206 { }
207
208 VBOXOSTYPE mOSType; /**@< For internal used. VBOXOSTYPE_Unknown if not reported. */
209 Utf8Str mOSTypeId;
210 FacilityMap mFacilityMap;
211 AdditionsRunLevelType_T mAdditionsRunLevel;
212 uint32_t mAdditionsVersionFull;
213 Utf8Str mAdditionsVersionNew;
214 uint32_t mAdditionsRevision;
215 uint32_t mAdditionsFeatures;
216 Utf8Str mInterfaceVersion;
217#ifdef VBOX_WITH_GUEST_CONTROL
218 GuestSessions mGuestSessions;
219 /** Guest control features (reported by the guest), VBOX_GUESTCTRL_GF_0_XXX. */
220 uint64_t mfGuestFeatures0;
221 /** Guest control features (reported by the guest), VBOX_GUESTCTRL_GF_1_XXX. */
222 uint64_t mfGuestFeatures1;
223#endif
224 } mData;
225
226 ULONG mMemoryBalloonSize;
227 ULONG mStatUpdateInterval; /**< In seconds. */
228 uint64_t mNetStatRx;
229 uint64_t mNetStatTx;
230 uint64_t mNetStatLastTs;
231 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
232 ULONG mCurrentGuestCpuUserStat[VMM_MAX_CPU_COUNT];
233 ULONG mCurrentGuestCpuKernelStat[VMM_MAX_CPU_COUNT];
234 ULONG mCurrentGuestCpuIdleStat[VMM_MAX_CPU_COUNT];
235 ULONG mVmValidStats;
236 BOOL mCollectVMMStats;
237 BOOL mfPageFusionEnabled;
238 uint32_t mCpus;
239
240 const ComObjPtr<Console> mParent;
241
242 /**
243 * This can safely be used without holding any locks.
244 * An AutoCaller suffices to prevent it being destroy while in use and
245 * internally there is a lock providing the necessary serialization.
246 */
247 const ComObjPtr<EventSource> mEventSource;
248#ifdef VBOX_WITH_GUEST_CONTROL
249 /** General extension callback for guest control. */
250 HGCMSVCEXTHANDLE mhExtCtrl;
251#endif
252
253#ifdef VBOX_WITH_DRAG_AND_DROP
254 /** The guest's DnD source. */
255 const ComObjPtr<GuestDnDSource> mDnDSource;
256 /** The guest's DnD target. */
257 const ComObjPtr<GuestDnDTarget> mDnDTarget;
258#endif
259
260 RTTIMERLR mStatTimer;
261 uint32_t mMagic; /** @todo r=andy Rename this to something more meaningful. */
262};
263#define GUEST_MAGIC 0xCEED2006u /** @todo r=andy Not very well defined!? */
264
265#endif /* !MAIN_INCLUDED_GuestImpl_h */
266
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