VirtualBox

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

最後變更 在這個檔案從39886是 39882,由 vboxsync 提交於 13 年 前

Config.kmk,VMMDev,Main,QtGui,VBoxManage: Refactored IGuest::additionsVersion and associated acts, splitting it up into additionsVersion and additionsRevision like IVirtualBox and IExtPack handles versioning. Fixed missing saved state in VMMDev where the VMMDevReq_ReportGuestInfo2 info was not saved and Main+Frontends led to believe we were running guest additions older than 3.2. The changes have be subjected to limited testing. Added TODOs for another missing save in VMMDev.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 33.0 KB
 
1/* $Id: GuestImpl.cpp 39882 2012-01-26 00:54:50Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation: Guest
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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#ifdef VBOX_WITH_DRAG_AND_DROP
24# include "GuestDnDImpl.h"
25#endif
26#include "VMMDev.h"
27
28#include "AutoCaller.h"
29#include "Logging.h"
30
31#include <VBox/VMMDev.h>
32#ifdef VBOX_WITH_GUEST_CONTROL
33# include <VBox/com/array.h>
34# include <VBox/com/ErrorInfo.h>
35#endif
36#include <iprt/cpp/utils.h>
37#include <VBox/vmm/pgm.h>
38#include <VBox/version.h>
39
40// defines
41/////////////////////////////////////////////////////////////////////////////
42
43// constructor / destructor
44/////////////////////////////////////////////////////////////////////////////
45
46DEFINE_EMPTY_CTOR_DTOR (Guest)
47
48HRESULT Guest::FinalConstruct()
49{
50 return BaseFinalConstruct();
51}
52
53void Guest::FinalRelease()
54{
55 uninit ();
56 BaseFinalRelease();
57}
58
59// public methods only for internal purposes
60/////////////////////////////////////////////////////////////////////////////
61
62/**
63 * Initializes the guest object.
64 */
65HRESULT Guest::init(Console *aParent)
66{
67 LogFlowThisFunc(("aParent=%p\n", aParent));
68
69 ComAssertRet(aParent, E_INVALIDARG);
70
71 /* Enclose the state transition NotReady->InInit->Ready */
72 AutoInitSpan autoInitSpan(this);
73 AssertReturn(autoInitSpan.isOk(), E_FAIL);
74
75 unconst(mParent) = aParent;
76
77 /* Confirm a successful initialization when it's the case */
78 autoInitSpan.setSucceeded();
79
80 ULONG aMemoryBalloonSize;
81 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
82 if (ret == S_OK)
83 mMemoryBalloonSize = aMemoryBalloonSize;
84 else
85 mMemoryBalloonSize = 0; /* Default is no ballooning */
86
87 BOOL fPageFusionEnabled;
88 ret = mParent->machine()->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
89 if (ret == S_OK)
90 mfPageFusionEnabled = fPageFusionEnabled;
91 else
92 mfPageFusionEnabled = false; /* Default is no page fusion*/
93
94 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
95
96 /* Clear statistics. */
97 for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
98 mCurrentGuestStat[i] = 0;
99
100#ifdef VBOX_WITH_GUEST_CONTROL
101 /* Init the context ID counter at 1000. */
102 mNextContextID = 1000;
103#endif
104
105#ifdef VBOX_WITH_DRAG_AND_DROP
106 m_pGuestDnD = new GuestDnD(this);
107#endif
108
109 return S_OK;
110}
111
112/**
113 * Uninitializes the instance and sets the ready flag to FALSE.
114 * Called either from FinalRelease() or by the parent when it gets destroyed.
115 */
116void Guest::uninit()
117{
118 LogFlowThisFunc(("\n"));
119
120#ifdef VBOX_WITH_GUEST_CONTROL
121 /* r=poetzsch: Not sure if this is really right. Please note that
122 * IGuest::uninit is called twice (which I also consider a bug). So the
123 * test for uninitDone should be always first! */
124 /* Scope write lock as much as possible. */
125 {
126 /*
127 * Cleanup must be done *before* AutoUninitSpan to cancel all
128 * all outstanding waits in API functions (which hold AutoCaller
129 * ref counts).
130 */
131 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
132
133 /* Notify left over callbacks that we are about to shutdown ... */
134 CallbackMapIter it;
135 for (it = mCallbackMap.begin(); it != mCallbackMap.end(); it++)
136 {
137 int rc2 = callbackNotifyEx(it->first, VERR_CANCELLED,
138 Guest::tr("VM is shutting down, canceling uncompleted guest requests ..."));
139 AssertRC(rc2);
140 }
141
142 /* Destroy left over callback data. */
143 for (it = mCallbackMap.begin(); it != mCallbackMap.end(); it++)
144 callbackDestroy(it->first);
145
146 /* Clear process map. */
147 mGuestProcessMap.clear();
148 }
149#endif
150
151 /* Enclose the state transition Ready->InUninit->NotReady */
152 AutoUninitSpan autoUninitSpan(this);
153 if (autoUninitSpan.uninitDone())
154 return;
155
156#ifdef VBOX_WITH_DRAG_AND_DROP
157 delete m_pGuestDnD;
158 m_pGuestDnD = NULL;
159#endif
160
161 unconst(mParent) = NULL;
162}
163
164// IGuest properties
165/////////////////////////////////////////////////////////////////////////////
166
167STDMETHODIMP Guest::COMGETTER(OSTypeId)(BSTR *a_pbstrOSTypeId)
168{
169 CheckComArgOutPointerValid(a_pbstrOSTypeId);
170
171 AutoCaller autoCaller(this);
172 HRESULT hrc = autoCaller.rc();
173 if (SUCCEEDED(hrc))
174 {
175 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
176 if (!mData.mInterfaceVersion.isEmpty())
177 mData.mOSTypeId.cloneTo(a_pbstrOSTypeId);
178 else
179 {
180 /* Redirect the call to IMachine if no additions are installed. */
181 ComPtr<IMachine> ptrMachine(mParent->machine());
182 alock.release();
183 hrc = ptrMachine->COMGETTER(OSTypeId)(a_pbstrOSTypeId);
184 }
185 }
186 return hrc;
187}
188
189STDMETHODIMP Guest::COMGETTER(AdditionsRunLevel) (AdditionsRunLevelType_T *aRunLevel)
190{
191 AutoCaller autoCaller(this);
192 if (FAILED(autoCaller.rc())) return autoCaller.rc();
193
194 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
195
196 *aRunLevel = mData.mAdditionsRunLevel;
197
198 return S_OK;
199}
200
201STDMETHODIMP Guest::COMGETTER(AdditionsVersion)(BSTR *a_pbstrAdditionsVersion)
202{
203 CheckComArgOutPointerValid(a_pbstrAdditionsVersion);
204
205 AutoCaller autoCaller(this);
206 HRESULT hrc = autoCaller.rc();
207 if (SUCCEEDED(hrc))
208 {
209 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
210
211 /*
212 * Return the ReportGuestInfo2 version info if available.
213 */
214 if ( !mData.mAdditionsVersionNew.isEmpty()
215 || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
216 mData.mAdditionsVersionNew.cloneTo(a_pbstrAdditionsVersion);
217 else
218 {
219 /*
220 * If we're running older guest additions (< 3.2.0) try get it from
221 * the guest properties.
222 */
223 ComPtr<IMachine> ptrMachine = mParent->machine();
224 alock.release(); /* No need to hold this during the IPC fun. */
225
226 Bstr bstr;
227 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
228 if (SUCCEEDED(hrc))
229 bstr.detachTo(a_pbstrAdditionsVersion);
230 else
231 {
232 /* Returning 1.4 is better than nothing. */
233 alock.acquire();
234 mData.mInterfaceVersion.cloneTo(a_pbstrAdditionsVersion);
235 hrc = S_OK;
236 }
237 }
238 }
239 return hrc;
240}
241
242STDMETHODIMP Guest::COMGETTER(AdditionsRevision)(ULONG *a_puAdditionsRevision)
243{
244 CheckComArgOutPointerValid(a_puAdditionsRevision);
245
246 AutoCaller autoCaller(this);
247 HRESULT hrc = autoCaller.rc();
248 if (SUCCEEDED(hrc))
249 {
250 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
251
252 /*
253 * Return the ReportGuestInfo2 version info if available.
254 */
255 if ( !mData.mAdditionsVersionNew.isEmpty()
256 || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
257 *a_puAdditionsRevision = mData.mAdditionsRevision;
258 else
259 {
260 /*
261 * If we're running older guest additions (< 3.2.0) try get it from
262 * the guest properties.
263 */
264 ComPtr<IMachine> ptrMachine = mParent->machine();
265 alock.release(); /* No need to hold this during the IPC fun. */
266
267 Bstr bstr;
268 hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
269 if (SUCCEEDED(hrc))
270 {
271 Utf8Str str(bstr);
272 uint32_t uRevision;
273 int vrc = RTStrToUInt32Full(str.c_str(), 0, &uRevision);
274 if (vrc == VINF_SUCCESS)
275 *a_puAdditionsRevision = uRevision;
276 else
277 hrc = VBOX_E_IPRT_ERROR;
278 }
279 if (FAILED(hrc))
280 {
281 /* Return 0 if we don't know. */
282 *a_puAdditionsRevision = 0;
283 hrc = 0;
284 }
285 }
286 }
287 return hrc;
288}
289
290STDMETHODIMP Guest::COMGETTER(Facilities)(ComSafeArrayOut(IAdditionsFacility*, aFacilities))
291{
292 CheckComArgOutPointerValid(aFacilities);
293
294 AutoCaller autoCaller(this);
295 if (FAILED(autoCaller.rc())) return autoCaller.rc();
296
297 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
298
299 SafeIfaceArray<IAdditionsFacility> fac(mData.mFacilityMap);
300 fac.detachTo(ComSafeArrayOutArg(aFacilities));
301
302 return S_OK;
303}
304
305BOOL Guest::isPageFusionEnabled()
306{
307 AutoCaller autoCaller(this);
308 if (FAILED(autoCaller.rc())) return false;
309
310 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
311
312 return mfPageFusionEnabled;
313}
314
315STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize)(ULONG *aMemoryBalloonSize)
316{
317 CheckComArgOutPointerValid(aMemoryBalloonSize);
318
319 AutoCaller autoCaller(this);
320 if (FAILED(autoCaller.rc())) return autoCaller.rc();
321
322 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
323
324 *aMemoryBalloonSize = mMemoryBalloonSize;
325
326 return S_OK;
327}
328
329STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize)(ULONG aMemoryBalloonSize)
330{
331 AutoCaller autoCaller(this);
332 if (FAILED(autoCaller.rc())) return autoCaller.rc();
333
334 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
335
336 /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
337 * does not call us back in any way! */
338 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
339 if (ret == S_OK)
340 {
341 mMemoryBalloonSize = aMemoryBalloonSize;
342 /* forward the information to the VMM device */
343 VMMDev *pVMMDev = mParent->getVMMDev();
344 /* MUST release all locks before calling VMM device as its critsect
345 * has higher lock order than anything in Main. */
346 alock.release();
347 if (pVMMDev)
348 {
349 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
350 if (pVMMDevPort)
351 pVMMDevPort->pfnSetMemoryBalloon(pVMMDevPort, aMemoryBalloonSize);
352 }
353 }
354
355 return ret;
356}
357
358STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval)(ULONG *aUpdateInterval)
359{
360 CheckComArgOutPointerValid(aUpdateInterval);
361
362 AutoCaller autoCaller(this);
363 if (FAILED(autoCaller.rc())) return autoCaller.rc();
364
365 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
366
367 *aUpdateInterval = mStatUpdateInterval;
368 return S_OK;
369}
370
371STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval)(ULONG aUpdateInterval)
372{
373 AutoCaller autoCaller(this);
374 if (FAILED(autoCaller.rc())) return autoCaller.rc();
375
376 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
377
378 mStatUpdateInterval = aUpdateInterval;
379 /* forward the information to the VMM device */
380 VMMDev *pVMMDev = mParent->getVMMDev();
381 /* MUST release all locks before calling VMM device as its critsect
382 * has higher lock order than anything in Main. */
383 alock.release();
384 if (pVMMDev)
385 {
386 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
387 if (pVMMDevPort)
388 pVMMDevPort->pfnSetStatisticsInterval(pVMMDevPort, aUpdateInterval);
389 }
390
391 return S_OK;
392}
393
394STDMETHODIMP Guest::InternalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
395 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared,
396 ULONG *aMemCache, ULONG *aPageTotal,
397 ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
398{
399 CheckComArgOutPointerValid(aCpuUser);
400 CheckComArgOutPointerValid(aCpuKernel);
401 CheckComArgOutPointerValid(aCpuIdle);
402 CheckComArgOutPointerValid(aMemTotal);
403 CheckComArgOutPointerValid(aMemFree);
404 CheckComArgOutPointerValid(aMemBalloon);
405 CheckComArgOutPointerValid(aMemShared);
406 CheckComArgOutPointerValid(aMemCache);
407 CheckComArgOutPointerValid(aPageTotal);
408 CheckComArgOutPointerValid(aMemAllocTotal);
409 CheckComArgOutPointerValid(aMemFreeTotal);
410 CheckComArgOutPointerValid(aMemBalloonTotal);
411 CheckComArgOutPointerValid(aMemSharedTotal);
412
413 AutoCaller autoCaller(this);
414 if (FAILED(autoCaller.rc())) return autoCaller.rc();
415
416 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
417
418 *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
419 *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
420 *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
421 *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
422 *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
423 *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
424 *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
425 *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
426
427 /* MUST release all locks before calling any PGM statistics queries,
428 * as they are executed by EMT and that might deadlock us by VMM device
429 * activity which waits for the Guest object lock. */
430 alock.release();
431 Console::SafeVMPtr pVM (mParent);
432 if (pVM.isOk())
433 {
434 uint64_t uFreeTotal, uAllocTotal, uBalloonedTotal, uSharedTotal;
435 *aMemFreeTotal = 0;
436 int rc = PGMR3QueryGlobalMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal, &uSharedTotal);
437 AssertRC(rc);
438 if (rc == VINF_SUCCESS)
439 {
440 *aMemAllocTotal = (ULONG)(uAllocTotal / _1K); /* bytes -> KB */
441 *aMemFreeTotal = (ULONG)(uFreeTotal / _1K);
442 *aMemBalloonTotal = (ULONG)(uBalloonedTotal / _1K);
443 *aMemSharedTotal = (ULONG)(uSharedTotal / _1K);
444 }
445 else
446 return E_FAIL;
447
448 /* Query the missing per-VM memory statistics. */
449 *aMemShared = 0;
450 uint64_t uTotalMem, uPrivateMem, uSharedMem, uZeroMem;
451 rc = PGMR3QueryMemoryStats(pVM.raw(), &uTotalMem, &uPrivateMem, &uSharedMem, &uZeroMem);
452 if (rc == VINF_SUCCESS)
453 {
454 *aMemShared = (ULONG)(uSharedMem / _1K);
455 }
456 else
457 return E_FAIL;
458 }
459 else
460 {
461 *aMemAllocTotal = 0;
462 *aMemFreeTotal = 0;
463 *aMemBalloonTotal = 0;
464 *aMemSharedTotal = 0;
465 *aMemShared = 0;
466 return E_FAIL;
467 }
468
469 return S_OK;
470}
471
472HRESULT Guest::setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
473{
474 AutoCaller autoCaller(this);
475 if (FAILED(autoCaller.rc())) return autoCaller.rc();
476
477 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
478
479 if (enmType >= GUESTSTATTYPE_MAX)
480 return E_INVALIDARG;
481
482 mCurrentGuestStat[enmType] = aVal;
483 return S_OK;
484}
485
486/**
487 * Returns the status of a specified Guest Additions facility.
488 *
489 * @return aStatus Current status of specified facility.
490 * @param aType Facility to get the status from.
491 * @param aTimestamp Timestamp of last facility status update in ms (optional).
492 */
493STDMETHODIMP Guest::GetFacilityStatus(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
494{
495 AutoCaller autoCaller(this);
496 if (FAILED(autoCaller.rc())) return autoCaller.rc();
497
498 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
499
500 CheckComArgNotNull(aStatus);
501 /* Not checking for aTimestamp is intentional; it's optional. */
502
503 FacilityMapIterConst it = mData.mFacilityMap.find(aType);
504 if (it != mData.mFacilityMap.end())
505 {
506 AdditionsFacility *pFacility = it->second;
507 ComAssert(pFacility);
508 *aStatus = pFacility->getStatus();
509 if (aTimestamp)
510 *aTimestamp = pFacility->getLastUpdated();
511 }
512 else
513 {
514 /*
515 * Do not fail here -- could be that the facility never has been brought up (yet) but
516 * the host wants to have its status anyway. So just tell we don't know at this point.
517 */
518 *aStatus = AdditionsFacilityStatus_Unknown;
519 if (aTimestamp)
520 *aTimestamp = RTTimeMilliTS();
521 }
522 return S_OK;
523}
524
525STDMETHODIMP Guest::GetAdditionsStatus(AdditionsRunLevelType_T aLevel, BOOL *aActive)
526{
527 AutoCaller autoCaller(this);
528 if (FAILED(autoCaller.rc())) return autoCaller.rc();
529
530 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
531
532 HRESULT rc = S_OK;
533 switch (aLevel)
534 {
535 case AdditionsRunLevelType_System:
536 *aActive = (mData.mAdditionsRunLevel > AdditionsRunLevelType_None);
537 break;
538
539 case AdditionsRunLevelType_Userland:
540 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Userland);
541 break;
542
543 case AdditionsRunLevelType_Desktop:
544 *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Desktop);
545 break;
546
547 default:
548 rc = setError(VBOX_E_NOT_SUPPORTED,
549 tr("Invalid status level defined: %u"), aLevel);
550 break;
551 }
552
553 return rc;
554}
555
556STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
557 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
558{
559 AutoCaller autoCaller(this);
560 if (FAILED(autoCaller.rc())) return autoCaller.rc();
561
562 /* forward the information to the VMM device */
563 VMMDev *pVMMDev = mParent->getVMMDev();
564 if (pVMMDev)
565 {
566 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
567 if (pVMMDevPort)
568 {
569 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
570 if (!aAllowInteractiveLogon)
571 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
572
573 pVMMDevPort->pfnSetCredentials(pVMMDevPort,
574 Utf8Str(aUserName).c_str(),
575 Utf8Str(aPassword).c_str(),
576 Utf8Str(aDomain).c_str(),
577 u32Flags);
578 return S_OK;
579 }
580 }
581
582 return setError(VBOX_E_VM_ERROR,
583 tr("VMM device is not available (is the VM running?)"));
584}
585
586STDMETHODIMP Guest::DragHGEnter(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
587{
588 /* Input validation */
589 CheckComArgSafeArrayNotNull(allowedActions);
590 CheckComArgSafeArrayNotNull(formats);
591 CheckComArgOutPointerValid(pResultAction);
592
593 AutoCaller autoCaller(this);
594 if (FAILED(autoCaller.rc())) return autoCaller.rc();
595
596#ifdef VBOX_WITH_DRAG_AND_DROP
597 return m_pGuestDnD->dragHGEnter(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
598#else /* VBOX_WITH_DRAG_AND_DROP */
599 ReturnComNotImplemented();
600#endif /* !VBOX_WITH_DRAG_AND_DROP */
601}
602
603STDMETHODIMP Guest::DragHGMove(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
604{
605 /* Input validation */
606 CheckComArgSafeArrayNotNull(allowedActions);
607 CheckComArgSafeArrayNotNull(formats);
608 CheckComArgOutPointerValid(pResultAction);
609
610 AutoCaller autoCaller(this);
611 if (FAILED(autoCaller.rc())) return autoCaller.rc();
612
613#ifdef VBOX_WITH_DRAG_AND_DROP
614 return m_pGuestDnD->dragHGMove(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
615#else /* VBOX_WITH_DRAG_AND_DROP */
616 ReturnComNotImplemented();
617#endif /* !VBOX_WITH_DRAG_AND_DROP */
618}
619
620STDMETHODIMP Guest::DragHGLeave(ULONG uScreenId)
621{
622 AutoCaller autoCaller(this);
623 if (FAILED(autoCaller.rc())) return autoCaller.rc();
624
625#ifdef VBOX_WITH_DRAG_AND_DROP
626 return m_pGuestDnD->dragHGLeave(uScreenId);
627#else /* VBOX_WITH_DRAG_AND_DROP */
628 ReturnComNotImplemented();
629#endif /* !VBOX_WITH_DRAG_AND_DROP */
630}
631
632STDMETHODIMP Guest::DragHGDrop(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction)
633{
634 /* Input validation */
635 CheckComArgSafeArrayNotNull(allowedActions);
636 CheckComArgSafeArrayNotNull(formats);
637 CheckComArgOutPointerValid(pstrFormat);
638 CheckComArgOutPointerValid(pResultAction);
639
640 AutoCaller autoCaller(this);
641 if (FAILED(autoCaller.rc())) return autoCaller.rc();
642
643#ifdef VBOX_WITH_DRAG_AND_DROP
644 return m_pGuestDnD->dragHGDrop(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pstrFormat, pResultAction);
645#else /* VBOX_WITH_DRAG_AND_DROP */
646 ReturnComNotImplemented();
647#endif /* !VBOX_WITH_DRAG_AND_DROP */
648}
649
650STDMETHODIMP Guest::DragHGPutData(ULONG uScreenId, IN_BSTR bstrFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress)
651{
652 /* Input validation */
653 CheckComArgStrNotEmptyOrNull(bstrFormat);
654 CheckComArgSafeArrayNotNull(data);
655 CheckComArgOutPointerValid(ppProgress);
656
657 AutoCaller autoCaller(this);
658 if (FAILED(autoCaller.rc())) return autoCaller.rc();
659
660#ifdef VBOX_WITH_DRAG_AND_DROP
661 return m_pGuestDnD->dragHGPutData(uScreenId, bstrFormat, ComSafeArrayInArg(data), ppProgress);
662#else /* VBOX_WITH_DRAG_AND_DROP */
663 ReturnComNotImplemented();
664#endif /* !VBOX_WITH_DRAG_AND_DROP */
665}
666
667STDMETHODIMP Guest::DragGHPending(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction)
668{
669 /* Input validation */
670 CheckComArgSafeArrayNotNull(formats);
671 CheckComArgSafeArrayNotNull(allowedActions);
672 CheckComArgOutPointerValid(pDefaultAction);
673
674 AutoCaller autoCaller(this);
675 if (FAILED(autoCaller.rc())) return autoCaller.rc();
676
677#ifdef VBOX_WITH_DRAG_AND_DROP
678 return m_pGuestDnD->dragGHPending(uScreenId, ComSafeArrayOutArg(formats), ComSafeArrayOutArg(allowedActions), pDefaultAction);
679#else /* VBOX_WITH_DRAG_AND_DROP */
680 ReturnComNotImplemented();
681#endif /* !VBOX_WITH_DRAG_AND_DROP */
682}
683
684STDMETHODIMP Guest::DragGHDropped(IN_BSTR bstrFormat, DragAndDropAction_T action, IProgress **ppProgress)
685{
686 /* Input validation */
687 CheckComArgStrNotEmptyOrNull(bstrFormat);
688 CheckComArgOutPointerValid(ppProgress);
689
690 AutoCaller autoCaller(this);
691 if (FAILED(autoCaller.rc())) return autoCaller.rc();
692
693#ifdef VBOX_WITH_DRAG_AND_DROP
694 return m_pGuestDnD->dragGHDropped(bstrFormat, action, ppProgress);
695#else /* VBOX_WITH_DRAG_AND_DROP */
696 ReturnComNotImplemented();
697#endif /* !VBOX_WITH_DRAG_AND_DROP */
698}
699
700STDMETHODIMP Guest::DragGHGetData(ComSafeArrayOut(BYTE, data))
701{
702 /* Input validation */
703 CheckComArgSafeArrayNotNull(data);
704
705 AutoCaller autoCaller(this);
706 if (FAILED(autoCaller.rc())) return autoCaller.rc();
707
708#ifdef VBOX_WITH_DRAG_AND_DROP
709 return m_pGuestDnD->dragGHGetData(ComSafeArrayOutArg(data));
710#else /* VBOX_WITH_DRAG_AND_DROP */
711 ReturnComNotImplemented();
712#endif /* !VBOX_WITH_DRAG_AND_DROP */
713}
714
715// public methods only for internal purposes
716/////////////////////////////////////////////////////////////////////////////
717
718/**
719 * Sets the general Guest Additions information like
720 * API (interface) version and OS type. Gets called by
721 * vmmdevUpdateGuestInfo.
722 *
723 * @param aInterfaceVersion
724 * @param aOsType
725 */
726void Guest::setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType)
727{
728 AutoCaller autoCaller(this);
729 AssertComRCReturnVoid(autoCaller.rc());
730
731 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
732
733 /*
734 * Note: The Guest Additions API (interface) version is deprecated
735 * and will not be used anymore! We might need it to at least report
736 * something as version number if *really* ancient Guest Additions are
737 * installed (without the guest version + revision properties having set).
738 */
739 mData.mInterfaceVersion = aInterfaceVersion;
740
741 /*
742 * Older Additions rely on the Additions API version whether they
743 * are assumed to be active or not. Since newer Additions do report
744 * the Additions version *before* calling this function (by calling
745 * VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
746 * in that order) we can tell apart old and new Additions here. Old
747 * Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
748 * so they just rely on the aInterfaceVersion string (which gets set by
749 * VMMDevReportGuestInfo).
750 *
751 * So only mark the Additions as being active (run level = system) when we
752 * don't have the Additions version set.
753 */
754 if (mData.mAdditionsVersionNew.isEmpty())
755 {
756 if (aInterfaceVersion.isEmpty())
757 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
758 else
759 {
760 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
761
762 /*
763 * To keep it compatible with the old Guest Additions behavior we need to set the
764 * "graphics" (feature) facility to active as soon as we got the Guest Additions
765 * interface version.
766 */
767 facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active);
768 }
769 }
770
771 /*
772 * Older Additions didn't have this finer grained capability bit,
773 * so enable it by default. Newer Additions will not enable this here
774 * and use the setSupportedFeatures function instead.
775 */
776 facilityUpdate(VBoxGuestFacilityType_Graphics, facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver) ?
777 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
778
779 /*
780 * Note! There is a race going on between setting mAdditionsRunLevel and
781 * mSupportsGraphics here and disabling/enabling it later according to
782 * its real status when using new(er) Guest Additions.
783 */
784 mData.mOSTypeId = Global::OSTypeId(aOsType);
785}
786
787/**
788 * Sets the Guest Additions version information details.
789 *
790 * Gets called by vmmdevUpdateGuestInfo2 and vmmdevUpdateGuestInfo (to clear the
791 * state).
792 *
793 * @param a_uFullVersion VBoxGuestInfo2::additionsMajor,
794 * VBoxGuestInfo2::additionsMinor and
795 * VBoxGuestInfo2::additionsBuild combined into
796 * one value by VBOX_FULL_VERSION_MAKE.
797 *
798 * When this is 0, it's vmmdevUpdateGuestInfo
799 * calling to reset the state.
800 *
801 * @param a_pszName Build type tag and/or publisher tag, empty
802 * string if neiter of those are present.
803 * @param a_uRevision See VBoxGuestInfo2::additionsRevision.
804 * @param a_fFeatures See VBoxGuestInfo2::additionsFeatures.
805 */
806void Guest::setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures)
807{
808 AutoCaller autoCaller(this);
809 AssertComRCReturnVoid(autoCaller.rc());
810
811 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
812
813 if (a_uFullVersion)
814 {
815 mData.mAdditionsVersionNew = BstrFmt(*a_pszName ? "%u.%u.%u_%s" : "%u.%u.%u",
816 VBOX_FULL_VERSION_GET_MAJOR(a_uFullVersion),
817 VBOX_FULL_VERSION_GET_MINOR(a_uFullVersion),
818 VBOX_FULL_VERSION_GET_BUILD(a_uFullVersion),
819 a_pszName);
820 mData.mAdditionsVersionFull = a_uFullVersion;
821 mData.mAdditionsRevision = a_uRevision;
822 mData.mAdditionsFeatures = a_fFeatures;
823 }
824 else
825 {
826 Assert(!a_fFeatures && !a_uRevision && !*a_pszName);
827 mData.mAdditionsVersionNew.setNull();
828 mData.mAdditionsVersionFull = 0;
829 mData.mAdditionsRevision = 0;
830 mData.mAdditionsFeatures = 0;
831 }
832}
833
834bool Guest::facilityIsActive(VBoxGuestFacilityType enmFacility)
835{
836 Assert(enmFacility < INT32_MAX);
837 FacilityMapIterConst it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
838 if (it != mData.mFacilityMap.end())
839 {
840 AdditionsFacility *pFac = it->second;
841 return (pFac->getStatus() == AdditionsFacilityStatus_Active);
842 }
843 return false;
844}
845
846HRESULT Guest::facilityUpdate(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus)
847{
848 ComAssertRet(enmFacility < INT32_MAX, E_INVALIDARG);
849
850 HRESULT rc;
851 RTTIMESPEC tsNow;
852 RTTimeNow(&tsNow);
853
854 FacilityMapIter it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
855 if (it != mData.mFacilityMap.end())
856 {
857 AdditionsFacility *pFac = it->second;
858 rc = pFac->update((AdditionsFacilityStatus_T)enmStatus, tsNow);
859 }
860 else
861 {
862 ComObjPtr<AdditionsFacility> pFacility;
863 pFacility.createObject();
864 ComAssert(!pFacility.isNull());
865 rc = pFacility->init(this,
866 (AdditionsFacilityType_T)enmFacility,
867 (AdditionsFacilityStatus_T)enmStatus);
868 if (SUCCEEDED(rc))
869 mData.mFacilityMap.insert(std::make_pair((AdditionsFacilityType_T)enmFacility, pFacility));
870 }
871
872 LogFlowFunc(("Returned with rc=%Rrc\n"));
873 return rc;
874}
875
876/**
877 * Sets the status of a certain Guest Additions facility.
878 * Gets called by vmmdevUpdateGuestStatus.
879 *
880 * @param enmFacility Facility to set the status for.
881 * @param enmStatus Actual status to set.
882 * @param aFlags
883 */
884void Guest::setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags)
885{
886 AutoCaller autoCaller(this);
887 AssertComRCReturnVoid(autoCaller.rc());
888
889 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
890
891 /*
892 * Set overall additions run level.
893 */
894
895 /* First check for disabled status. */
896 uint32_t uCurFacility = enmFacility + (enmStatus == VBoxGuestFacilityStatus_Active ? 0 : -1);
897 if ( enmFacility < VBoxGuestFacilityType_VBoxGuestDriver
898 || ( enmFacility == VBoxGuestFacilityType_All
899 && enmStatus == VBoxGuestFacilityStatus_Inactive)
900 )
901 {
902 mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
903 }
904 else if (uCurFacility >= VBoxGuestFacilityType_VBoxTrayClient)
905 {
906 mData.mAdditionsRunLevel = AdditionsRunLevelType_Desktop;
907 }
908 else if (uCurFacility >= VBoxGuestFacilityType_VBoxService)
909 {
910 mData.mAdditionsRunLevel = AdditionsRunLevelType_Userland;
911 }
912 else if (uCurFacility >= VBoxGuestFacilityType_VBoxGuestDriver)
913 {
914 mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
915 }
916 else /* Should never happen! */
917 AssertMsgFailed(("Invalid facility status/run level detected! uCurFacility=%d\n", uCurFacility));
918
919 /** @todo Above is wrong. The runlevel has to be recalculated from the
920 * facilities. A user can stop VBoxService before logging out.
921 * The runlevel should then drop to System, not Userland.
922 *
923 * Also, if given enmFacility = VBoxGuestFacilityType_Unknown, we'll be
924 * bosting the runlevel to Desktop (0 - 1 = UINT32_MAX; UINT32_MAX >=
925 * VBoxGuestFacilityType_VBoxTrayClient). */
926
927 /** @todo VBoxGuest (the driver) should track VMMDevReq_ReportGuestStatus
928 * calls per session and automatically send VBoxGuestFacilityStatus_Failed
929 * for the facilites that does not have the status
930 * VBoxGuestFacilityStatus_Terminated, VBoxGuestFacilityStatus_Failed or
931 * VBoxGuestFacilityStatus_Inactive. Not doing so means this
932 * information is not reliable. */
933
934 /*
935 * Set a specific facility status.
936 */
937 if (enmFacility > VBoxGuestFacilityType_Unknown)
938 {
939 if (enmFacility == VBoxGuestFacilityType_All)
940 {
941 FacilityMapIter it = mData.mFacilityMap.begin();
942 while (it != mData.mFacilityMap.end())
943 {
944 facilityUpdate((VBoxGuestFacilityType)it->first, enmStatus);
945 it++;
946 }
947 }
948 else /* Update one facility only. */
949 facilityUpdate(enmFacility, enmStatus);
950 }
951}
952
953/**
954 * Sets the supported features (and whether they are active or not).
955 *
956 * @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
957 */
958void Guest::setSupportedFeatures(uint32_t aCaps)
959{
960 AutoCaller autoCaller(this);
961 AssertComRCReturnVoid(autoCaller.rc());
962
963 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
964
965 facilityUpdate(VBoxGuestFacilityType_Seamless, aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ?
966 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
967 /** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
968 facilityUpdate(VBoxGuestFacilityType_Graphics, aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ?
969 VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
970}
971/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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