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