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