VirtualBox

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

Last change on this file since 78493 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

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