VirtualBox

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

Last change on this file since 79658 was 79296, checked in by vboxsync, 6 years ago

Main,VBoxService,GstCtrlSvc: Added functions for exchanging feature masks between guest and host so new features can more easily be added without resorting to version comparsion magic. Added alternative read and write completion notifications that includes the new file offset. Made sure RTFileReadAt and RTFileWriteAt are followed by a RTFileSeek call so we'll end up with the same file position regardless of guest OS. bugref:9320

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