VirtualBox

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

Last change on this file since 45418 was 45415, checked in by vboxsync, 12 years ago

GuestCtrl: Implemented using (public) VirtualBox events instead of own callback mechanisms. Bugfixes for testcases (still work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.2 KB
Line 
1/* $Id: GuestImpl.cpp 45415 2013-04-08 21:40:42Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation: Guest
4 */
5
6/*
7 * Copyright (C) 2006-2013 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#include "GuestSessionImpl.h"
20
21#include "Global.h"
22#include "ConsoleImpl.h"
23#include "ProgressImpl.h"
24#ifdef VBOX_WITH_DRAG_AND_DROP
25# include "GuestDnDImpl.h"
26#endif
27#include "VMMDev.h"
28
29#include "AutoCaller.h"
30#include "Logging.h"
31#include "Performance.h"
32
33#include <VBox/VMMDev.h>
34#include <iprt/cpp/utils.h>
35#include <iprt/ctype.h>
36#include <iprt/stream.h>
37#include <iprt/timer.h>
38#include <VBox/vmm/pgm.h>
39#include <VBox/version.h>
40
41// defines
42/////////////////////////////////////////////////////////////////////////////
43
44// constructor / destructor
45/////////////////////////////////////////////////////////////////////////////
46
47DEFINE_EMPTY_CTOR_DTOR(Guest)
48
49HRESULT Guest::FinalConstruct()
50{
51 return BaseFinalConstruct();
52}
53
54void Guest::FinalRelease()
55{
56 uninit();
57 BaseFinalRelease();
58}
59
60// public methods only for internal purposes
61/////////////////////////////////////////////////////////////////////////////
62
63/**
64 * Initializes the guest object.
65 */
66HRESULT Guest::init(Console *aParent)
67{
68 LogFlowThisFunc(("aParent=%p\n", aParent));
69
70 ComAssertRet(aParent, E_INVALIDARG);
71
72 /* Enclose the state transition NotReady->InInit->Ready */
73 AutoInitSpan autoInitSpan(this);
74 AssertReturn(autoInitSpan.isOk(), E_FAIL);
75
76 unconst(mParent) = aParent;
77
78 /* Confirm a successful initialization when it's the case */
79 autoInitSpan.setSucceeded();
80
81 ULONG aMemoryBalloonSize;
82 HRESULT hr = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
83 if (hr == S_OK) /** @todo r=andy SUCCEEDED? */
84 mMemoryBalloonSize = aMemoryBalloonSize;
85 else
86 mMemoryBalloonSize = 0; /* Default is no ballooning */
87
88 BOOL fPageFusionEnabled;
89 hr = mParent->machine()->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
90 if (hr == S_OK) /** @todo r=andy SUCCEEDED? */
91 mfPageFusionEnabled = fPageFusionEnabled;
92 else
93 mfPageFusionEnabled = false; /* Default is no page fusion*/
94
95 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
96 mCollectVMMStats = false;
97
98 /* Clear statistics. */
99 mNetStatRx = mNetStatTx = 0;
100 mNetStatLastTs = RTTimeNanoTS();
101 for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
102 mCurrentGuestStat[i] = 0;
103 mVmValidStats = pm::VMSTATMASK_NONE;
104
105 mMagic = GUEST_MAGIC;
106 int vrc = RTTimerLRCreate(&mStatTimer, 1000 /* ms */,
107 &Guest::staticUpdateStats, this);
108 AssertMsgRC(vrc, ("Failed to create guest statistics update timer (%Rrc)\n", vrc));
109
110#ifdef VBOX_WITH_GUEST_CONTROL
111 unconst(mEventSource).createObject();
112 Assert(!mEventSource.isNull());
113 hr = mEventSource->init(static_cast<IGuest*>(this));
114#else
115 hr = S_OK;
116#endif
117
118 try
119 {
120#ifdef VBOX_WITH_DRAG_AND_DROP
121 m_pGuestDnD = new GuestDnD(this);
122 AssertPtr(m_pGuestDnD);
123#endif
124 }
125 catch(std::bad_alloc &)
126 {
127 hr = E_OUTOFMEMORY;
128 }
129
130 return hr;
131}
132
133/**
134 * Uninitializes the instance and sets the ready flag to FALSE.
135 * Called either from FinalRelease() or by the parent when it gets destroyed.
136 */
137void Guest::uninit()
138{
139 LogFlowThisFunc(("\n"));
140
141 /* Enclose the state transition Ready->InUninit->NotReady */
142 AutoUninitSpan autoUninitSpan(this);
143 if (autoUninitSpan.uninitDone())
144 return;
145
146 /* Destroy stat update timer */
147 int vrc = RTTimerLRDestroy(mStatTimer);
148 AssertMsgRC(vrc, ("Failed to create guest statistics update timer(%Rra)\n", vrc));
149 mStatTimer = NULL;
150 mMagic = 0;
151
152#ifdef VBOX_WITH_GUEST_CONTROL
153 LogFlowThisFunc(("Closing sessions (%RU64 total)\n",
154 mData.mGuestSessions.size()));
155 GuestSessions::iterator itSessions = mData.mGuestSessions.begin();
156 while (itSessions != mData.mGuestSessions.end())
157 {
158#ifdef DEBUG
159 ULONG cRefs = itSessions->second->AddRef();
160 LogFlowThisFunc(("pSession=%p, cRefs=%RU32\n", (GuestSession *)itSessions->second, cRefs > 0 ? cRefs - 1 : 0));
161 itSessions->second->Release();
162#endif
163 itSessions->second->uninit();
164 itSessions++;
165 }
166 mData.mGuestSessions.clear();
167#endif
168
169#ifdef VBOX_WITH_DRAG_AND_DROP
170 if (m_pGuestDnD)
171 {
172 delete m_pGuestDnD;
173 m_pGuestDnD = NULL;
174 }
175#endif
176
177#ifdef VBOX_WITH_GUEST_CONTROL
178 unconst(mEventSource).setNull();
179#endif
180 unconst(mParent) = NULL;
181
182 LogFlowFuncLeave();
183}
184
185/* static */
186void Guest::staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick)
187{
188 AssertReturnVoid(pvUser != NULL);
189 Guest *guest = static_cast<Guest *>(pvUser);
190 Assert(guest->mMagic == GUEST_MAGIC);
191 if (guest->mMagic == GUEST_MAGIC)
192 guest->updateStats(iTick);
193
194 NOREF(hTimerLR);
195}
196
197/* static */
198int Guest::staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
199 STAMVISIBILITY enmVisiblity, const char *pszDesc, void *pvUser)
200{
201 PSTAMCOUNTER pCnt = (PSTAMCOUNTER)pvSample;
202 char *pszEnd = strrchr((char*)pszName, '/');
203 if (pszEnd)
204 {
205 bool fRx;
206 uint8_t uInstance = 0;
207
208 switch (pszEnd[1])
209 {
210 case 'R':
211 fRx = true;
212 break;
213 case 'T':
214 fRx = false;
215 break;
216 default:
217 LogRel(("Failed to parse the name of network stat counter (unknown counter): %s\n", pszName));
218 return VINF_SUCCESS;
219 }
220 do
221 --pszEnd;
222 while (pszEnd > pszName && RT_C_IS_DIGIT(*pszEnd));
223 if (RT_SUCCESS(RTStrToUInt8Ex(pszEnd + 1, NULL, 10, &uInstance)))
224 {
225 Guest *pGuest = (Guest *)pvUser;
226 LogFlowFunc(("%s i=%u d=%s %llu %s\n", pszName, uInstance, fRx ? "RX" : "TX",
227 pCnt->c, STAMR3GetUnit(enmUnit)));
228 if (fRx)
229 pGuest->mNetStatRx += pCnt->c;
230 else
231 pGuest->mNetStatTx += pCnt->c;
232 }
233 else
234 LogRel(("Failed to extract the device instance from the name of network stat counter: %s\n", pszEnd));
235 }
236 else
237 LogRel(("Failed to parse the name of network stat counter (no slash): %s\n", pszName));
238
239 return VINF_SUCCESS;
240}
241
242void Guest::updateStats(uint64_t iTick)
243{
244 uint64_t cbFreeTotal = 0;
245 uint64_t cbAllocTotal = 0;
246 uint64_t cbBalloonedTotal = 0;
247 uint64_t cbSharedTotal = 0;
248 uint64_t cbSharedMem = 0;
249 ULONG uNetStatRx = 0;
250 ULONG uNetStatTx = 0;
251 ULONG aGuestStats[GUESTSTATTYPE_MAX];
252 RT_ZERO(aGuestStats);
253
254 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
255
256 ULONG validStats = mVmValidStats;
257 /* Check if we have anything to report */
258 if (validStats)
259 {
260 mVmValidStats = pm::VMSTATMASK_NONE;
261 memcpy(aGuestStats, mCurrentGuestStat, sizeof(aGuestStats));
262 }
263 alock.release();
264
265 /*
266 * Calling SessionMachine may take time as the object resides in VBoxSVC
267 * process. This is why we took a snapshot of currently collected stats
268 * and released the lock.
269 */
270 Console::SafeVMPtr ptrVM(mParent);
271 if (ptrVM.isOk())
272 {
273 int rc;
274
275 /*
276 * There is no point in collecting VM shared memory if other memory
277 * statistics are not available yet. Or is there?
278 */
279 if (validStats)
280 {
281 /* Query the missing per-VM memory statistics. */
282 uint64_t cbTotalMemIgn, cbPrivateMemIgn, cbZeroMemIgn;
283 rc = PGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn, &cbSharedMem, &cbZeroMemIgn);
284 if (rc == VINF_SUCCESS)
285 validStats |= pm::VMSTATMASK_GUEST_MEMSHARED;
286 }
287
288 if (mCollectVMMStats)
289 {
290 rc = PGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal, &cbBalloonedTotal, &cbSharedTotal);
291 AssertRC(rc);
292 if (rc == VINF_SUCCESS)
293 validStats |= pm::VMSTATMASK_VMM_ALLOC | pm::VMSTATMASK_VMM_FREE
294 | pm::VMSTATMASK_VMM_BALOON | pm::VMSTATMASK_VMM_SHARED;
295 }
296
297 uint64_t uRxPrev = mNetStatRx;
298 uint64_t uTxPrev = mNetStatTx;
299 mNetStatRx = mNetStatTx = 0;
300 rc = STAMR3Enum(ptrVM.rawUVM(), "*/ReceiveBytes|*/TransmitBytes", staticEnumStatsCallback, this);
301 AssertRC(rc);
302
303 uint64_t uTsNow = RTTimeNanoTS();
304 uint64_t cNsPassed = uTsNow - mNetStatLastTs;
305 if (cNsPassed >= 1000)
306 {
307 mNetStatLastTs = uTsNow;
308
309 uNetStatRx = (ULONG)((mNetStatRx - uRxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
310 uNetStatTx = (ULONG)((mNetStatTx - uTxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
311 validStats |= pm::VMSTATMASK_NET_RX | pm::VMSTATMASK_NET_TX;
312 LogFlowThisFunc(("Net Rx=%llu Tx=%llu Ts=%llu Delta=%llu\n", mNetStatRx, mNetStatTx, uTsNow, cNsPassed));
313 }
314 else
315 {
316 /* Can happen on resume or if we're using a non-monotonic clock
317 source for the timer and the time is adjusted. */
318 mNetStatRx = uRxPrev;
319 mNetStatTx = uTxPrev;
320 LogThisFunc(("Net Ts=%llu cNsPassed=%llu - too small interval\n", uTsNow, cNsPassed));
321 }
322 }
323
324 mParent->reportVmStatistics(validStats,
325 aGuestStats[GUESTSTATTYPE_CPUUSER],
326 aGuestStats[GUESTSTATTYPE_CPUKERNEL],
327 aGuestStats[GUESTSTATTYPE_CPUIDLE],
328 /* Convert the units for RAM usage stats: page (4K) -> 1KB units */
329 mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K),
330 mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K),
331 mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K),
332 (ULONG)(cbSharedMem / _1K), /* bytes -> KB */
333 mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K),
334 mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K),
335 (ULONG)(cbAllocTotal / _1K), /* bytes -> KB */
336 (ULONG)(cbFreeTotal / _1K),
337 (ULONG)(cbBalloonedTotal / _1K),
338 (ULONG)(cbSharedTotal / _1K),
339 uNetStatRx,
340 uNetStatTx);
341}
342
343// IGuest properties
344/////////////////////////////////////////////////////////////////////////////
345
346STDMETHODIMP Guest::COMGETTER(OSTypeId)(BSTR *a_pbstrOSTypeId)
347{
348 CheckComArgOutPointerValid(a_pbstrOSTypeId);
349
350 AutoCaller autoCaller(this);
351 HRESULT hrc = autoCaller.rc();
352 if (SUCCEEDED(hrc))
353 {
354 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
355 if (!mData.mInterfaceVersion.isEmpty())
356 mData.mOSTypeId.cloneTo(a_pbstrOSTypeId);
357 else
358 {
359 /* Redirect the call to IMachine if no additions are installed. */
360 ComPtr<IMachine> ptrMachine(mParent->machine());
361 alock.release();
362 hrc = ptrMachine->COMGETTER(OSTypeId)(a_pbstrOSTypeId);
363 }
364 }
365 return hrc;
366}
367
368STDMETHODIMP Guest::COMGETTER(AdditionsRunLevel)(AdditionsRunLevelType_T *aRunLevel)
369{
370 AutoCaller autoCaller(this);
371 if (FAILED(autoCaller.rc())) return autoCaller.rc();
372
373 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
374
375 *aRunLevel = mData.mAdditionsRunLevel;
376
377 return S_OK;
378}
379
380STDMETHODIMP Guest::COMGETTER(AdditionsVersion)(BSTR *a_pbstrAdditionsVersion)
381{
382 CheckComArgOutPointerValid(a_pbstrAdditionsVersion);
383
384 AutoCaller autoCaller(this);
385 HRESULT hrc = autoCaller.rc();
386 if (SUCCEEDED(hrc))
387 {
388 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
389
390 /*
391 * Return the ReportGuestInfo2 version info if available.
392 */
393 if ( !mData.mAdditionsVersionNew.isEmpty()
394 || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
395 mData.mAdditionsVersionNew.cloneTo(a_pbstrAdditionsVersion);
396 else
397 {
398 /*
399 * If we're running older guest additions (< 3.2.0) try get it from
400 * the guest properties. Detected switched around Version and
401 * Revision in early 3.1.x releases (see r57115).
402 */
403 ComPtr<IMachine> ptrMachine = mParent->machine();
404 alock.release(); /* No need to hold this during the IPC fun. */
405
406 Bstr bstr;
407 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
408 if ( SUCCEEDED(hrc)
409 && !bstr.isEmpty())
410 {
411 Utf8Str str(bstr);
412 if (str.count('.') == 0)
413 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
414 str = bstr;
415 if (str.count('.') != 2)
416 hrc = E_FAIL;
417 }
418
419 if (SUCCEEDED(hrc))
420 bstr.detachTo(a_pbstrAdditionsVersion);
421 else
422 {
423 /* Returning 1.4 is better than nothing. */
424 alock.acquire();
425 mData.mInterfaceVersion.cloneTo(a_pbstrAdditionsVersion);
426 hrc = S_OK;
427 }
428 }
429 }
430 return hrc;
431}
432
433STDMETHODIMP Guest::COMGETTER(AdditionsRevision)(ULONG *a_puAdditionsRevision)
434{
435 CheckComArgOutPointerValid(a_puAdditionsRevision);
436
437 AutoCaller autoCaller(this);
438 HRESULT hrc = autoCaller.rc();
439 if (SUCCEEDED(hrc))
440 {
441 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
442
443 /*
444 * Return the ReportGuestInfo2 version info if available.
445 */
446 if ( !mData.mAdditionsVersionNew.isEmpty()
447 || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
448 *a_puAdditionsRevision = mData.mAdditionsRevision;
449 else
450 {
451 /*
452 * If we're running older guest additions (< 3.2.0) try get it from
453 * the guest properties. Detected switched around Version and
454 * Revision in early 3.1.x releases (see r57115).
455 */
456 ComPtr<IMachine> ptrMachine = mParent->machine();
457 alock.release(); /* No need to hold this during the IPC fun. */
458
459 Bstr bstr;
460 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
461 if (SUCCEEDED(hrc))
462 {
463 Utf8Str str(bstr);
464 uint32_t uRevision;
465 int vrc = RTStrToUInt32Full(str.c_str(), 0, &uRevision);
466 if (vrc != VINF_SUCCESS && str.count('.') == 2)
467 {
468 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
469 if (SUCCEEDED(hrc))
470 {
471 str = bstr;
472 vrc = RTStrToUInt32Full(str.c_str(), 0, &uRevision);
473 }
474 }
475 if (vrc == VINF_SUCCESS)
476 *a_puAdditionsRevision = uRevision;
477 else
478 hrc = VBOX_E_IPRT_ERROR;
479 }
480 if (FAILED(hrc))
481 {
482 /* Return 0 if we don't know. */
483 *a_puAdditionsRevision = 0;
484 hrc = S_OK;
485 }
486 }
487 }
488 return hrc;
489}
490
491STDMETHODIMP Guest::COMGETTER(Facilities)(ComSafeArrayOut(IAdditionsFacility *, aFacilities))
492{
493 CheckComArgOutSafeArrayPointerValid(aFacilities);
494
495 AutoCaller autoCaller(this);
496 if (FAILED(autoCaller.rc())) return autoCaller.rc();
497
498 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
499
500 SafeIfaceArray<IAdditionsFacility> fac(mData.mFacilityMap);
501 fac.detachTo(ComSafeArrayOutArg(aFacilities));
502
503 return S_OK;
504}
505
506STDMETHODIMP Guest::COMGETTER(Sessions)(ComSafeArrayOut(IGuestSession *, aSessions))
507{
508 CheckComArgOutSafeArrayPointerValid(aSessions);
509
510 AutoCaller autoCaller(this);
511 if (FAILED(autoCaller.rc())) return autoCaller.rc();
512
513 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
514
515 SafeIfaceArray<IGuestSession> collection(mData.mGuestSessions);
516 collection.detachTo(ComSafeArrayOutArg(aSessions));
517
518 return S_OK;
519}
520
521BOOL Guest::isPageFusionEnabled()
522{
523 AutoCaller autoCaller(this);
524 if (FAILED(autoCaller.rc())) return false;
525
526 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
527
528 return mfPageFusionEnabled;
529}
530
531STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize)(ULONG *aMemoryBalloonSize)
532{
533 CheckComArgOutPointerValid(aMemoryBalloonSize);
534
535 AutoCaller autoCaller(this);
536 if (FAILED(autoCaller.rc())) return autoCaller.rc();
537
538 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
539
540 *aMemoryBalloonSize = mMemoryBalloonSize;
541
542 return S_OK;
543}
544
545STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize)(ULONG aMemoryBalloonSize)
546{
547 AutoCaller autoCaller(this);
548 if (FAILED(autoCaller.rc())) return autoCaller.rc();
549
550 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
551
552 /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
553 * does not call us back in any way! */
554 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
555 if (ret == S_OK)
556 {
557 mMemoryBalloonSize = aMemoryBalloonSize;
558 /* forward the information to the VMM device */
559 VMMDev *pVMMDev = mParent->getVMMDev();
560 /* MUST release all locks before calling VMM device as its critsect
561 * has higher lock order than anything in Main. */
562 alock.release();
563 if (pVMMDev)
564 {
565 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
566 if (pVMMDevPort)
567 pVMMDevPort->pfnSetMemoryBalloon(pVMMDevPort, aMemoryBalloonSize);
568 }
569 }
570
571 return ret;
572}
573
574STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval)(ULONG *aUpdateInterval)
575{
576 CheckComArgOutPointerValid(aUpdateInterval);
577
578 AutoCaller autoCaller(this);
579 if (FAILED(autoCaller.rc())) return autoCaller.rc();
580
581 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
582
583 *aUpdateInterval = mStatUpdateInterval;
584 return S_OK;
585}
586
587STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval)(ULONG aUpdateInterval)
588{
589 AutoCaller autoCaller(this);
590 if (FAILED(autoCaller.rc())) return autoCaller.rc();
591
592 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
593
594 if (mStatUpdateInterval)
595 if (aUpdateInterval == 0)
596 RTTimerLRStop(mStatTimer);
597 else
598 RTTimerLRChangeInterval(mStatTimer, aUpdateInterval);
599 else
600 if (aUpdateInterval != 0)
601 {
602 RTTimerLRChangeInterval(mStatTimer, aUpdateInterval);
603 RTTimerLRStart(mStatTimer, 0);
604 }
605 mStatUpdateInterval = aUpdateInterval;
606 /* forward the information to the VMM device */
607 VMMDev *pVMMDev = mParent->getVMMDev();
608 /* MUST release all locks before calling VMM device as its critsect
609 * has higher lock order than anything in Main. */
610 alock.release();
611 if (pVMMDev)
612 {
613 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
614 if (pVMMDevPort)
615 pVMMDevPort->pfnSetStatisticsInterval(pVMMDevPort, aUpdateInterval);
616 }
617
618 return S_OK;
619}
620
621STDMETHODIMP Guest::InternalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
622 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared,
623 ULONG *aMemCache, ULONG *aPageTotal,
624 ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
625{
626 CheckComArgOutPointerValid(aCpuUser);
627 CheckComArgOutPointerValid(aCpuKernel);
628 CheckComArgOutPointerValid(aCpuIdle);
629 CheckComArgOutPointerValid(aMemTotal);
630 CheckComArgOutPointerValid(aMemFree);
631 CheckComArgOutPointerValid(aMemBalloon);
632 CheckComArgOutPointerValid(aMemShared);
633 CheckComArgOutPointerValid(aMemCache);
634 CheckComArgOutPointerValid(aPageTotal);
635 CheckComArgOutPointerValid(aMemAllocTotal);
636 CheckComArgOutPointerValid(aMemFreeTotal);
637 CheckComArgOutPointerValid(aMemBalloonTotal);
638 CheckComArgOutPointerValid(aMemSharedTotal);
639
640 AutoCaller autoCaller(this);
641 if (FAILED(autoCaller.rc())) return autoCaller.rc();
642
643 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
644
645 *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
646 *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
647 *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
648 *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
649 *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
650 *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
651 *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
652 *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
653
654 /* Play safe or smth? */
655 *aMemAllocTotal = 0;
656 *aMemFreeTotal = 0;
657 *aMemBalloonTotal = 0;
658 *aMemSharedTotal = 0;
659 *aMemShared = 0;
660
661 /* MUST release all locks before calling any PGM statistics queries,
662 * as they are executed by EMT and that might deadlock us by VMM device
663 * activity which waits for the Guest object lock. */
664 alock.release();
665 Console::SafeVMPtr ptrVM(mParent);
666 if (!ptrVM.isOk())
667 return E_FAIL;
668
669 uint64_t cbFreeTotal, cbAllocTotal, cbBalloonedTotal, cbSharedTotal;
670 int rc = PGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal, &cbBalloonedTotal, &cbSharedTotal);
671 AssertRCReturn(rc, E_FAIL);
672
673 *aMemAllocTotal = (ULONG)(cbAllocTotal / _1K); /* bytes -> KB */
674 *aMemFreeTotal = (ULONG)(cbFreeTotal / _1K);
675 *aMemBalloonTotal = (ULONG)(cbBalloonedTotal / _1K);
676 *aMemSharedTotal = (ULONG)(cbSharedTotal / _1K);
677
678 /* Query the missing per-VM memory statistics. */
679 uint64_t cbTotalMemIgn, cbPrivateMemIgn, cbSharedMem, cbZeroMemIgn;
680 rc = PGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn, &cbSharedMem, &cbZeroMemIgn);
681 AssertRCReturn(rc, E_FAIL);
682 *aMemShared = (ULONG)(cbSharedMem / _1K);
683
684 return S_OK;
685}
686
687HRESULT Guest::setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
688{
689 static ULONG indexToPerfMask[] =
690 {
691 pm::VMSTATMASK_GUEST_CPUUSER,
692 pm::VMSTATMASK_GUEST_CPUKERNEL,
693 pm::VMSTATMASK_GUEST_CPUIDLE,
694 pm::VMSTATMASK_GUEST_MEMTOTAL,
695 pm::VMSTATMASK_GUEST_MEMFREE,
696 pm::VMSTATMASK_GUEST_MEMBALLOON,
697 pm::VMSTATMASK_GUEST_MEMCACHE,
698 pm::VMSTATMASK_GUEST_PAGETOTAL,
699 pm::VMSTATMASK_NONE
700 };
701 AutoCaller autoCaller(this);
702 if (FAILED(autoCaller.rc())) return autoCaller.rc();
703
704 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
705
706 if (enmType >= GUESTSTATTYPE_MAX)
707 return E_INVALIDARG;
708
709 mCurrentGuestStat[enmType] = aVal;
710 mVmValidStats |= indexToPerfMask[enmType];
711 return S_OK;
712}
713
714/**
715 * Returns the status of a specified Guest Additions facility.
716 *
717 * @return aStatus Current status of specified facility.
718 * @param aType Facility to get the status from.
719 * @param aTimestamp Timestamp of last facility status update in ms (optional).
720 */
721STDMETHODIMP Guest::GetFacilityStatus(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
722{
723 AutoCaller autoCaller(this);
724 if (FAILED(autoCaller.rc())) return autoCaller.rc();
725
726 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
727
728 CheckComArgNotNull(aStatus);
729 /* Not checking for aTimestamp is intentional; it's optional. */
730
731 FacilityMapIterConst it = mData.mFacilityMap.find(aType);
732 if (it != mData.mFacilityMap.end())
733 {
734 AdditionsFacility *pFacility = it->second;
735 ComAssert(pFacility);
736 *aStatus = pFacility->getStatus();
737 if (aTimestamp)
738 *aTimestamp = pFacility->getLastUpdated();
739 }
740 else
741 {
742 /*
743 * Do not fail here -- could be that the facility never has been brought up (yet) but
744 * the host wants to have its status anyway. So just tell we don't know at this point.
745 */
746 *aStatus = AdditionsFacilityStatus_Unknown;
747 if (aTimestamp)
748 *aTimestamp = RTTimeMilliTS();
749 }
750 return S_OK;
751}
752
753STDMETHODIMP Guest::GetAdditionsStatus(AdditionsRunLevelType_T aLevel, BOOL *aActive)
754{
755 AutoCaller autoCaller(this);
756 if (FAILED(autoCaller.rc())) return autoCaller.rc();
757
758 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
759
760 HRESULT rc = S_OK;
761 switch (aLevel)
762 {
763 case AdditionsRunLevelType_System:
764 *aActive = (mData.mAdditionsRunLevel > AdditionsRunLevelType_None);
765 break;
766
767 case AdditionsRunLevelType_Userland:
768 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Userland);
769 break;
770
771 case AdditionsRunLevelType_Desktop:
772 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Desktop);
773 break;
774
775 default:
776 rc = setError(VBOX_E_NOT_SUPPORTED,
777 tr("Invalid status level defined: %u"), aLevel);
778 break;
779 }
780
781 return rc;
782}
783
784STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
785 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
786{
787 AutoCaller autoCaller(this);
788 if (FAILED(autoCaller.rc())) return autoCaller.rc();
789
790 /* forward the information to the VMM device */
791 VMMDev *pVMMDev = mParent->getVMMDev();
792 if (pVMMDev)
793 {
794 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
795 if (pVMMDevPort)
796 {
797 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
798 if (!aAllowInteractiveLogon)
799 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
800
801 pVMMDevPort->pfnSetCredentials(pVMMDevPort,
802 Utf8Str(aUserName).c_str(),
803 Utf8Str(aPassword).c_str(),
804 Utf8Str(aDomain).c_str(),
805 u32Flags);
806 return S_OK;
807 }
808 }
809
810 return setError(VBOX_E_VM_ERROR,
811 tr("VMM device is not available (is the VM running?)"));
812}
813
814STDMETHODIMP Guest::DragHGEnter(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
815{
816 /* Input validation */
817 CheckComArgSafeArrayNotNull(allowedActions);
818 CheckComArgSafeArrayNotNull(formats);
819 CheckComArgOutPointerValid(pResultAction);
820
821 AutoCaller autoCaller(this);
822 if (FAILED(autoCaller.rc())) return autoCaller.rc();
823
824#ifdef VBOX_WITH_DRAG_AND_DROP
825 return m_pGuestDnD->dragHGEnter(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
826#else /* VBOX_WITH_DRAG_AND_DROP */
827 ReturnComNotImplemented();
828#endif /* !VBOX_WITH_DRAG_AND_DROP */
829}
830
831STDMETHODIMP Guest::DragHGMove(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
832{
833 /* Input validation */
834 CheckComArgSafeArrayNotNull(allowedActions);
835 CheckComArgSafeArrayNotNull(formats);
836 CheckComArgOutPointerValid(pResultAction);
837
838 AutoCaller autoCaller(this);
839 if (FAILED(autoCaller.rc())) return autoCaller.rc();
840
841#ifdef VBOX_WITH_DRAG_AND_DROP
842 return m_pGuestDnD->dragHGMove(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
843#else /* VBOX_WITH_DRAG_AND_DROP */
844 ReturnComNotImplemented();
845#endif /* !VBOX_WITH_DRAG_AND_DROP */
846}
847
848STDMETHODIMP Guest::DragHGLeave(ULONG uScreenId)
849{
850 AutoCaller autoCaller(this);
851 if (FAILED(autoCaller.rc())) return autoCaller.rc();
852
853#ifdef VBOX_WITH_DRAG_AND_DROP
854 return m_pGuestDnD->dragHGLeave(uScreenId);
855#else /* VBOX_WITH_DRAG_AND_DROP */
856 ReturnComNotImplemented();
857#endif /* !VBOX_WITH_DRAG_AND_DROP */
858}
859
860STDMETHODIMP Guest::DragHGDrop(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction)
861{
862 /* Input validation */
863 CheckComArgSafeArrayNotNull(allowedActions);
864 CheckComArgSafeArrayNotNull(formats);
865 CheckComArgOutPointerValid(pstrFormat);
866 CheckComArgOutPointerValid(pResultAction);
867
868 AutoCaller autoCaller(this);
869 if (FAILED(autoCaller.rc())) return autoCaller.rc();
870
871#ifdef VBOX_WITH_DRAG_AND_DROP
872 return m_pGuestDnD->dragHGDrop(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pstrFormat, pResultAction);
873#else /* VBOX_WITH_DRAG_AND_DROP */
874 ReturnComNotImplemented();
875#endif /* !VBOX_WITH_DRAG_AND_DROP */
876}
877
878STDMETHODIMP Guest::DragHGPutData(ULONG uScreenId, IN_BSTR bstrFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress)
879{
880 /* Input validation */
881 CheckComArgStrNotEmptyOrNull(bstrFormat);
882 CheckComArgSafeArrayNotNull(data);
883 CheckComArgOutPointerValid(ppProgress);
884
885 AutoCaller autoCaller(this);
886 if (FAILED(autoCaller.rc())) return autoCaller.rc();
887
888#ifdef VBOX_WITH_DRAG_AND_DROP
889 return m_pGuestDnD->dragHGPutData(uScreenId, bstrFormat, ComSafeArrayInArg(data), ppProgress);
890#else /* VBOX_WITH_DRAG_AND_DROP */
891 ReturnComNotImplemented();
892#endif /* !VBOX_WITH_DRAG_AND_DROP */
893}
894
895STDMETHODIMP Guest::DragGHPending(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction)
896{
897 /* Input validation */
898 CheckComArgSafeArrayNotNull(formats);
899 CheckComArgSafeArrayNotNull(allowedActions);
900 CheckComArgOutPointerValid(pDefaultAction);
901
902 AutoCaller autoCaller(this);
903 if (FAILED(autoCaller.rc())) return autoCaller.rc();
904
905#if defined(VBOX_WITH_DRAG_AND_DROP) && defined(VBOX_WITH_DRAG_AND_DROP_GH)
906 return m_pGuestDnD->dragGHPending(uScreenId, ComSafeArrayOutArg(formats), ComSafeArrayOutArg(allowedActions), pDefaultAction);
907#else /* VBOX_WITH_DRAG_AND_DROP */
908 ReturnComNotImplemented();
909#endif /* !VBOX_WITH_DRAG_AND_DROP */
910}
911
912STDMETHODIMP Guest::DragGHDropped(IN_BSTR bstrFormat, DragAndDropAction_T action, IProgress **ppProgress)
913{
914 /* Input validation */
915 CheckComArgStrNotEmptyOrNull(bstrFormat);
916 CheckComArgOutPointerValid(ppProgress);
917
918 AutoCaller autoCaller(this);
919 if (FAILED(autoCaller.rc())) return autoCaller.rc();
920
921#if defined(VBOX_WITH_DRAG_AND_DROP) && defined(VBOX_WITH_DRAG_AND_DROP_GH)
922 return m_pGuestDnD->dragGHDropped(bstrFormat, action, ppProgress);
923#else /* VBOX_WITH_DRAG_AND_DROP */
924 ReturnComNotImplemented();
925#endif /* !VBOX_WITH_DRAG_AND_DROP */
926}
927
928STDMETHODIMP Guest::DragGHGetData(ComSafeArrayOut(BYTE, data))
929{
930 /* Input validation */
931 CheckComArgSafeArrayNotNull(data);
932
933 AutoCaller autoCaller(this);
934 if (FAILED(autoCaller.rc())) return autoCaller.rc();
935
936#if defined(VBOX_WITH_DRAG_AND_DROP) && defined(VBOX_WITH_DRAG_AND_DROP_GH)
937 return m_pGuestDnD->dragGHGetData(ComSafeArrayOutArg(data));
938#else /* VBOX_WITH_DRAG_AND_DROP */
939 ReturnComNotImplemented();
940#endif /* !VBOX_WITH_DRAG_AND_DROP */
941}
942
943// public methods only for internal purposes
944/////////////////////////////////////////////////////////////////////////////
945
946/**
947 * Sets the general Guest Additions information like
948 * API (interface) version and OS type. Gets called by
949 * vmmdevUpdateGuestInfo.
950 *
951 * @param aInterfaceVersion
952 * @param aOsType
953 */
954void Guest::setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType)
955{
956 RTTIMESPEC TimeSpecTS;
957 RTTimeNow(&TimeSpecTS);
958
959 AutoCaller autoCaller(this);
960 AssertComRCReturnVoid(autoCaller.rc());
961
962 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
963
964
965 /*
966 * Note: The Guest Additions API (interface) version is deprecated
967 * and will not be used anymore! We might need it to at least report
968 * something as version number if *really* ancient Guest Additions are
969 * installed (without the guest version + revision properties having set).
970 */
971 mData.mInterfaceVersion = aInterfaceVersion;
972
973 /*
974 * Older Additions rely on the Additions API version whether they
975 * are assumed to be active or not. Since newer Additions do report
976 * the Additions version *before* calling this function (by calling
977 * VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
978 * in that order) we can tell apart old and new Additions here. Old
979 * Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
980 * so they just rely on the aInterfaceVersion string (which gets set by
981 * VMMDevReportGuestInfo).
982 *
983 * So only mark the Additions as being active (run level = system) when we
984 * don't have the Additions version set.
985 */
986 if (mData.mAdditionsVersionNew.isEmpty())
987 {
988 if (aInterfaceVersion.isEmpty())
989 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
990 else
991 {
992 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
993
994 /*
995 * To keep it compatible with the old Guest Additions behavior we need to set the
996 * "graphics" (feature) facility to active as soon as we got the Guest Additions
997 * interface version.
998 */
999 facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active, 0 /*fFlags*/, &TimeSpecTS);
1000 }
1001 }
1002
1003 /*
1004 * Older Additions didn't have this finer grained capability bit,
1005 * so enable it by default. Newer Additions will not enable this here
1006 * and use the setSupportedFeatures function instead.
1007 */
1008 /** @todo r=bird: I don't get the above comment nor the code below...
1009 * One talks about capability bits, the one always does something to a facility.
1010 * Then there is the comment below it all, which is placed like it addresses the
1011 * mOSTypeId, but talks about something which doesn't remotely like mOSTypeId...
1012 *
1013 * Andy, could you please try clarify and make the comments shorter and more
1014 * coherent! Also, explain why this is important and what depends on it.
1015 *
1016 * PS. There is the VMMDEV_GUEST_SUPPORTS_GRAPHICS capability* report... It
1017 * should come in pretty quickly after this update, normally.
1018 */
1019 facilityUpdate(VBoxGuestFacilityType_Graphics,
1020 facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver)
1021 ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
1022 0 /*fFlags*/, &TimeSpecTS); /** @todo the timestamp isn't gonna be right here on saved state restore. */
1023
1024 /*
1025 * Note! There is a race going on between setting mAdditionsRunLevel and
1026 * mSupportsGraphics here and disabling/enabling it later according to
1027 * its real status when using new(er) Guest Additions.
1028 */
1029 mData.mOSTypeId = Global::OSTypeId(aOsType);
1030}
1031
1032/**
1033 * Sets the Guest Additions version information details.
1034 *
1035 * Gets called by vmmdevUpdateGuestInfo2 and vmmdevUpdateGuestInfo (to clear the
1036 * state).
1037 *
1038 * @param a_uFullVersion VBoxGuestInfo2::additionsMajor,
1039 * VBoxGuestInfo2::additionsMinor and
1040 * VBoxGuestInfo2::additionsBuild combined into
1041 * one value by VBOX_FULL_VERSION_MAKE.
1042 *
1043 * When this is 0, it's vmmdevUpdateGuestInfo
1044 * calling to reset the state.
1045 *
1046 * @param a_pszName Build type tag and/or publisher tag, empty
1047 * string if neiter of those are present.
1048 * @param a_uRevision See VBoxGuestInfo2::additionsRevision.
1049 * @param a_fFeatures See VBoxGuestInfo2::additionsFeatures.
1050 */
1051void Guest::setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures)
1052{
1053 AutoCaller autoCaller(this);
1054 AssertComRCReturnVoid(autoCaller.rc());
1055
1056 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1057
1058 if (a_uFullVersion)
1059 {
1060 mData.mAdditionsVersionNew = BstrFmt(*a_pszName ? "%u.%u.%u_%s" : "%u.%u.%u",
1061 VBOX_FULL_VERSION_GET_MAJOR(a_uFullVersion),
1062 VBOX_FULL_VERSION_GET_MINOR(a_uFullVersion),
1063 VBOX_FULL_VERSION_GET_BUILD(a_uFullVersion),
1064 a_pszName);
1065 mData.mAdditionsVersionFull = a_uFullVersion;
1066 mData.mAdditionsRevision = a_uRevision;
1067 mData.mAdditionsFeatures = a_fFeatures;
1068 }
1069 else
1070 {
1071 Assert(!a_fFeatures && !a_uRevision && !*a_pszName);
1072 mData.mAdditionsVersionNew.setNull();
1073 mData.mAdditionsVersionFull = 0;
1074 mData.mAdditionsRevision = 0;
1075 mData.mAdditionsFeatures = 0;
1076 }
1077}
1078
1079bool Guest::facilityIsActive(VBoxGuestFacilityType enmFacility)
1080{
1081 Assert(enmFacility < INT32_MAX);
1082 FacilityMapIterConst it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
1083 if (it != mData.mFacilityMap.end())
1084 {
1085 AdditionsFacility *pFac = it->second;
1086 return (pFac->getStatus() == AdditionsFacilityStatus_Active);
1087 }
1088 return false;
1089}
1090
1091void Guest::facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
1092 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
1093{
1094 AssertReturnVoid( a_enmFacility < VBoxGuestFacilityType_All
1095 && a_enmFacility > VBoxGuestFacilityType_Unknown);
1096
1097 FacilityMapIter it = mData.mFacilityMap.find((AdditionsFacilityType_T)a_enmFacility);
1098 if (it != mData.mFacilityMap.end())
1099 {
1100 AdditionsFacility *pFac = it->second;
1101 pFac->update((AdditionsFacilityStatus_T)a_enmStatus, a_fFlags, a_pTimeSpecTS);
1102 }
1103 else
1104 {
1105 if (mData.mFacilityMap.size() > 64)
1106 {
1107 /* The easy way out for now. We could automatically destroy
1108 inactive facilities like VMMDev does if we like... */
1109 AssertFailedReturnVoid();
1110 }
1111
1112 ComObjPtr<AdditionsFacility> ptrFac;
1113 ptrFac.createObject();
1114 AssertReturnVoid(!ptrFac.isNull());
1115
1116 HRESULT hrc = ptrFac->init(this, (AdditionsFacilityType_T)a_enmFacility, (AdditionsFacilityStatus_T)a_enmStatus,
1117 a_fFlags, a_pTimeSpecTS);
1118 if (SUCCEEDED(hrc))
1119 mData.mFacilityMap.insert(std::make_pair((AdditionsFacilityType_T)a_enmFacility, ptrFac));
1120 }
1121}
1122
1123/**
1124 * Sets the status of a certain Guest Additions facility.
1125 *
1126 * Gets called by vmmdevUpdateGuestStatus, which just passes the report along.
1127 *
1128 * @param a_pInterface Pointer to this interface.
1129 * @param a_enmFacility The facility.
1130 * @param a_enmStatus The status.
1131 * @param a_fFlags Flags assoicated with the update. Currently
1132 * reserved and should be ignored.
1133 * @param a_pTimeSpecTS Pointer to the timestamp of this report.
1134 * @sa PDMIVMMDEVCONNECTOR::pfnUpdateGuestStatus, vmmdevUpdateGuestStatus
1135 * @thread The emulation thread.
1136 */
1137void Guest::setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
1138 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
1139{
1140 Assert( a_enmFacility > VBoxGuestFacilityType_Unknown
1141 && a_enmFacility <= VBoxGuestFacilityType_All); /* Paranoia, VMMDev checks for this. */
1142
1143 AutoCaller autoCaller(this);
1144 AssertComRCReturnVoid(autoCaller.rc());
1145
1146 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1147
1148 /*
1149 * Set a specific facility status.
1150 */
1151 if (a_enmFacility == VBoxGuestFacilityType_All)
1152 for (FacilityMapIter it = mData.mFacilityMap.begin(); it != mData.mFacilityMap.end(); ++it)
1153 facilityUpdate((VBoxGuestFacilityType)it->first, a_enmStatus, a_fFlags, a_pTimeSpecTS);
1154 else /* Update one facility only. */
1155 facilityUpdate(a_enmFacility, a_enmStatus, a_fFlags, a_pTimeSpecTS);
1156
1157 /*
1158 * Recalc the runlevel.
1159 */
1160 if (facilityIsActive(VBoxGuestFacilityType_VBoxTrayClient))
1161 mData.mAdditionsRunLevel = AdditionsRunLevelType_Desktop;
1162 else if (facilityIsActive(VBoxGuestFacilityType_VBoxService))
1163 mData.mAdditionsRunLevel = AdditionsRunLevelType_Userland;
1164 else if (facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver))
1165 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
1166 else
1167 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
1168}
1169
1170/**
1171 * Sets the supported features (and whether they are active or not).
1172 *
1173 * @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
1174 */
1175void Guest::setSupportedFeatures(uint32_t aCaps)
1176{
1177 AutoCaller autoCaller(this);
1178 AssertComRCReturnVoid(autoCaller.rc());
1179
1180 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1181
1182 /** @todo A nit: The timestamp is wrong on saved state restore. Would be better
1183 * to move the graphics and seamless capability -> facility translation to
1184 * VMMDev so this could be saved. */
1185 RTTIMESPEC TimeSpecTS;
1186 RTTimeNow(&TimeSpecTS);
1187
1188 facilityUpdate(VBoxGuestFacilityType_Seamless,
1189 aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
1190 0 /*fFlags*/, &TimeSpecTS);
1191 /** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
1192 facilityUpdate(VBoxGuestFacilityType_Graphics,
1193 aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
1194 0 /*fFlags*/, &TimeSpecTS);
1195}
1196
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