VirtualBox

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

Last change on this file since 25414 was 25346, checked in by vboxsync, 14 years ago

iprt/cpputils.h -> iprt/cpp/utils.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: GuestImpl.cpp 25346 2009-12-13 16:21: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 "Logging.h"
31
32#include <VBox/VMMDev.h>
33#include <iprt/cpp/utils.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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
124
125 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
142
143 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
156
157 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
170
171 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
184
185 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
198
199 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
200
201 *aMemoryBalloonSize = mMemoryBalloonSize;
202
203 return S_OK;
204}
205
206STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
207{
208 AutoCaller autoCaller(this);
209 if (FAILED(autoCaller.rc())) return autoCaller.rc();
210
211 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return autoCaller.rc();
232
233 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
234
235 *aUpdateInterval = mStatUpdateInterval;
236
237 return S_OK;
238}
239
240STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
241{
242 AutoCaller autoCaller(this);
243 if (FAILED(autoCaller.rc())) return autoCaller.rc();
244
245 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
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 if (FAILED(autoCaller.rc())) return 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? 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;
298
299 *aStatVal = mCurrentGuestStat[aStatistic];
300 return S_OK;
301}
302
303STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
304{
305 CheckComArgExpr(aCpuId, aCpuId == 0);
306 CheckComArgExpr(aStatistic, aStatistic < GuestStatisticType_MaxVal);
307
308 /* internal method assumes that the caller knows what he's doing (no boundary checks) */
309 mCurrentGuestStat[aStatistic] = aStatVal;
310 return S_OK;
311}
312
313// public methods only for internal purposes
314/////////////////////////////////////////////////////////////////////////////
315
316void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
317{
318 Assert(aVersion.isNull() || !aVersion.isEmpty());
319
320 AutoCaller autoCaller(this);
321 AssertComRCReturnVoid (autoCaller.rc());
322
323 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
324
325 mData.mAdditionsVersion = aVersion;
326 mData.mAdditionsActive = !aVersion.isNull();
327
328 mData.mOSTypeId = Global::OSTypeId (aOsType);
329}
330
331void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
332{
333 AutoCaller autoCaller(this);
334 AssertComRCReturnVoid (autoCaller.rc());
335
336 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
337
338 mData.mSupportsSeamless = aSupportsSeamless;
339}
340
341void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
342{
343 AutoCaller autoCaller(this);
344 AssertComRCReturnVoid (autoCaller.rc());
345
346 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
347
348 mData.mSupportsGraphics = aSupportsGraphics;
349}
350/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use