VirtualBox

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

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

Statistics interval controllable from within the guest from now on.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: GuestImpl.cpp 26290 2010-02-05 14:27:19Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
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
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.
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.
22 */
23
24#include "GuestImpl.h"
25
26#include "Global.h"
27#include "ConsoleImpl.h"
28#include "VMMDev.h"
29
30#include "AutoCaller.h"
31#include "Logging.h"
32
33#include <VBox/VMMDev.h>
34#include <iprt/cpp/utils.h>
35
36// defines
37/////////////////////////////////////////////////////////////////////////////
38
39// constructor / destructor
40/////////////////////////////////////////////////////////////////////////////
41
42DEFINE_EMPTY_CTOR_DTOR (Guest)
43
44HRESULT Guest::FinalConstruct()
45{
46 return S_OK;
47}
48
49void Guest::FinalRelease()
50{
51 uninit ();
52}
53
54// public methods only for internal purposes
55/////////////////////////////////////////////////////////////////////////////
56
57/**
58 * Initializes the guest object.
59 */
60HRESULT Guest::init (Console *aParent)
61{
62 LogFlowThisFunc(("aParent=%p\n", aParent));
63
64 ComAssertRet(aParent, E_INVALIDARG);
65
66 /* Enclose the state transition NotReady->InInit->Ready */
67 AutoInitSpan autoInitSpan(this);
68 AssertReturn(autoInitSpan.isOk(), E_FAIL);
69
70 unconst(mParent) = aParent;
71
72 /* mData.mAdditionsActive is FALSE */
73
74 /* Confirm a successful initialization when it's the case */
75 autoInitSpan.setSucceeded();
76
77 ULONG aMemoryBalloonSize;
78 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
79 if (ret == S_OK)
80 mMemoryBalloonSize = aMemoryBalloonSize;
81 else
82 mMemoryBalloonSize = 0; /* Default is no ballooning */
83
84 /* invalidate all stats */
85 for (int i=0;i<GuestStatisticType_MaxVal;i++)
86 mCurrentGuestStat[i] = GUEST_STAT_INVALID;
87
88 /* start with sample 0 */
89 mCurrentGuestStat[GuestStatisticType_SampleNumber] = 0;
90 return S_OK;
91}
92
93/**
94 * Uninitializes the instance and sets the ready flag to FALSE.
95 * Called either from FinalRelease() or by the parent when it gets destroyed.
96 */
97void Guest::uninit()
98{
99 LogFlowThisFunc(("\n"));
100
101 /* Enclose the state transition Ready->InUninit->NotReady */
102 AutoUninitSpan autoUninitSpan(this);
103 if (autoUninitSpan.uninitDone())
104 return;
105
106 unconst(mParent).setNull();
107}
108
109// IGuest properties
110/////////////////////////////////////////////////////////////////////////////
111
112STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
113{
114 CheckComArgOutPointerValid(aOSTypeId);
115
116 AutoCaller autoCaller(this);
117 if (FAILED(autoCaller.rc())) return autoCaller.rc();
118
119 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
120
121 // redirect the call to IMachine if no additions are installed
122 if (mData.mAdditionsVersion.isNull())
123 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
124
125 mData.mOSTypeId.cloneTo(aOSTypeId);
126
127 return S_OK;
128}
129
130STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
131{
132 CheckComArgOutPointerValid(aAdditionsActive);
133
134 AutoCaller autoCaller(this);
135 if (FAILED(autoCaller.rc())) return autoCaller.rc();
136
137 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
138
139 *aAdditionsActive = mData.mAdditionsActive;
140
141 return S_OK;
142}
143
144STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
145{
146 CheckComArgOutPointerValid(aAdditionsVersion);
147
148 AutoCaller autoCaller(this);
149 if (FAILED(autoCaller.rc())) return autoCaller.rc();
150
151 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
152
153 mData.mAdditionsVersion.cloneTo(aAdditionsVersion);
154
155 return S_OK;
156}
157
158STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
159{
160 CheckComArgOutPointerValid(aSupportsSeamless);
161
162 AutoCaller autoCaller(this);
163 if (FAILED(autoCaller.rc())) return autoCaller.rc();
164
165 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
166
167 *aSupportsSeamless = mData.mSupportsSeamless;
168
169 return S_OK;
170}
171
172STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
173{
174 CheckComArgOutPointerValid(aSupportsGraphics);
175
176 AutoCaller autoCaller(this);
177 if (FAILED(autoCaller.rc())) return autoCaller.rc();
178
179 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
180
181 *aSupportsGraphics = mData.mSupportsGraphics;
182
183 return S_OK;
184}
185
186STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
187{
188 CheckComArgOutPointerValid(aMemoryBalloonSize);
189
190 AutoCaller autoCaller(this);
191 if (FAILED(autoCaller.rc())) return autoCaller.rc();
192
193 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
194
195 *aMemoryBalloonSize = mMemoryBalloonSize;
196
197 return S_OK;
198}
199
200STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
201{
202 AutoCaller autoCaller(this);
203 if (FAILED(autoCaller.rc())) return autoCaller.rc();
204
205 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
206
207 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
208 if (ret == S_OK)
209 {
210 mMemoryBalloonSize = aMemoryBalloonSize;
211 /* forward the information to the VMM device */
212 VMMDev *vmmDev = mParent->getVMMDev();
213 if (vmmDev)
214 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
215 }
216
217 return ret;
218}
219
220
221STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
222 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
223{
224 CheckComArgNotNull(aUserName);
225 CheckComArgNotNull(aPassword);
226 CheckComArgNotNull(aDomain);
227
228 AutoCaller autoCaller(this);
229 if (FAILED(autoCaller.rc())) return autoCaller.rc();
230
231 /* forward the information to the VMM device */
232 VMMDev *vmmDev = mParent->getVMMDev();
233 if (vmmDev)
234 {
235 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
236 if (!aAllowInteractiveLogon)
237 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
238
239 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
240 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
241 Utf8Str(aDomain).raw(), u32Flags);
242 return S_OK;
243 }
244
245 return setError(VBOX_E_VM_ERROR,
246 tr("VMM device is not available (is the VM running?)"));
247}
248
249STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
250{
251 CheckComArgExpr(aCpuId, aCpuId == 0);
252 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
253 CheckComArgOutPointerValid(aStatVal);
254
255 /* Not available or not yet reported? In that case, just return with a proper error
256 * but don't use setError(). */
257 if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
258 return E_INVALIDARG;
259
260 *aStatVal = mCurrentGuestStat[aStatistic];
261 return S_OK;
262}
263
264STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
265{
266 CheckComArgExpr(aCpuId, aCpuId == 0);
267 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
268
269 /* internal method assumes that the caller knows what he's doing (no boundary checks) */
270 mCurrentGuestStat[aStatistic] = aStatVal;
271 return S_OK;
272}
273
274// public methods only for internal purposes
275/////////////////////////////////////////////////////////////////////////////
276
277void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
278{
279 Assert(aVersion.isNull() || !aVersion.isEmpty());
280
281 AutoCaller autoCaller(this);
282 AssertComRCReturnVoid (autoCaller.rc());
283
284 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
285
286 mData.mAdditionsVersion = aVersion;
287 mData.mAdditionsActive = !aVersion.isNull();
288
289 mData.mOSTypeId = Global::OSTypeId (aOsType);
290}
291
292void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
293{
294 AutoCaller autoCaller(this);
295 AssertComRCReturnVoid (autoCaller.rc());
296
297 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
298
299 mData.mSupportsSeamless = aSupportsSeamless;
300}
301
302void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
303{
304 AutoCaller autoCaller(this);
305 AssertComRCReturnVoid (autoCaller.rc());
306
307 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
308
309 mData.mSupportsGraphics = aSupportsGraphics;
310}
311/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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