VirtualBox

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

Last change on this file since 94134 was 93468, checked in by vboxsync, 3 years ago

VBoxDbg,VMM/STAM,Main: Converted VBoxDbg to use the VMM function table, extending the STAMR3Enum to include the unit string to avoid needing to call STAMR3GetUnit a lot. The latter would better fit with the XML based viewer, as it only gets the string version of the unit. Had to adjust a user of STAMR3Enum in Main. bugref:10074

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: GuestImpl.h 93468 2022-01-27 21:17:12Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2022 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_COMMON_CLASS_METHODS (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_onUserStateChanged(const Utf8Str &aUser, const Utf8Str &aDomain, VBoxGuestUserState enmState,
98 const uint8_t *puDetails, uint32_t cbDetails);
99 void i_setSupportedFeatures(uint32_t aCaps);
100 HRESULT i_setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
101 BOOL i_isPageFusionEnabled();
102 void i_setCpuCount(uint32_t aCpus) { mCpus = aCpus; }
103 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *aText, ...)
104 {
105 va_list va;
106 va_start(va, aText);
107 HRESULT hrc = setErrorInternalV(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, va, false, true);
108 va_end(va);
109 return hrc;
110 }
111 uint32_t i_getAdditionsRevision(void) { return mData.mAdditionsRevision; }
112 uint32_t i_getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
113 VBOXOSTYPE i_getGuestOSType(void) const { return mData.mOSType; }
114 /** Checks if the guest OS type is part of the windows NT family. */
115 bool i_isGuestInWindowsNtFamily(void) const
116 {
117 return mData.mOSType < VBOXOSTYPE_OS2 && mData.mOSType >= VBOXOSTYPE_WinNT;
118 }
119#ifdef VBOX_WITH_GUEST_CONTROL
120 int i_dispatchToSession(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
121 int i_sessionCreate(const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds,
122 ComObjPtr<GuestSession> &pGuestSession);
123 int i_sessionDestroy(uint32_t uSessionID);
124 inline bool i_sessionExists(uint32_t uSessionID);
125 /** Returns the VBOX_GUESTCTRL_GF_0_XXX mask reported by the guest. */
126 uint64_t i_getGuestControlFeatures0() const { return mData.mfGuestFeatures0; }
127 /** Returns the VBOX_GUESTCTRL_GF_1_XXX mask reported by the guest. */
128 uint64_t i_getGuestControlFeatures1() const { return mData.mfGuestFeatures1; }
129#endif
130 /** @} */
131
132private:
133
134 // wrapped IGuest properties
135 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
136 HRESULT getAdditionsRunLevel(AdditionsRunLevelType_T *aAdditionsRunLevel);
137 HRESULT getAdditionsVersion(com::Utf8Str &aAdditionsVersion);
138 HRESULT getAdditionsRevision(ULONG *aAdditionsRevision);
139 HRESULT getDnDSource(ComPtr<IGuestDnDSource> &aDnDSource);
140 HRESULT getDnDTarget(ComPtr<IGuestDnDTarget> &aDnDTarget);
141 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
142 HRESULT getFacilities(std::vector<ComPtr<IAdditionsFacility> > &aFacilities);
143 HRESULT getSessions(std::vector<ComPtr<IGuestSession> > &aSessions);
144 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
145 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
146 HRESULT getStatisticsUpdateInterval(ULONG *aStatisticsUpdateInterval);
147 HRESULT setStatisticsUpdateInterval(ULONG aStatisticsUpdateInterval);
148 HRESULT internalGetStatistics(ULONG *aCpuUser,
149 ULONG *aCpuKernel,
150 ULONG *aCpuIdle,
151 ULONG *aMemTotal,
152 ULONG *aMemFree,
153 ULONG *aMemBalloon,
154 ULONG *aMemShared,
155 ULONG *aMemCache,
156 ULONG *aPagedTotal,
157 ULONG *aMemAllocTotal,
158 ULONG *aMemFreeTotal,
159 ULONG *aMemBalloonTotal,
160 ULONG *aMemSharedTotal);
161 HRESULT getFacilityStatus(AdditionsFacilityType_T aFacility,
162 LONG64 *aTimestamp,
163 AdditionsFacilityStatus_T *aStatus);
164 HRESULT getAdditionsStatus(AdditionsRunLevelType_T aLevel,
165 BOOL *aActive);
166 HRESULT setCredentials(const com::Utf8Str &aUserName,
167 const com::Utf8Str &aPassword,
168 const com::Utf8Str &aDomain,
169 BOOL aAllowInteractiveLogon);
170
171 // wrapped IGuest methods
172 HRESULT createSession(const com::Utf8Str &aUser,
173 const com::Utf8Str &aPassword,
174 const com::Utf8Str &aDomain,
175 const com::Utf8Str &aSessionName,
176 ComPtr<IGuestSession> &aGuestSession);
177
178 HRESULT findSession(const com::Utf8Str &aSessionName,
179 std::vector<ComPtr<IGuestSession> > &aSessions);
180 HRESULT shutdown(const std::vector<GuestShutdownFlag_T> &aFlags);
181 HRESULT updateGuestAdditions(const com::Utf8Str &aSource,
182 const std::vector<com::Utf8Str> &aArguments,
183 const std::vector<AdditionsUpdateFlag_T> &aFlags,
184 ComPtr<IProgress> &aProgress);
185
186
187 /** @name Private internal methods.
188 * @{ */
189 void i_updateStats(uint64_t iTick);
190 static DECLCALLBACK(int) i_staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample,
191 STAMUNIT enmUnit, const char *pszUnit, STAMVISIBILITY enmVisiblity,
192 const char *pszDesc, void *pvUser);
193
194 /** @} */
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#ifdef VBOX_WITH_GUEST_CONTROL
201 /** Map for keeping the guest sessions. The primary key marks the guest session ID. */
202 typedef std::map <uint32_t, ComObjPtr<GuestSession> > GuestSessions;
203#endif
204
205 struct Data
206 {
207 Data() : mOSType(VBOXOSTYPE_Unknown), mAdditionsRunLevel(AdditionsRunLevelType_None)
208 , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
209#ifdef VBOX_WITH_GUEST_CONTROL
210 , mfGuestFeatures0(0), mfGuestFeatures1(0)
211#endif
212 { }
213
214 VBOXOSTYPE mOSType; /**@< For internal used. VBOXOSTYPE_Unknown if not reported. */
215 Utf8Str mOSTypeId;
216 FacilityMap mFacilityMap;
217 AdditionsRunLevelType_T mAdditionsRunLevel;
218 uint32_t mAdditionsVersionFull;
219 Utf8Str mAdditionsVersionNew;
220 uint32_t mAdditionsRevision;
221 uint32_t mAdditionsFeatures;
222 Utf8Str mInterfaceVersion;
223#ifdef VBOX_WITH_GUEST_CONTROL
224 GuestSessions mGuestSessions;
225 /** Guest control features (reported by the guest), VBOX_GUESTCTRL_GF_0_XXX. */
226 uint64_t mfGuestFeatures0;
227 /** Guest control features (reported by the guest), VBOX_GUESTCTRL_GF_1_XXX. */
228 uint64_t mfGuestFeatures1;
229#endif
230 } mData;
231
232 ULONG mMemoryBalloonSize;
233 ULONG mStatUpdateInterval; /**< In seconds. */
234 uint64_t mNetStatRx;
235 uint64_t mNetStatTx;
236 uint64_t mNetStatLastTs;
237 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
238 ULONG mCurrentGuestCpuUserStat[VMM_MAX_CPU_COUNT];
239 ULONG mCurrentGuestCpuKernelStat[VMM_MAX_CPU_COUNT];
240 ULONG mCurrentGuestCpuIdleStat[VMM_MAX_CPU_COUNT];
241 ULONG mVmValidStats;
242 BOOL mCollectVMMStats;
243 BOOL mfPageFusionEnabled;
244 uint32_t mCpus;
245
246 const ComObjPtr<Console> mParent;
247
248 /**
249 * This can safely be used without holding any locks.
250 * An AutoCaller suffices to prevent it being destroy while in use and
251 * internally there is a lock providing the necessary serialization.
252 */
253 const ComObjPtr<EventSource> mEventSource;
254#ifdef VBOX_WITH_GUEST_CONTROL
255 /** General extension callback for guest control. */
256 HGCMSVCEXTHANDLE mhExtCtrl;
257#endif
258
259#ifdef VBOX_WITH_DRAG_AND_DROP
260 /** The guest's DnD source. */
261 const ComObjPtr<GuestDnDSource> mDnDSource;
262 /** The guest's DnD target. */
263 const ComObjPtr<GuestDnDTarget> mDnDTarget;
264#endif
265
266 RTTIMERLR mStatTimer;
267 uint32_t mMagic; /** @todo r=andy Rename this to something more meaningful. */
268};
269#define GUEST_MAGIC 0xCEED2006u /** @todo r=andy Not very well defined!? */
270
271#endif /* !MAIN_INCLUDED_GuestImpl_h */
272
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