VirtualBox

source: vbox/trunk/src/VBox/Main/GuestImpl.cpp@ 16560

Last change on this file since 16560 was 16125, checked in by vboxsync, 15 years ago

Guest::SetStatistic argument check as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
RevLine 
[9360]1/* $Id: GuestImpl.cpp 16125 2009-01-21 11:03:50Z 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
32#include <VBox/VBoxDev.h>
[3007]33#include <iprt/cpputils.h>
[1]34
35// defines
36/////////////////////////////////////////////////////////////////////////////
37
38// constructor / destructor
39/////////////////////////////////////////////////////////////////////////////
40
[2567]41DEFINE_EMPTY_CTOR_DTOR (Guest)
42
[1]43HRESULT Guest::FinalConstruct()
44{
45 return S_OK;
46}
47
48void 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 */
59HRESULT Guest::init (Console *aParent)
60{
[2567]61 LogFlowThisFunc (("aParent=%p\n", aParent));
[1]62
63 ComAssertRet (aParent, E_INVALIDARG);
64
[2567]65 /* Enclose the state transition NotReady->InInit->Ready */
66 AutoInitSpan autoInitSpan (this);
[14579]67 AssertReturn (autoInitSpan.isOk(), E_FAIL);
[1]68
[2567]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 */
103void Guest::uninit()
104{
[2567]105 LogFlowThisFunc (("\n"));
[1]106
[2567]107 /* Enclose the state transition Ready->InUninit->NotReady */
108 AutoUninitSpan autoUninitSpan (this);
109 if (autoUninitSpan.uninitDone())
110 return;
[1]111
[2567]112 unconst (mParent).setNull();
[1]113}
114
115// IGuest properties
116/////////////////////////////////////////////////////////////////////////////
117
[2567]118STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
[1]119{
[14972]120 CheckComArgOutPointerValid(aOSTypeId);
[1]121
[2567]122 AutoCaller autoCaller (this);
123 CheckComRCReturnRC (autoCaller.rc());
[1]124
[8083]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
[2567]131 mData.mOSTypeId.cloneTo (aOSTypeId);
132
[1]133 return S_OK;
134}
135
136STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
137{
[14972]138 CheckComArgOutPointerValid(aAdditionsActive);
[1]139
[2567]140 AutoCaller autoCaller (this);
141 CheckComRCReturnRC (autoCaller.rc());
[1]142
[8083]143 AutoReadLock alock (this);
[2567]144
145 *aAdditionsActive = mData.mAdditionsActive;
146
[1]147 return S_OK;
148}
149
150STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
151{
[14972]152 CheckComArgOutPointerValid(aAdditionsVersion);
[1]153
[2567]154 AutoCaller autoCaller (this);
155 CheckComRCReturnRC (autoCaller.rc());
[1]156
[8083]157 AutoReadLock alock (this);
[2567]158
159 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
160
[1]161 return S_OK;
162}
163
[3911]164STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
[3582]165{
[14972]166 CheckComArgOutPointerValid(aSupportsSeamless);
[3582]167
168 AutoCaller autoCaller (this);
169 CheckComRCReturnRC (autoCaller.rc());
170
[8083]171 AutoReadLock alock (this);
[3582]172
[3911]173 *aSupportsSeamless = mData.mSupportsSeamless;
[3582]174
175 return S_OK;
176}
177
[7409]178STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
179{
[14972]180 CheckComArgOutPointerValid(aSupportsGraphics);
[7409]181
182 AutoCaller autoCaller (this);
183 CheckComRCReturnRC (autoCaller.rc());
184
[8083]185 AutoReadLock alock (this);
[7409]186
187 *aSupportsGraphics = mData.mSupportsGraphics;
188
189 return S_OK;
190}
191
[4314]192STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
193{
[14972]194 CheckComArgOutPointerValid(aMemoryBalloonSize);
[4314]195
196 AutoCaller autoCaller (this);
197 CheckComRCReturnRC (autoCaller.rc());
198
[8083]199 AutoReadLock alock (this);
[4314]200
201 *aMemoryBalloonSize = mMemoryBalloonSize;
202
203 return S_OK;
204}
205
206STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
207{
[4318]208 AutoCaller autoCaller (this);
209 CheckComRCReturnRC (autoCaller.rc());
210
[8083]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]226STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
227{
[14972]228 CheckComArgOutPointerValid(aUpdateInterval);
[4318]229
230 AutoCaller autoCaller (this);
231 CheckComRCReturnRC (autoCaller.rc());
232
[8083]233 AutoReadLock alock (this);
[4318]234
235 *aUpdateInterval = mStatUpdateInterval;
236
237 return S_OK;
238}
239
240STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
241{
242 AutoCaller autoCaller (this);
243 CheckComRCReturnRC (autoCaller.rc());
244
[8083]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]260STDMETHODIMP 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
[2567]267 AutoCaller autoCaller (this);
268 CheckComRCReturnRC (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]288STDMETHODIMP 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
[4647]294 /* not available or not yet reported? */
[14972]295 CheckComArgExpr(aStatistic, mCurrentGuestStat[aStatistic] != GUEST_STAT_INVALID);
[4647]296
297 *aStatVal = mCurrentGuestStat[aStatistic];
[4316]298 return S_OK;
299}
300
[4571]301STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
[4316]302{
[16125]303 CheckComArgExpr(aCpuId, aCpuId == 0);
[14972]304 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
[4571]305
[14972]306 /* internal method assumes that the caller knows what he's doing (no boundary checks) */
[4647]307 mCurrentGuestStat[aStatistic] = aStatVal;
[4316]308 return S_OK;
309}
310
[1]311// public methods only for internal purposes
312/////////////////////////////////////////////////////////////////////////////
313
[8690]314void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
[1]315{
[8690]316 Assert(aVersion.isNull() || !aVersion.isEmpty());
[2567]317
318 AutoCaller autoCaller (this);
319 AssertComRCReturnVoid (autoCaller.rc());
320
[8083]321 AutoWriteLock alock (this);
[2567]322
323 mData.mAdditionsVersion = aVersion;
[8690]324 mData.mAdditionsActive = !aVersion.isNull();
[9360]325
326 mData.mOSTypeId = Global::OSTypeId (aOsType);
[1]327}
[3582]328
[3911]329void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
[3582]330{
331 AutoCaller autoCaller (this);
332 AssertComRCReturnVoid (autoCaller.rc());
333
[8083]334 AutoWriteLock alock (this);
[3582]335
[3911]336 mData.mSupportsSeamless = aSupportsSeamless;
[3582]337}
[7409]338
339void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
340{
341 AutoCaller autoCaller (this);
342 AssertComRCReturnVoid (autoCaller.rc());
343
[8083]344 AutoWriteLock alock (this);
[7409]345
346 mData.mSupportsGraphics = aSupportsGraphics;
347}
[14772]348/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use