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
Line 
1/* $Id: GuestImpl.cpp 16125 2009-01-21 11:03:50Z 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 "Logging.h"
31
32#include <VBox/VBoxDev.h>
33#include <iprt/cpputils.h>
34
35// defines
36/////////////////////////////////////////////////////////////////////////////
37
38// constructor / destructor
39/////////////////////////////////////////////////////////////////////////////
40
41DEFINE_EMPTY_CTOR_DTOR (Guest)
42
43HRESULT Guest::FinalConstruct()
44{
45 return S_OK;
46}
47
48void Guest::FinalRelease()
49{
50 uninit ();
51}
52
53// public methods only for internal purposes
54/////////////////////////////////////////////////////////////////////////////
55
56/**
57 * Initializes the guest object.
58 */
59HRESULT Guest::init (Console *aParent)
60{
61 LogFlowThisFunc (("aParent=%p\n", aParent));
62
63 ComAssertRet (aParent, E_INVALIDARG);
64
65 /* Enclose the state transition NotReady->InInit->Ready */
66 AutoInitSpan autoInitSpan (this);
67 AssertReturn (autoInitSpan.isOk(), E_FAIL);
68
69 unconst (mParent) = aParent;
70
71 /* mData.mAdditionsActive is FALSE */
72
73 /* Confirm a successful initialization when it's the case */
74 autoInitSpan.setSucceeded();
75
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 */
82
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
90 /* invalidate all stats */
91 for (int i=0;i<GuestStatisticType_MaxVal;i++)
92 mCurrentGuestStat[i] = GUEST_STAT_INVALID;
93
94 /* start with sample 0 */
95 mCurrentGuestStat[GuestStatisticType_SampleNumber] = 0;
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{
105 LogFlowThisFunc (("\n"));
106
107 /* Enclose the state transition Ready->InUninit->NotReady */
108 AutoUninitSpan autoUninitSpan (this);
109 if (autoUninitSpan.uninitDone())
110 return;
111
112 unconst (mParent).setNull();
113}
114
115// IGuest properties
116/////////////////////////////////////////////////////////////////////////////
117
118STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
119{
120 CheckComArgOutPointerValid(aOSTypeId);
121
122 AutoCaller autoCaller (this);
123 CheckComRCReturnRC (autoCaller.rc());
124
125 AutoReadLock alock (this);
126
127 // redirect the call to IMachine if no additions are installed
128 if (mData.mAdditionsVersion.isNull())
129 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
130
131 mData.mOSTypeId.cloneTo (aOSTypeId);
132
133 return S_OK;
134}
135
136STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
137{
138 CheckComArgOutPointerValid(aAdditionsActive);
139
140 AutoCaller autoCaller (this);
141 CheckComRCReturnRC (autoCaller.rc());
142
143 AutoReadLock alock (this);
144
145 *aAdditionsActive = mData.mAdditionsActive;
146
147 return S_OK;
148}
149
150STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
151{
152 CheckComArgOutPointerValid(aAdditionsVersion);
153
154 AutoCaller autoCaller (this);
155 CheckComRCReturnRC (autoCaller.rc());
156
157 AutoReadLock alock (this);
158
159 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
160
161 return S_OK;
162}
163
164STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
165{
166 CheckComArgOutPointerValid(aSupportsSeamless);
167
168 AutoCaller autoCaller (this);
169 CheckComRCReturnRC (autoCaller.rc());
170
171 AutoReadLock alock (this);
172
173 *aSupportsSeamless = mData.mSupportsSeamless;
174
175 return S_OK;
176}
177
178STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
179{
180 CheckComArgOutPointerValid(aSupportsGraphics);
181
182 AutoCaller autoCaller (this);
183 CheckComRCReturnRC (autoCaller.rc());
184
185 AutoReadLock alock (this);
186
187 *aSupportsGraphics = mData.mSupportsGraphics;
188
189 return S_OK;
190}
191
192STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
193{
194 CheckComArgOutPointerValid(aMemoryBalloonSize);
195
196 AutoCaller autoCaller (this);
197 CheckComRCReturnRC (autoCaller.rc());
198
199 AutoReadLock alock (this);
200
201 *aMemoryBalloonSize = mMemoryBalloonSize;
202
203 return S_OK;
204}
205
206STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
207{
208 AutoCaller autoCaller (this);
209 CheckComRCReturnRC (autoCaller.rc());
210
211 AutoWriteLock alock (this);
212
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 }
222
223 return ret;
224}
225
226STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
227{
228 CheckComArgOutPointerValid(aUpdateInterval);
229
230 AutoCaller autoCaller (this);
231 CheckComRCReturnRC (autoCaller.rc());
232
233 AutoReadLock alock (this);
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
245 AutoWriteLock alock (this);
246
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 }
256
257 return ret;
258}
259
260STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
261 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
262{
263 CheckComArgNotNull(aUserName);
264 CheckComArgNotNull(aPassword);
265 CheckComArgNotNull(aDomain);
266
267 AutoCaller autoCaller (this);
268 CheckComRCReturnRC (autoCaller.rc());
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(),
279 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
280 Utf8Str(aDomain).raw(), u32Flags);
281 return S_OK;
282 }
283
284 return setError (VBOX_E_VM_ERROR,
285 tr ("VMM device is not available (is the VM running?)"));
286}
287
288STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
289{
290 CheckComArgExpr(aCpuId, aCpuId == 0);
291 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
292 CheckComArgOutPointerValid(aStatVal);
293
294 /* not available or not yet reported? */
295 CheckComArgExpr(aStatistic, mCurrentGuestStat[aStatistic] != GUEST_STAT_INVALID);
296
297 *aStatVal = mCurrentGuestStat[aStatistic];
298 return S_OK;
299}
300
301STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
302{
303 CheckComArgExpr(aCpuId, aCpuId == 0);
304 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
305
306 /* internal method assumes that the caller knows what he's doing (no boundary checks) */
307 mCurrentGuestStat[aStatistic] = aStatVal;
308 return S_OK;
309}
310
311// public methods only for internal purposes
312/////////////////////////////////////////////////////////////////////////////
313
314void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
315{
316 Assert(aVersion.isNull() || !aVersion.isEmpty());
317
318 AutoCaller autoCaller (this);
319 AssertComRCReturnVoid (autoCaller.rc());
320
321 AutoWriteLock alock (this);
322
323 mData.mAdditionsVersion = aVersion;
324 mData.mAdditionsActive = !aVersion.isNull();
325
326 mData.mOSTypeId = Global::OSTypeId (aOsType);
327}
328
329void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
330{
331 AutoCaller autoCaller (this);
332 AssertComRCReturnVoid (autoCaller.rc());
333
334 AutoWriteLock alock (this);
335
336 mData.mSupportsSeamless = aSupportsSeamless;
337}
338
339void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
340{
341 AutoCaller autoCaller (this);
342 AssertComRCReturnVoid (autoCaller.rc());
343
344 AutoWriteLock alock (this);
345
346 mData.mSupportsGraphics = aSupportsGraphics;
347}
348/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use