1 | /* $Id: GuestImpl.cpp 26186 2010-02-03 13:07:12Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "GuestImpl.h"
|
---|
25 |
|
---|
26 | #include "Global.h"
|
---|
27 | #include "ConsoleImpl.h"
|
---|
28 | #include "VMMDev.h"
|
---|
29 |
|
---|
30 | #include "AutoCaller.h"
|
---|
31 | #include "Logging.h"
|
---|
32 |
|
---|
33 | #include <VBox/VMMDev.h>
|
---|
34 | #include <iprt/cpp/utils.h>
|
---|
35 |
|
---|
36 | // defines
|
---|
37 | /////////////////////////////////////////////////////////////////////////////
|
---|
38 |
|
---|
39 | // constructor / destructor
|
---|
40 | /////////////////////////////////////////////////////////////////////////////
|
---|
41 |
|
---|
42 | DEFINE_EMPTY_CTOR_DTOR (Guest)
|
---|
43 |
|
---|
44 | HRESULT Guest::FinalConstruct()
|
---|
45 | {
|
---|
46 | return S_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | void Guest::FinalRelease()
|
---|
50 | {
|
---|
51 | uninit ();
|
---|
52 | }
|
---|
53 |
|
---|
54 | // public methods only for internal purposes
|
---|
55 | /////////////////////////////////////////////////////////////////////////////
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Initializes the guest object.
|
---|
59 | */
|
---|
60 | HRESULT Guest::init (Console *aParent)
|
---|
61 | {
|
---|
62 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
63 |
|
---|
64 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
65 |
|
---|
66 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
67 | AutoInitSpan autoInitSpan(this);
|
---|
68 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
69 |
|
---|
70 | unconst(mParent) = aParent;
|
---|
71 |
|
---|
72 | /* mData.mAdditionsActive is FALSE */
|
---|
73 |
|
---|
74 | /* Confirm a successful initialization when it's the case */
|
---|
75 | autoInitSpan.setSucceeded();
|
---|
76 |
|
---|
77 | ULONG aMemoryBalloonSize;
|
---|
78 | HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
|
---|
79 | if (ret == S_OK)
|
---|
80 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
81 | else
|
---|
82 | mMemoryBalloonSize = 0; /* Default is no ballooning */
|
---|
83 |
|
---|
84 | ULONG aStatUpdateInterval;
|
---|
85 | ret = mParent->machine()->COMGETTER(StatisticsUpdateInterval)(&aStatUpdateInterval);
|
---|
86 | if (ret == S_OK)
|
---|
87 | mStatUpdateInterval = aStatUpdateInterval;
|
---|
88 | else
|
---|
89 | mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
|
---|
90 |
|
---|
91 | /* invalidate all stats */
|
---|
92 | for (int i=0;i<GuestStatisticType_MaxVal;i++)
|
---|
93 | mCurrentGuestStat[i] = GUEST_STAT_INVALID;
|
---|
94 |
|
---|
95 | /* start with sample 0 */
|
---|
96 | mCurrentGuestStat[GuestStatisticType_SampleNumber] = 0;
|
---|
97 | return S_OK;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
102 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
103 | */
|
---|
104 | void Guest::uninit()
|
---|
105 | {
|
---|
106 | LogFlowThisFunc(("\n"));
|
---|
107 |
|
---|
108 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
109 | AutoUninitSpan autoUninitSpan(this);
|
---|
110 | if (autoUninitSpan.uninitDone())
|
---|
111 | return;
|
---|
112 |
|
---|
113 | unconst(mParent).setNull();
|
---|
114 | }
|
---|
115 |
|
---|
116 | // IGuest properties
|
---|
117 | /////////////////////////////////////////////////////////////////////////////
|
---|
118 |
|
---|
119 | STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
|
---|
120 | {
|
---|
121 | CheckComArgOutPointerValid(aOSTypeId);
|
---|
122 |
|
---|
123 | AutoCaller autoCaller(this);
|
---|
124 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
125 |
|
---|
126 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
127 |
|
---|
128 | // redirect the call to IMachine if no additions are installed
|
---|
129 | if (mData.mAdditionsVersion.isNull())
|
---|
130 | return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
|
---|
131 |
|
---|
132 | mData.mOSTypeId.cloneTo(aOSTypeId);
|
---|
133 |
|
---|
134 | return S_OK;
|
---|
135 | }
|
---|
136 |
|
---|
137 | STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
|
---|
138 | {
|
---|
139 | CheckComArgOutPointerValid(aAdditionsActive);
|
---|
140 |
|
---|
141 | AutoCaller autoCaller(this);
|
---|
142 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
143 |
|
---|
144 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
145 |
|
---|
146 | *aAdditionsActive = mData.mAdditionsActive;
|
---|
147 |
|
---|
148 | return S_OK;
|
---|
149 | }
|
---|
150 |
|
---|
151 | STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
|
---|
152 | {
|
---|
153 | CheckComArgOutPointerValid(aAdditionsVersion);
|
---|
154 |
|
---|
155 | AutoCaller autoCaller(this);
|
---|
156 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
157 |
|
---|
158 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
159 |
|
---|
160 | mData.mAdditionsVersion.cloneTo(aAdditionsVersion);
|
---|
161 |
|
---|
162 | return S_OK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
|
---|
166 | {
|
---|
167 | CheckComArgOutPointerValid(aSupportsSeamless);
|
---|
168 |
|
---|
169 | AutoCaller autoCaller(this);
|
---|
170 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
171 |
|
---|
172 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
173 |
|
---|
174 | *aSupportsSeamless = mData.mSupportsSeamless;
|
---|
175 |
|
---|
176 | return S_OK;
|
---|
177 | }
|
---|
178 |
|
---|
179 | STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
|
---|
180 | {
|
---|
181 | CheckComArgOutPointerValid(aSupportsGraphics);
|
---|
182 |
|
---|
183 | AutoCaller autoCaller(this);
|
---|
184 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
185 |
|
---|
186 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
187 |
|
---|
188 | *aSupportsGraphics = mData.mSupportsGraphics;
|
---|
189 |
|
---|
190 | return S_OK;
|
---|
191 | }
|
---|
192 |
|
---|
193 | STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
|
---|
194 | {
|
---|
195 | CheckComArgOutPointerValid(aMemoryBalloonSize);
|
---|
196 |
|
---|
197 | AutoCaller autoCaller(this);
|
---|
198 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
199 |
|
---|
200 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
201 |
|
---|
202 | *aMemoryBalloonSize = mMemoryBalloonSize;
|
---|
203 |
|
---|
204 | return S_OK;
|
---|
205 | }
|
---|
206 |
|
---|
207 | STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
|
---|
208 | {
|
---|
209 | AutoCaller autoCaller(this);
|
---|
210 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
211 |
|
---|
212 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
213 |
|
---|
214 | HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
|
---|
215 | if (ret == S_OK)
|
---|
216 | {
|
---|
217 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
218 | /* forward the information to the VMM device */
|
---|
219 | VMMDev *vmmDev = mParent->getVMMDev();
|
---|
220 | if (vmmDev)
|
---|
221 | vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
|
---|
222 | }
|
---|
223 |
|
---|
224 | return ret;
|
---|
225 | }
|
---|
226 |
|
---|
227 | STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
|
---|
228 | {
|
---|
229 | CheckComArgOutPointerValid(aUpdateInterval);
|
---|
230 |
|
---|
231 | AutoCaller autoCaller(this);
|
---|
232 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
233 |
|
---|
234 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
235 |
|
---|
236 | *aUpdateInterval = mStatUpdateInterval;
|
---|
237 |
|
---|
238 | return S_OK;
|
---|
239 | }
|
---|
240 |
|
---|
241 | STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
|
---|
242 | {
|
---|
243 | AutoCaller autoCaller(this);
|
---|
244 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
245 |
|
---|
246 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
247 |
|
---|
248 | HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
|
---|
249 | if (ret == S_OK)
|
---|
250 | {
|
---|
251 | mStatUpdateInterval = aUpdateInterval;
|
---|
252 | /* forward the information to the VMM device */
|
---|
253 | VMMDev *vmmDev = mParent->getVMMDev();
|
---|
254 | if (vmmDev)
|
---|
255 | vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
|
---|
256 | }
|
---|
257 |
|
---|
258 | return ret;
|
---|
259 | }
|
---|
260 |
|
---|
261 | STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
262 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
|
---|
263 | {
|
---|
264 | CheckComArgNotNull(aUserName);
|
---|
265 | CheckComArgNotNull(aPassword);
|
---|
266 | CheckComArgNotNull(aDomain);
|
---|
267 |
|
---|
268 | AutoCaller autoCaller(this);
|
---|
269 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
270 |
|
---|
271 | /* forward the information to the VMM device */
|
---|
272 | VMMDev *vmmDev = mParent->getVMMDev();
|
---|
273 | if (vmmDev)
|
---|
274 | {
|
---|
275 | uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
|
---|
276 | if (!aAllowInteractiveLogon)
|
---|
277 | u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
|
---|
278 |
|
---|
279 | vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
|
---|
280 | Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
|
---|
281 | Utf8Str(aDomain).raw(), u32Flags);
|
---|
282 | return S_OK;
|
---|
283 | }
|
---|
284 |
|
---|
285 | return setError(VBOX_E_VM_ERROR,
|
---|
286 | tr("VMM device is not available (is the VM running?)"));
|
---|
287 | }
|
---|
288 |
|
---|
289 | STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
|
---|
290 | {
|
---|
291 | CheckComArgExpr(aCpuId, aCpuId == 0);
|
---|
292 | CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
|
---|
293 | CheckComArgOutPointerValid(aStatVal);
|
---|
294 |
|
---|
295 | /* Not available or not yet reported? In that case, just return with a proper error
|
---|
296 | * but don't use setError(). */
|
---|
297 | if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
|
---|
298 | return E_INVALIDARG;
|
---|
299 |
|
---|
300 | *aStatVal = mCurrentGuestStat[aStatistic];
|
---|
301 | return S_OK;
|
---|
302 | }
|
---|
303 |
|
---|
304 | STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
|
---|
305 | {
|
---|
306 | CheckComArgExpr(aCpuId, aCpuId == 0);
|
---|
307 | CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
|
---|
308 |
|
---|
309 | /* internal method assumes that the caller knows what he's doing (no boundary checks) */
|
---|
310 | mCurrentGuestStat[aStatistic] = aStatVal;
|
---|
311 | return S_OK;
|
---|
312 | }
|
---|
313 |
|
---|
314 | // public methods only for internal purposes
|
---|
315 | /////////////////////////////////////////////////////////////////////////////
|
---|
316 |
|
---|
317 | void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
|
---|
318 | {
|
---|
319 | Assert(aVersion.isNull() || !aVersion.isEmpty());
|
---|
320 |
|
---|
321 | AutoCaller autoCaller(this);
|
---|
322 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
323 |
|
---|
324 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
325 |
|
---|
326 | mData.mAdditionsVersion = aVersion;
|
---|
327 | mData.mAdditionsActive = !aVersion.isNull();
|
---|
328 |
|
---|
329 | mData.mOSTypeId = Global::OSTypeId (aOsType);
|
---|
330 | }
|
---|
331 |
|
---|
332 | void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
|
---|
333 | {
|
---|
334 | AutoCaller autoCaller(this);
|
---|
335 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
336 |
|
---|
337 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
338 |
|
---|
339 | mData.mSupportsSeamless = aSupportsSeamless;
|
---|
340 | }
|
---|
341 |
|
---|
342 | void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
|
---|
343 | {
|
---|
344 | AutoCaller autoCaller(this);
|
---|
345 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
346 |
|
---|
347 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
348 |
|
---|
349 | mData.mSupportsGraphics = aSupportsGraphics;
|
---|
350 | }
|
---|
351 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|