VirtualBox

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

Last change on this file since 50874 was 50544, checked in by vboxsync, 11 years ago

Main/Event: eliminate unused parameter

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

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