1 | /* $Id: GuestImpl.h 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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/vmm/stam.h>
|
---|
27 |
|
---|
28 | #include "AdditionsFacilityImpl.h"
|
---|
29 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
30 | # include "GuestCtrlImplPrivate.h"
|
---|
31 | # include "GuestSessionImpl.h"
|
---|
32 | #endif
|
---|
33 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
34 | # include "GuestDnDSourceImpl.h"
|
---|
35 | # include "GuestDnDTargetImpl.h"
|
---|
36 | #endif
|
---|
37 | #include "EventImpl.h"
|
---|
38 | #include "HGCM.h"
|
---|
39 |
|
---|
40 | typedef enum
|
---|
41 | {
|
---|
42 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
43 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
44 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
45 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
46 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
47 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
48 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
49 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
50 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
51 | GUESTSTATTYPE_MAX = 9
|
---|
52 | } GUESTSTATTYPE;
|
---|
53 |
|
---|
54 | class Console;
|
---|
55 |
|
---|
56 | class ATL_NO_VTABLE Guest :
|
---|
57 | public GuestWrap
|
---|
58 | {
|
---|
59 | public:
|
---|
60 |
|
---|
61 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
62 |
|
---|
63 | HRESULT FinalConstruct();
|
---|
64 | void FinalRelease();
|
---|
65 |
|
---|
66 | // Public initializer/uninitializer for internal purposes only.
|
---|
67 | HRESULT init(Console *aParent);
|
---|
68 | void uninit();
|
---|
69 |
|
---|
70 |
|
---|
71 | public:
|
---|
72 | /** @name Static internal methods.
|
---|
73 | * @{ */
|
---|
74 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
75 | /** Static callback for handling guest control notifications. */
|
---|
76 | static DECLCALLBACK(int) i_notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvData, uint32_t cbData);
|
---|
77 | #endif
|
---|
78 | static DECLCALLBACK(void) i_staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 | public:
|
---|
82 | /** @name Public internal methods.
|
---|
83 | * @{ */
|
---|
84 | void i_enableVMMStatistics(BOOL aEnable) { mCollectVMMStats = aEnable; };
|
---|
85 | void i_setAdditionsInfo(const com::Utf8Str &aInterfaceVersion, VBOXOSTYPE aOsType);
|
---|
86 | void i_setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures);
|
---|
87 | bool i_facilityIsActive(VBoxGuestFacilityType enmFacility);
|
---|
88 | void i_facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
|
---|
89 | uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
90 | ComObjPtr<Console> i_getConsole(void) { return mParent; }
|
---|
91 | void i_setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
|
---|
92 | uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
93 | void i_onUserStateChange(Bstr aUser, Bstr aDomain, VBoxGuestUserState enmState, const uint8_t *puDetails, uint32_t cbDetails);
|
---|
94 | void i_setSupportedFeatures(uint32_t aCaps);
|
---|
95 | HRESULT i_setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
96 | BOOL i_isPageFusionEnabled();
|
---|
97 | void i_setCpuCount(uint32_t aCpus) { mCpus = aCpus; }
|
---|
98 | static HRESULT i_setErrorStatic(HRESULT aResultCode, const Utf8Str &aText)
|
---|
99 | {
|
---|
100 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
101 | }
|
---|
102 | uint32_t i_getAdditionsRevision(void) { return mData.mAdditionsRevision; }
|
---|
103 | uint32_t i_getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
|
---|
104 | VBOXOSTYPE i_getGuestOSType(void) { return mData.mOSType; }
|
---|
105 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
106 | int i_dispatchToSession(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
107 | int i_sessionRemove(GuestSession *pSession);
|
---|
108 | int i_sessionCreate(const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds,
|
---|
109 | ComObjPtr<GuestSession> &pGuestSession);
|
---|
110 | inline bool i_sessionExists(uint32_t uSessionID);
|
---|
111 |
|
---|
112 | #endif
|
---|
113 | /** @} */
|
---|
114 |
|
---|
115 | private:
|
---|
116 |
|
---|
117 | // wrapped IGuest properties
|
---|
118 | HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
|
---|
119 | HRESULT getAdditionsRunLevel(AdditionsRunLevelType_T *aAdditionsRunLevel);
|
---|
120 | HRESULT getAdditionsVersion(com::Utf8Str &aAdditionsVersion);
|
---|
121 | HRESULT getAdditionsRevision(ULONG *aAdditionsRevision);
|
---|
122 | HRESULT getDnDSource(ComPtr<IGuestDnDSource> &aDnDSource);
|
---|
123 | HRESULT getDnDTarget(ComPtr<IGuestDnDTarget> &aDnDTarget);
|
---|
124 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
125 | HRESULT getFacilities(std::vector<ComPtr<IAdditionsFacility> > &aFacilities);
|
---|
126 | HRESULT getSessions(std::vector<ComPtr<IGuestSession> > &aSessions);
|
---|
127 | HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
|
---|
128 | HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
|
---|
129 | HRESULT getStatisticsUpdateInterval(ULONG *aStatisticsUpdateInterval);
|
---|
130 | HRESULT setStatisticsUpdateInterval(ULONG aStatisticsUpdateInterval);
|
---|
131 | HRESULT internalGetStatistics(ULONG *aCpuUser,
|
---|
132 | ULONG *aCpuKernel,
|
---|
133 | ULONG *aCpuIdle,
|
---|
134 | ULONG *aMemTotal,
|
---|
135 | ULONG *aMemFree,
|
---|
136 | ULONG *aMemBalloon,
|
---|
137 | ULONG *aMemShared,
|
---|
138 | ULONG *aMemCache,
|
---|
139 | ULONG *aPagedTotal,
|
---|
140 | ULONG *aMemAllocTotal,
|
---|
141 | ULONG *aMemFreeTotal,
|
---|
142 | ULONG *aMemBalloonTotal,
|
---|
143 | ULONG *aMemSharedTotal);
|
---|
144 | HRESULT getFacilityStatus(AdditionsFacilityType_T aFacility,
|
---|
145 | LONG64 *aTimestamp,
|
---|
146 | AdditionsFacilityStatus_T *aStatus);
|
---|
147 | HRESULT getAdditionsStatus(AdditionsRunLevelType_T aLevel,
|
---|
148 | BOOL *aActive);
|
---|
149 | HRESULT setCredentials(const com::Utf8Str &aUserName,
|
---|
150 | const com::Utf8Str &aPassword,
|
---|
151 | const com::Utf8Str &aDomain,
|
---|
152 | BOOL aAllowInteractiveLogon);
|
---|
153 |
|
---|
154 | // wrapped IGuest methods
|
---|
155 | HRESULT createSession(const com::Utf8Str &aUser,
|
---|
156 | const com::Utf8Str &aPassword,
|
---|
157 | const com::Utf8Str &aDomain,
|
---|
158 | const com::Utf8Str &aSessionName,
|
---|
159 | ComPtr<IGuestSession> &aGuestSession);
|
---|
160 |
|
---|
161 | HRESULT findSession(const com::Utf8Str &aSessionName,
|
---|
162 | std::vector<ComPtr<IGuestSession> > &aSessions);
|
---|
163 | HRESULT updateGuestAdditions(const com::Utf8Str &aSource,
|
---|
164 | const std::vector<com::Utf8Str> &aArguments,
|
---|
165 | const std::vector<AdditionsUpdateFlag_T> &aFlags,
|
---|
166 | ComPtr<IProgress> &aProgress);
|
---|
167 |
|
---|
168 |
|
---|
169 | /** @name Private internal methods.
|
---|
170 | * @{ */
|
---|
171 | void i_updateStats(uint64_t iTick);
|
---|
172 | static DECLCALLBACK(int) i_staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample,
|
---|
173 | STAMUNIT enmUnit, STAMVISIBILITY enmVisiblity,
|
---|
174 | const char *pszDesc, void *pvUser);
|
---|
175 |
|
---|
176 | /** @} */
|
---|
177 |
|
---|
178 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
|
---|
179 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
|
---|
180 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
|
---|
181 |
|
---|
182 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
183 | /** Map for keeping the guest sessions. The primary key marks the guest session ID. */
|
---|
184 | typedef std::map <uint32_t, ComObjPtr<GuestSession> > GuestSessions;
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | struct Data
|
---|
188 | {
|
---|
189 | Data() : mOSType(VBOXOSTYPE_Unknown), mAdditionsRunLevel(AdditionsRunLevelType_None)
|
---|
190 | , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
|
---|
191 | { }
|
---|
192 |
|
---|
193 | VBOXOSTYPE mOSType; /**@< For internal used. VBOXOSTYPE_Unknown if not reported. */
|
---|
194 | Utf8Str mOSTypeId;
|
---|
195 | FacilityMap mFacilityMap;
|
---|
196 | AdditionsRunLevelType_T mAdditionsRunLevel;
|
---|
197 | uint32_t mAdditionsVersionFull;
|
---|
198 | Utf8Str mAdditionsVersionNew;
|
---|
199 | uint32_t mAdditionsRevision;
|
---|
200 | uint32_t mAdditionsFeatures;
|
---|
201 | Utf8Str mInterfaceVersion;
|
---|
202 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
203 | GuestSessions mGuestSessions;
|
---|
204 | uint32_t mNextSessionID;
|
---|
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 |
|
---|