VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/GuestImpl.cpp@ 35984

Last change on this file since 35984 was 35977, checked in by vboxsync, 14 years ago

Main: Fixed resizing/seamless mode because of missing facility status.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
Line 
1/* $Id: GuestImpl.cpp 35977 2011-02-15 12:44:02Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation: Guest
4 */
5
6/*
7 * Copyright (C) 2006-2011 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#include "GuestImpl.h"
19
20#include "Global.h"
21#include "ConsoleImpl.h"
22#include "ProgressImpl.h"
23#include "VMMDev.h"
24
25#include "AutoCaller.h"
26#include "Logging.h"
27
28#include <VBox/VMMDev.h>
29#ifdef VBOX_WITH_GUEST_CONTROL
30# include <VBox/com/array.h>
31# include <VBox/com/ErrorInfo.h>
32#endif
33#include <iprt/cpp/utils.h>
34#include <VBox/vmm/pgm.h>
35
36// defines
37/////////////////////////////////////////////////////////////////////////////
38
39// constructor / destructor
40/////////////////////////////////////////////////////////////////////////////
41
42DEFINE_EMPTY_CTOR_DTOR (Guest)
43
44HRESULT Guest::FinalConstruct()
45{
46 return BaseFinalConstruct();
47}
48
49void Guest::FinalRelease()
50{
51 uninit ();
52 BaseFinalRelease();
53}
54
55// public methods only for internal purposes
56/////////////////////////////////////////////////////////////////////////////
57
58/**
59 * Initializes the guest object.
60 */
61HRESULT Guest::init(Console *aParent)
62{
63 LogFlowThisFunc(("aParent=%p\n", aParent));
64
65 ComAssertRet(aParent, E_INVALIDARG);
66
67 /* Enclose the state transition NotReady->InInit->Ready */
68 AutoInitSpan autoInitSpan(this);
69 AssertReturn(autoInitSpan.isOk(), E_FAIL);
70
71 unconst(mParent) = aParent;
72
73 /* Confirm a successful initialization when it's the case */
74 autoInitSpan.setSucceeded();
75
76 ULONG aMemoryBalloonSize;
77 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
78 if (ret == S_OK)
79 mMemoryBalloonSize = aMemoryBalloonSize;
80 else
81 mMemoryBalloonSize = 0; /* Default is no ballooning */
82
83 BOOL fPageFusionEnabled;
84 ret = mParent->machine()->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
85 if (ret == S_OK)
86 mfPageFusionEnabled = fPageFusionEnabled;
87 else
88 mfPageFusionEnabled = false; /* Default is no page fusion*/
89
90 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
91
92 /* Clear statistics. */
93 for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
94 mCurrentGuestStat[i] = 0;
95
96#ifdef VBOX_WITH_GUEST_CONTROL
97 /* Init the context ID counter at 1000. */
98 mNextContextID = 1000;
99#endif
100
101 return S_OK;
102}
103
104/**
105 * Uninitializes the instance and sets the ready flag to FALSE.
106 * Called either from FinalRelease() or by the parent when it gets destroyed.
107 */
108void Guest::uninit()
109{
110 LogFlowThisFunc(("\n"));
111
112#ifdef VBOX_WITH_GUEST_CONTROL
113 /* Scope write lock as much as possible. */
114 {
115 /*
116 * Cleanup must be done *before* AutoUninitSpan to cancel all
117 * all outstanding waits in API functions (which hold AutoCaller
118 * ref counts).
119 */
120 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
121
122 /* Clean up callback data. */
123 CallbackMapIter it;
124 for (it = mCallbackMap.begin(); it != mCallbackMap.end(); it++)
125 destroyCtrlCallbackContext(it);
126
127 /* Clear process map. */
128 mGuestProcessMap.clear();
129 }
130#endif
131
132 /* Enclose the state transition Ready->InUninit->NotReady */
133 AutoUninitSpan autoUninitSpan(this);
134 if (autoUninitSpan.uninitDone())
135 return;
136
137 unconst(mParent) = NULL;
138}
139
140// IGuest properties
141/////////////////////////////////////////////////////////////////////////////
142
143STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
144{
145 CheckComArgOutPointerValid(aOSTypeId);
146
147 AutoCaller autoCaller(this);
148 if (FAILED(autoCaller.rc())) return autoCaller.rc();
149
150 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
151
152 /* Redirect the call to IMachine if no additions are installed. */
153 if (mData.mAdditionsVersion.isEmpty())
154 return mParent->machine()->COMGETTER(OSTypeId)(aOSTypeId);
155
156 mData.mOSTypeId.cloneTo(aOSTypeId);
157
158 return S_OK;
159}
160
161STDMETHODIMP Guest::COMGETTER(AdditionsRunLevel) (AdditionsRunLevelType_T *aRunLevel)
162{
163 AutoCaller autoCaller(this);
164 if (FAILED(autoCaller.rc())) return autoCaller.rc();
165
166 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
167
168 *aRunLevel = mData.mAdditionsRunLevel;
169
170 return S_OK;
171}
172
173STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
174{
175 CheckComArgOutPointerValid(aAdditionsVersion);
176
177 AutoCaller autoCaller(this);
178 if (FAILED(autoCaller.rc())) return autoCaller.rc();
179
180 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
181
182 HRESULT hr = S_OK;
183 if ( mData.mAdditionsVersion.isEmpty()
184 /* Only try alternative way if GA are active! */
185 && mData.mAdditionsRunLevel > AdditionsRunLevelType_None)
186 {
187 /*
188 * If we got back an empty string from GetAdditionsVersion() we either
189 * really don't have the Guest Additions version yet or the guest is running
190 * older Guest Additions (< 3.2.0) which don't provide VMMDevReq_ReportGuestInfo2,
191 * so get the version + revision from the (hopefully) provided guest properties
192 * instead.
193 */
194 Bstr addVersion;
195 LONG64 u64Timestamp;
196 Bstr flags;
197 hr = mParent->machine()->GetGuestProperty(Bstr("/VirtualBox/GuestAdd/Version").raw(),
198 addVersion.asOutParam(), &u64Timestamp, flags.asOutParam());
199 if (hr == S_OK)
200 {
201 Bstr addRevision;
202 hr = mParent->machine()->GetGuestProperty(Bstr("/VirtualBox/GuestAdd/Revision").raw(),
203 addRevision.asOutParam(), &u64Timestamp, flags.asOutParam());
204 if ( hr == S_OK
205 && !addVersion.isEmpty()
206 && !addRevision.isEmpty())
207 {
208 /* Some Guest Additions versions had interchanged version + revision values,
209 * so check if the version value at least has a dot to identify it and change
210 * both values to reflect the right content. */
211 if (!Utf8Str(addVersion).contains("."))
212 {
213 Bstr addTemp = addVersion;
214 addVersion = addRevision;
215 addRevision = addTemp;
216 }
217
218 Bstr additionsVersion = BstrFmt("%ls r%ls",
219 addVersion.raw(), addRevision.raw());
220 additionsVersion.cloneTo(aAdditionsVersion);
221 }
222 /** @todo r=bird: else: Should not return failure! */
223 }
224 else
225 {
226 /* If getting the version + revision above fails or they simply aren't there
227 * because of *really* old Guest Additions we only can report the interface
228 * version to at least have something. */
229 mData.mInterfaceVersion.cloneTo(aAdditionsVersion);
230 /** @todo r=bird: hr is still indicating failure! */
231 }
232 }
233 else
234 mData.mAdditionsVersion.cloneTo(aAdditionsVersion);
235
236 return hr;
237}
238
239STDMETHODIMP Guest::COMGETTER(Facilities)(ComSafeArrayOut(IAdditionsFacility*, aFacilities))
240{
241 CheckComArgOutPointerValid(aFacilities);
242
243 AutoCaller autoCaller(this);
244 if (FAILED(autoCaller.rc())) return autoCaller.rc();
245
246 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
247
248 SafeIfaceArray<IAdditionsFacility> fac(mData.mFacilityMap);
249 fac.detachTo(ComSafeArrayOutArg(aFacilities));
250
251 return S_OK;
252}
253
254BOOL Guest::isPageFusionEnabled()
255{
256 AutoCaller autoCaller(this);
257 if (FAILED(autoCaller.rc())) return false;
258
259 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
260
261 return mfPageFusionEnabled;
262}
263
264STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize)(ULONG *aMemoryBalloonSize)
265{
266 CheckComArgOutPointerValid(aMemoryBalloonSize);
267
268 AutoCaller autoCaller(this);
269 if (FAILED(autoCaller.rc())) return autoCaller.rc();
270
271 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
272
273 *aMemoryBalloonSize = mMemoryBalloonSize;
274
275 return S_OK;
276}
277
278STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize)(ULONG aMemoryBalloonSize)
279{
280 AutoCaller autoCaller(this);
281 if (FAILED(autoCaller.rc())) return autoCaller.rc();
282
283 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
284
285 /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
286 * does not call us back in any way! */
287 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
288 if (ret == S_OK)
289 {
290 mMemoryBalloonSize = aMemoryBalloonSize;
291 /* forward the information to the VMM device */
292 VMMDev *pVMMDev = mParent->getVMMDev();
293 /* MUST release all locks before calling VMM device as its critsect
294 * has higher lock order than anything in Main. */
295 alock.release();
296 if (pVMMDev)
297 {
298 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
299 if (pVMMDevPort)
300 pVMMDevPort->pfnSetMemoryBalloon(pVMMDevPort, aMemoryBalloonSize);
301 }
302 }
303
304 return ret;
305}
306
307STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval)(ULONG *aUpdateInterval)
308{
309 CheckComArgOutPointerValid(aUpdateInterval);
310
311 AutoCaller autoCaller(this);
312 if (FAILED(autoCaller.rc())) return autoCaller.rc();
313
314 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
315
316 *aUpdateInterval = mStatUpdateInterval;
317 return S_OK;
318}
319
320STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval)(ULONG aUpdateInterval)
321{
322 AutoCaller autoCaller(this);
323 if (FAILED(autoCaller.rc())) return autoCaller.rc();
324
325 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
326
327 mStatUpdateInterval = aUpdateInterval;
328 /* forward the information to the VMM device */
329 VMMDev *pVMMDev = mParent->getVMMDev();
330 /* MUST release all locks before calling VMM device as its critsect
331 * has higher lock order than anything in Main. */
332 alock.release();
333 if (pVMMDev)
334 {
335 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
336 if (pVMMDevPort)
337 pVMMDevPort->pfnSetStatisticsInterval(pVMMDevPort, aUpdateInterval);
338 }
339
340 return S_OK;
341}
342
343STDMETHODIMP Guest::InternalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
344 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared,
345 ULONG *aMemCache, ULONG *aPageTotal,
346 ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
347{
348 CheckComArgOutPointerValid(aCpuUser);
349 CheckComArgOutPointerValid(aCpuKernel);
350 CheckComArgOutPointerValid(aCpuIdle);
351 CheckComArgOutPointerValid(aMemTotal);
352 CheckComArgOutPointerValid(aMemFree);
353 CheckComArgOutPointerValid(aMemBalloon);
354 CheckComArgOutPointerValid(aMemShared);
355 CheckComArgOutPointerValid(aMemCache);
356 CheckComArgOutPointerValid(aPageTotal);
357 CheckComArgOutPointerValid(aMemAllocTotal);
358 CheckComArgOutPointerValid(aMemFreeTotal);
359 CheckComArgOutPointerValid(aMemBalloonTotal);
360 CheckComArgOutPointerValid(aMemSharedTotal);
361
362 AutoCaller autoCaller(this);
363 if (FAILED(autoCaller.rc())) return autoCaller.rc();
364
365 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
366
367 *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
368 *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
369 *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
370 *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
371 *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
372 *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
373 *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
374 *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
375
376 /* MUST release all locks before calling any PGM statistics queries,
377 * as they are executed by EMT and that might deadlock us by VMM device
378 * activity which waits for the Guest object lock. */
379 alock.release();
380 Console::SafeVMPtr pVM (mParent);
381 if (pVM.isOk())
382 {
383 uint64_t uFreeTotal, uAllocTotal, uBalloonedTotal, uSharedTotal;
384 *aMemFreeTotal = 0;
385 int rc = PGMR3QueryVMMMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal, &uSharedTotal);
386 AssertRC(rc);
387 if (rc == VINF_SUCCESS)
388 {
389 *aMemAllocTotal = (ULONG)(uAllocTotal / _1K); /* bytes -> KB */
390 *aMemFreeTotal = (ULONG)(uFreeTotal / _1K);
391 *aMemBalloonTotal = (ULONG)(uBalloonedTotal / _1K);
392 *aMemSharedTotal = (ULONG)(uSharedTotal / _1K);
393 }
394
395 /* Query the missing per-VM memory statistics. */
396 *aMemShared = 0;
397 uint64_t uTotalMem, uPrivateMem, uSharedMem, uZeroMem;
398 rc = PGMR3QueryMemoryStats(pVM.raw(), &uTotalMem, &uPrivateMem, &uSharedMem, &uZeroMem);
399 if (rc == VINF_SUCCESS)
400 {
401 *aMemShared = (ULONG)(uSharedMem / _1K);
402 }
403 }
404 else
405 {
406 *aMemFreeTotal = 0;
407 *aMemShared = 0;
408 }
409
410 return S_OK;
411}
412
413HRESULT Guest::setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
414{
415 AutoCaller autoCaller(this);
416 if (FAILED(autoCaller.rc())) return autoCaller.rc();
417
418 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
419
420 if (enmType >= GUESTSTATTYPE_MAX)
421 return E_INVALIDARG;
422
423 mCurrentGuestStat[enmType] = aVal;
424 return S_OK;
425}
426
427/**
428 * Returns the status of a specified Guest Additions facility.
429 *
430 * @return aStatus Current status of specified facility.
431 * @param aType Facility to get the status from.
432 * @param aTimestamp Timestamp of last facility status update in ms (optional).
433 */
434STDMETHODIMP Guest::GetFacilityStatus(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
435{
436 AutoCaller autoCaller(this);
437 if (FAILED(autoCaller.rc())) return autoCaller.rc();
438
439 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
440
441 CheckComArgNotNull(aStatus);
442 /* Not checking for aTimestamp is intentional; it's optional. */
443
444 FacilityMapIterConst it = mData.mFacilityMap.find(aType);
445 if (it != mData.mFacilityMap.end())
446 {
447 AdditionsFacility *pFacility = it->second;
448 ComAssert(pFacility);
449 *aStatus = pFacility->getStatus();
450 if (aTimestamp)
451 *aTimestamp = pFacility->getLastUpdated();
452 }
453 else
454 {
455 /*
456 * Do not fail here -- could be that the facility never has been brought up (yet) but
457 * the host wants to have its status anyway. So just tell we don't know at this point.
458 */
459 *aStatus = AdditionsFacilityStatus_Unknown;
460 if (aTimestamp)
461 *aTimestamp = RTTimeMilliTS();
462 }
463 return S_OK;
464}
465
466STDMETHODIMP Guest::GetAdditionsStatus(AdditionsRunLevelType_T aLevel, BOOL *aActive)
467{
468 AutoCaller autoCaller(this);
469 if (FAILED(autoCaller.rc())) return autoCaller.rc();
470
471 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
472
473 HRESULT rc = S_OK;
474 switch (aLevel)
475 {
476 case AdditionsRunLevelType_System:
477 *aActive = (mData.mAdditionsRunLevel > AdditionsRunLevelType_None);
478 break;
479
480 case AdditionsRunLevelType_Userland:
481 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Userland);
482 break;
483
484 case AdditionsRunLevelType_Desktop:
485 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Desktop);
486 break;
487
488 default:
489 rc = setError(VBOX_E_NOT_SUPPORTED,
490 tr("Invalid status level defined: %u"), aLevel);
491 break;
492 }
493
494 return rc;
495}
496
497STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
498 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
499{
500 AutoCaller autoCaller(this);
501 if (FAILED(autoCaller.rc())) return autoCaller.rc();
502
503 /* forward the information to the VMM device */
504 VMMDev *pVMMDev = mParent->getVMMDev();
505 if (pVMMDev)
506 {
507 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
508 if (pVMMDevPort)
509 {
510 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
511 if (!aAllowInteractiveLogon)
512 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
513
514 pVMMDevPort->pfnSetCredentials(pVMMDevPort,
515 Utf8Str(aUserName).c_str(),
516 Utf8Str(aPassword).c_str(),
517 Utf8Str(aDomain).c_str(),
518 u32Flags);
519 return S_OK;
520 }
521 }
522
523 return setError(VBOX_E_VM_ERROR,
524 tr("VMM device is not available (is the VM running?)"));
525}
526
527// public methods only for internal purposes
528/////////////////////////////////////////////////////////////////////////////
529
530/**
531 * Sets the general Guest Additions information like
532 * API (interface) version and OS type. Gets called by
533 * vmmdevUpdateGuestInfo.
534 *
535 * @param aInterfaceVersion
536 * @param aOsType
537 */
538void Guest::setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType)
539{
540 AutoCaller autoCaller(this);
541 AssertComRCReturnVoid(autoCaller.rc());
542
543 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
544
545 /*
546 * Note: The Guest Additions API (interface) version is deprecated
547 * and will not be used anymore! We might need it to at least report
548 * something as version number if *really* ancient Guest Additions are
549 * installed (without the guest version + revision properties having set).
550 */
551 mData.mInterfaceVersion = aInterfaceVersion;
552
553 /*
554 * Older Additions rely on the Additions API version whether they
555 * are assumed to be active or not. Since newer Additions do report
556 * the Additions version *before* calling this function (by calling
557 * VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
558 * in that order) we can tell apart old and new Additions here. Old
559 * Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
560 * so they just rely on the aInterfaceVersion string (which gets set by
561 * VMMDevReportGuestInfo).
562 *
563 * So only mark the Additions as being active (run level = system) when we
564 * don't have the Additions version set.
565 */
566 if (mData.mAdditionsVersion.isEmpty())
567 {
568 if (aInterfaceVersion.isEmpty())
569 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
570 else
571 {
572 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
573
574 /*
575 * To keep it compatible with the old Guest Additions behavior we need to set the
576 * "graphics" (feature) facility to active as soon as we got the Guest Additions
577 * interface version.
578 */
579 facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active);
580 }
581 }
582
583 /*
584 * Older Additions didn't have this finer grained capability bit,
585 * so enable it by default. Newer Additions will not enable this here
586 * and use the setSupportedFeatures function instead.
587 */
588 facilityUpdate(VBoxGuestFacilityType_Graphics, facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver) ?
589 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
590
591 /*
592 * Note! There is a race going on between setting mAdditionsRunLevel and
593 * mSupportsGraphics here and disabling/enabling it later according to
594 * its real status when using new(er) Guest Additions.
595 */
596 mData.mOSTypeId = Global::OSTypeId (aOsType);
597}
598
599/**
600 * Sets the Guest Additions version information details.
601 * Gets called by vmmdevUpdateGuestInfo2.
602 *
603 * @param aAdditionsVersion
604 * @param aVersionName
605 */
606void Guest::setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision)
607{
608 AutoCaller autoCaller(this);
609 AssertComRCReturnVoid(autoCaller.rc());
610
611 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
612
613 if (!aVersionName.isEmpty())
614 /*
615 * aVersionName could be "x.y.z_BETA1_FOOBAR", so append revision manually to
616 * become "x.y.z_BETA1_FOOBAR r12345".
617 */
618 mData.mAdditionsVersion = BstrFmt("%ls r%ls", aVersionName.raw(), aRevision.raw());
619 else /* aAdditionsVersion is in x.y.zr12345 format. */
620 mData.mAdditionsVersion = aAdditionsVersion;
621}
622
623bool Guest::facilityIsActive(VBoxGuestFacilityType enmFacility)
624{
625 Assert(enmFacility < INT32_MAX);
626 FacilityMapIterConst it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
627 if (it != mData.mFacilityMap.end())
628 {
629 AdditionsFacility *pFac = it->second;
630 return (pFac->getStatus() == AdditionsFacilityStatus_Active);
631 }
632 return false;
633}
634
635HRESULT Guest::facilityUpdate(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus)
636{
637 ComAssertRet(enmFacility < INT32_MAX, E_INVALIDARG);
638
639 HRESULT rc;
640 RTTIMESPEC tsNow;
641 RTTimeNow(&tsNow);
642
643 FacilityMapIter it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
644 if (it != mData.mFacilityMap.end())
645 {
646 AdditionsFacility *pFac = it->second;
647 rc = pFac->update((AdditionsFacilityStatus_T)enmStatus, tsNow);
648 }
649 else
650 {
651 ComObjPtr<AdditionsFacility> pFacility;
652 pFacility.createObject();
653 ComAssert(!pFacility.isNull());
654 rc = pFacility->init(this,
655 (AdditionsFacilityType_T)enmFacility,
656 (AdditionsFacilityStatus_T)enmStatus);
657 if (SUCCEEDED(rc))
658 mData.mFacilityMap.insert(std::make_pair((AdditionsFacilityType_T)enmFacility, pFacility));
659 }
660
661 LogFlowFunc(("Returned with rc=%Rrc\n"));
662 return rc;
663}
664
665/**
666 * Sets the status of a certain Guest Additions facility.
667 * Gets called by vmmdevUpdateGuestStatus.
668 *
669 * @param enmFacility Facility to set the status for.
670 * @param enmStatus Actual status to set.
671 * @param aFlags
672 */
673void Guest::setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags)
674{
675 AutoCaller autoCaller(this);
676 AssertComRCReturnVoid(autoCaller.rc());
677
678 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
679
680 /*
681 * Set overall additions run level.
682 */
683
684 /* First check for disabled status. */
685 uint32_t uCurFacility = enmFacility + (enmStatus == VBoxGuestFacilityStatus_Active ? 0 : -1);
686 if ( enmFacility < VBoxGuestFacilityType_VBoxGuestDriver
687 || ( enmFacility == VBoxGuestFacilityType_All
688 && enmStatus == VBoxGuestFacilityStatus_Inactive)
689 )
690 {
691 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
692 }
693 else if (uCurFacility >= VBoxGuestFacilityType_VBoxTrayClient)
694 {
695 mData.mAdditionsRunLevel = AdditionsRunLevelType_Desktop;
696 }
697 else if (uCurFacility >= VBoxGuestFacilityType_VBoxService)
698 {
699 mData.mAdditionsRunLevel = AdditionsRunLevelType_Userland;
700 }
701 else if (uCurFacility >= VBoxGuestFacilityType_VBoxGuestDriver)
702 {
703 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
704 }
705 else /* Should never happen! */
706 AssertMsgFailed(("Invalid facility status/run level detected! uCurFacility=%ld\n", uCurFacility));
707
708 /*
709 * Set a specific facility status.
710 */
711 if (enmFacility > VBoxGuestFacilityType_Unknown)
712 {
713 if (enmFacility == VBoxGuestFacilityType_All)
714 {
715 FacilityMapIter it = mData.mFacilityMap.begin();
716 while (it != mData.mFacilityMap.end())
717 {
718 facilityUpdate((VBoxGuestFacilityType)it->first, enmStatus);
719 it++;
720 }
721 }
722 else /* Update one facility only. */
723 facilityUpdate(enmFacility, enmStatus);
724 }
725}
726
727/**
728 * Sets the supported features (and whether they are active or not).
729 *
730 * @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
731 */
732void Guest::setSupportedFeatures(uint32_t aCaps)
733{
734 AutoCaller autoCaller(this);
735 AssertComRCReturnVoid(autoCaller.rc());
736
737 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
738
739 facilityUpdate(VBoxGuestFacilityType_Seamless, aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ?
740 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
741 /** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
742 facilityUpdate(VBoxGuestFacilityType_Graphics, aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ?
743 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
744}
745/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette