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 |
|
---|
25 | #include "AdditionsFacilityImpl.h"
|
---|
26 | #include "GuestCtrlImplPrivate.h"
|
---|
27 | #include "GuestSessionImpl.h"
|
---|
28 | #include "HGCM.h"
|
---|
29 |
|
---|
30 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
31 | class GuestDnD;
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | typedef enum
|
---|
35 | {
|
---|
36 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
37 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
38 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
39 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
40 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
41 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
42 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
43 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
44 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
45 | GUESTSTATTYPE_MAX = 9
|
---|
46 | } GUESTSTATTYPE;
|
---|
47 |
|
---|
48 | class Console;
|
---|
49 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
50 | class Progress;
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | class ATL_NO_VTABLE Guest :
|
---|
54 | public VirtualBoxBase,
|
---|
55 | VBOX_SCRIPTABLE_IMPL(IGuest)
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
|
---|
59 |
|
---|
60 | DECLARE_NOT_AGGREGATABLE(Guest)
|
---|
61 |
|
---|
62 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
63 |
|
---|
64 | BEGIN_COM_MAP(Guest)
|
---|
65 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
|
---|
66 | END_COM_MAP()
|
---|
67 |
|
---|
68 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
69 |
|
---|
70 | HRESULT FinalConstruct(void);
|
---|
71 | void FinalRelease(void);
|
---|
72 |
|
---|
73 | // Public initializer/uninitializer for internal purposes only.
|
---|
74 | HRESULT init (Console *aParent);
|
---|
75 | void uninit();
|
---|
76 |
|
---|
77 | // IGuest properties.
|
---|
78 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
79 | STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
|
---|
80 | STDMETHOD(COMGETTER(AdditionsVersion))(BSTR *a_pbstrAdditionsVersion);
|
---|
81 | STDMETHOD(COMGETTER(AdditionsRevision))(ULONG *a_puAdditionsRevision);
|
---|
82 | STDMETHOD(COMGETTER(Facilities)) (ComSafeArrayOut(IAdditionsFacility *, aFacilities));
|
---|
83 | STDMETHOD(COMGETTER(Sessions)) (ComSafeArrayOut(IGuestSession *, aSessions));
|
---|
84 | STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
|
---|
85 | STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
|
---|
86 | STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
|
---|
87 | STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
|
---|
88 | // IGuest methods.
|
---|
89 | STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
|
---|
90 | STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
|
---|
91 | STDMETHOD(SetCredentials)(IN_BSTR aUsername, IN_BSTR aPassword,
|
---|
92 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
|
---|
93 | // Drag'n drop support.
|
---|
94 | STDMETHOD(DragHGEnter)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
|
---|
95 | STDMETHOD(DragHGMove)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction);
|
---|
96 | STDMETHOD(DragHGLeave)(ULONG uScreenId);
|
---|
97 | STDMETHOD(DragHGDrop)(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction);
|
---|
98 | STDMETHOD(DragHGPutData)(ULONG uScreenId, IN_BSTR strFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress);
|
---|
99 | STDMETHOD(DragGHPending)(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction);
|
---|
100 | STDMETHOD(DragGHDropped)(IN_BSTR strFormat, DragAndDropAction_T action, IProgress **ppProgress);
|
---|
101 | STDMETHOD(DragGHGetData)(ComSafeArrayOut(BYTE, data));
|
---|
102 | // Misc stuff
|
---|
103 | STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
104 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
|
---|
105 | ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
|
---|
106 | STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ComSafeArrayIn(AdditionsUpdateFlag_T, aFlags), IProgress **aProgress);
|
---|
107 | STDMETHOD(CreateSession)(IN_BSTR aUser, IN_BSTR aPassword, IN_BSTR aDomain, IN_BSTR aSessionName, IGuestSession **aGuestSession);
|
---|
108 | STDMETHOD(FindSession)(IN_BSTR aSessionName, ComSafeArrayOut(IGuestSession *, aSessions));
|
---|
109 |
|
---|
110 | public:
|
---|
111 | /** @name Static internal methods.
|
---|
112 | * @{ */
|
---|
113 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
114 | /** Static callback for handling guest control notifications. */
|
---|
115 | static DECLCALLBACK(int) notifyCtrlDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
116 | static void staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
|
---|
117 | #endif
|
---|
118 | /** @} */
|
---|
119 |
|
---|
120 | public:
|
---|
121 | /** @name Public internal methods.
|
---|
122 | * @{ */
|
---|
123 | void enableVMMStatistics(BOOL aEnable) { mCollectVMMStats = aEnable; };
|
---|
124 | void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
|
---|
125 | void setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures);
|
---|
126 | bool facilityIsActive(VBoxGuestFacilityType enmFacility);
|
---|
127 | void facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
128 | void setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS);
|
---|
129 | void setSupportedFeatures(uint32_t aCaps);
|
---|
130 | HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
131 | BOOL isPageFusionEnabled();
|
---|
132 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
133 | const Utf8Str &aText)
|
---|
134 | {
|
---|
135 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
136 | }
|
---|
137 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
138 | int dispatchToSession(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
|
---|
139 | uint32_t getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
|
---|
140 | Console *getConsole(void) { return mParent; }
|
---|
141 | int sessionClose(ComObjPtr<GuestSession> pSession);
|
---|
142 | int sessionCreate(const Utf8Str &strUser, const Utf8Str &strPassword, const Utf8Str &strDomain,
|
---|
143 | const Utf8Str &strSessionName, ComObjPtr<GuestSession> &pGuestSession);
|
---|
144 | inline bool sessionExists(uint32_t uSessionID);
|
---|
145 | #endif
|
---|
146 | /** @} */
|
---|
147 |
|
---|
148 | private:
|
---|
149 | /** @name Private internal methods.
|
---|
150 | * @{ */
|
---|
151 | void updateStats(uint64_t iTick);
|
---|
152 | /** @} */
|
---|
153 |
|
---|
154 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
|
---|
155 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
|
---|
156 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
|
---|
157 |
|
---|
158 | /** Map for keeping the guest sessions. The primary key marks the guest session ID. */
|
---|
159 | typedef std::map <uint32_t, ComObjPtr<GuestSession> > GuestSessions;
|
---|
160 |
|
---|
161 | struct Data
|
---|
162 | {
|
---|
163 | Data() : mAdditionsRunLevel(AdditionsRunLevelType_None)
|
---|
164 | , mAdditionsVersionFull(0), mAdditionsRevision(0), mAdditionsFeatures(0)
|
---|
165 | { }
|
---|
166 |
|
---|
167 | Bstr mOSTypeId;
|
---|
168 | FacilityMap mFacilityMap;
|
---|
169 | AdditionsRunLevelType_T mAdditionsRunLevel;
|
---|
170 | uint32_t mAdditionsVersionFull;
|
---|
171 | Bstr mAdditionsVersionNew;
|
---|
172 | uint32_t mAdditionsRevision;
|
---|
173 | uint32_t mAdditionsFeatures;
|
---|
174 | Bstr mInterfaceVersion;
|
---|
175 | GuestSessions mGuestSessions;
|
---|
176 | uint32_t mNextSessionID;
|
---|
177 | };
|
---|
178 |
|
---|
179 | ULONG mMemoryBalloonSize;
|
---|
180 | ULONG mStatUpdateInterval;
|
---|
181 | ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
|
---|
182 | ULONG mGuestValidStats;
|
---|
183 | BOOL mCollectVMMStats;
|
---|
184 | BOOL mfPageFusionEnabled;
|
---|
185 |
|
---|
186 | Console *mParent;
|
---|
187 | Data mData;
|
---|
188 |
|
---|
189 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
190 | /** General extension callback for guest control. */
|
---|
191 | HGCMSVCEXTHANDLE mhExtCtrl;
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
195 | GuestDnD *m_pGuestDnD;
|
---|
196 | friend class GuestDnD;
|
---|
197 | friend class GuestDnDPrivate;
|
---|
198 | #endif
|
---|
199 |
|
---|
200 | RTTIMERLR mStatTimer;
|
---|
201 | uint32_t mMagic;
|
---|
202 | };
|
---|
203 | #define GUEST_MAGIC 0xCEED2006u
|
---|
204 |
|
---|
205 | #endif // ____H_GUESTIMPL
|
---|
206 |
|
---|