1 | /** @file
|
---|
2 | * VirtualBox COM class implementation
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ____H_GUESTIMPL
|
---|
18 | #define ____H_GUESTIMPL
|
---|
19 |
|
---|
20 | #include "VirtualBoxBase.h"
|
---|
21 | #include <iprt/list.h>
|
---|
22 | #include <iprt/time.h>
|
---|
23 | #include <VBox/ostypes.h>
|
---|
24 | #include <VBox/vmm/stam.h>
|
---|
25 |
|
---|
26 | #include "AdditionsFacilityImpl.h"
|
---|
27 | #include "GuestCtrlImplPrivate.h"
|
---|
28 | #include "GuestSessionImpl.h"
|
---|
29 | #include "HGCM.h"
|
---|
30 |
|
---|
31 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
32 | class GuestDnD;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | typedef enum
|
---|
36 | {
|
---|
37 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
38 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
39 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
40 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
41 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
42 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
43 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
44 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
45 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
46 | GUESTSTATTYPE_MAX = 9
|
---|
47 | } GUESTSTATTYPE;
|
---|
48 |
|
---|
49 | class Console;
|
---|
50 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
51 | class Progress;
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | class ATL_NO_VTABLE Guest :
|
---|
55 | public VirtualBoxBase,
|
---|
56 | VBOX_SCRIPTABLE_IMPL(IGuest)
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
|
---|
60 |
|
---|
61 | DECLARE_NOT_AGGREGATABLE(Guest)
|
---|
62 |
|
---|
63 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
64 |
|
---|
65 | BEGIN_COM_MAP(Guest)
|
---|
66 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
|
---|
67 | END_COM_MAP()
|
---|
68 |
|
---|
69 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
70 |
|
---|
71 | HRESULT FinalConstruct(void);
|
---|
72 | void FinalRelease(void);
|
---|
73 |
|
---|
74 | // Public initializer/uninitializer for internal purposes only.
|
---|
75 | HRESULT init (Console *aParent);
|
---|
76 | void uninit();
|
---|
77 |
|
---|
78 | // IGuest properties.
|
---|
79 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
80 | STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
|
---|
81 | STDMETHOD(COMGETTER(AdditionsVersion))(BSTR *a_pbstrAdditionsVersion);
|
---|
82 | STDMETHOD(COMGETTER(AdditionsRevision))(ULONG *a_puAdditionsRevision);
|
---|
83 | STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
|
---|
84 | STDMETHOD(COMGETTER(Facilities)) (ComSafeArrayOut(IAdditionsFacility *, aFacilities));
|
---|
85 | STDMETHOD(COMGETTER(Sessions)) (ComSafeArrayOut(IGuestSession *, aSessions));
|
---|
86 | STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
|
---|
87 | STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
|
---|
88 | STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
|
---|
89 | STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
|
---|
90 | // IGuest methods.
|
---|
91 | STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
|
---|
92 | STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
|
---|
93 | STDMETHOD(SetCredentials)(IN_BSTR aUsername, IN_BSTR aPassword,
|
---|
94 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
|
---|
95 | // Drag'n drop support.
|
---|
96 | STDMETHOD(DragHGEnter)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
|
---|
97 | STDMETHOD(DragHGMove)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
|
---|
98 | STDMETHOD(DragHGLeave)(ULONG uScreenId);
|
---|
99 | STDMETHOD(DragHGDrop)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction);
|
---|
100 | STDMETHOD(DragHGPutData)(ULONG uScreenId, IN_BSTR strFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress);
|
---|
101 | STDMETHOD(DragGHPending)(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction);
|
---|
102 | STDMETHOD(DragGHDropped)(IN_BSTR strFormat, DragAndDropAction_T action, IProgress **ppProgress);
|
---|
103 | STDMETHOD(DragGHGetData)(ComSafeArrayOut(BYTE, data));
|
---|
104 | // Guest control.
|
---|
105 | STDMETHOD(CreateSession)(IN_BSTR aUser, IN_BSTR aPassword, IN_BSTR aDomain, IN_BSTR aSessionName, IGuestSession **aGuestSession);
|
---|
106 | STDMETHOD(FindSession)(IN_BSTR aSessionName, ComSafeArrayOut(IGuestSession *, aSessions));
|
---|
107 | // Misc stuff
|
---|
108 | STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
109 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
|
---|
110 | ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
|
---|
111 | STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(AdditionsUpdateFlag_T, aFlags), IProgress **aProgress);
|
---|
112 |
|
---|
113 | public:
|
---|
114 | /** @name Static internal methods.
|
---|
115 | * @{ */
|
---|
116 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
117 | /** Static callback for handling guest control notifications. */
|
---|
118 | static DECLCALLBACK(int) notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvData, uint32_t cbData);
|
---|
119 | static DECLCALLBACK(void) staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
|
---|
120 | #endif
|
---|
121 | /** @} */
|
---|
122 |
|
---|
123 | public:
|
---|
124 | /** @name Public internal methods.
|
---|
125 | * @{ */
|
---|
126 | void enableVMMStatistics(BOOL aEnable) { mCollectVMMStats = aEnable; };
|
---|
127 | void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
|
---|
128 | void setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures);
|
---|
129 | bool facilityIsActive(VBoxGuestFacilityType enmFacility);
|
---|
130 | void facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
131 | void setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
132 | void setSupportedFeatures(uint32_t aCaps);
|
---|
133 | HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
134 | BOOL isPageFusionEnabled();
|
---|
135 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
136 | const Utf8Str &aText)
|
---|
137 | {
|
---|
138 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
139 | }
|
---|
140 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
141 | int dispatchToSession(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
142 | uint32_t getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
|
---|
143 | Console *getConsole(void) { return mParent; }
|
---|
144 | int sessionRemove(GuestSession *pSession);
|
---|
145 | int sessionCreate(const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds, ComObjPtr<GuestSession> &pGuestSession);
|
---|
146 | inline bool sessionExists(uint32_t uSessionID);
|
---|
147 | #endif
|
---|
148 | /** @} */
|
---|
149 |
|
---|
150 | private:
|
---|
151 | /** @name Private internal methods.
|
---|
152 | * @{ */
|
---|
153 | void updateStats(uint64_t iTick);
|
---|
154 | static int staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
|
---|
155 | STAMVISIBILITY enmVisiblity, const char *pszDesc, void *pvUser);
|
---|
156 | /** @} */
|
---|
157 |
|
---|
158 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
|
---|
159 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
|
---|
160 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
|
---|
161 |
|
---|
162 | /** Map for keeping the guest sessions. The primary key marks the guest session ID. */
|
---|
163 | typedef std::map <uint32_t, ComObjPtr<GuestSession> > GuestSessions;
|
---|
164 |
|
---|
165 | struct Data
|
---|
166 | {
|
---|
167 | Data() : mAdditionsRunLevel(AdditionsRunLevelType_None)
|
---|
168 | , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
|
---|
169 | { }
|
---|
170 |
|
---|
171 | Bstr mOSTypeId;
|
---|
172 | FacilityMap mFacilityMap;
|
---|
173 | AdditionsRunLevelType_T mAdditionsRunLevel;
|
---|
174 | uint32_t mAdditionsVersionFull;
|
---|
175 | Bstr mAdditionsVersionNew;
|
---|
176 | uint32_t mAdditionsRevision;
|
---|
177 | uint32_t mAdditionsFeatures;
|
---|
178 | Bstr mInterfaceVersion;
|
---|
179 | GuestSessions mGuestSessions;
|
---|
180 | uint32_t mNextSessionID;
|
---|
181 | } mData;
|
---|
182 |
|
---|
183 | ULONG mMemoryBalloonSize;
|
---|
184 | ULONG mStatUpdateInterval;
|
---|
185 | uint64_t mNetStatRx;
|
---|
186 | uint64_t mNetStatTx;
|
---|
187 | uint64_t mNetStatLastTs;
|
---|
188 | ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
|
---|
189 | ULONG mVmValidStats;
|
---|
190 | BOOL mCollectVMMStats;
|
---|
191 | BOOL mfPageFusionEnabled;
|
---|
192 |
|
---|
193 | Console *mParent;
|
---|
194 |
|
---|
195 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
196 | /**
|
---|
197 | * This can safely be used without holding any locks.
|
---|
198 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
199 | * internally there is a lock providing the necessary serialization.
|
---|
200 | */
|
---|
201 | const ComObjPtr<EventSource> mEventSource;
|
---|
202 | /** General extension callback for guest control. */
|
---|
203 | HGCMSVCEXTHANDLE mhExtCtrl;
|
---|
204 | #endif
|
---|
205 |
|
---|
206 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
207 | GuestDnD *m_pGuestDnD;
|
---|
208 | friend class GuestDnD;
|
---|
209 | friend class GuestDnDPrivate;
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | RTTIMERLR mStatTimer;
|
---|
213 | uint32_t mMagic;
|
---|
214 | };
|
---|
215 | #define GUEST_MAGIC 0xCEED2006u
|
---|
216 |
|
---|
217 | #endif // ____H_GUESTIMPL
|
---|
218 |
|
---|