VirtualBox

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

Last change on this file since 11938 was 9360, checked in by vboxsync, 17 years ago

Main: Return the correct value for IGuest::OSTypeId as reported by the guest additions when they are active (fixes #1761#c77).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1/* $Id: GuestImpl.cpp 9360 2008-06-03 17:10:09Z 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_UNEXPECTED);
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 if (!aOSTypeId)
121 return E_POINTER;
122
123 AutoCaller autoCaller (this);
124 CheckComRCReturnRC (autoCaller.rc());
125
126 AutoReadLock alock (this);
127
128 // redirect the call to IMachine if no additions are installed
129 if (mData.mAdditionsVersion.isNull())
130 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
131
132 mData.mOSTypeId.cloneTo (aOSTypeId);
133
134 return S_OK;
135}
136
137STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
138{
139 if (!aAdditionsActive)
140 return E_POINTER;
141
142 AutoCaller autoCaller (this);
143 CheckComRCReturnRC (autoCaller.rc());
144
145 AutoReadLock alock (this);
146
147 *aAdditionsActive = mData.mAdditionsActive;
148
149 return S_OK;
150}
151
152STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
153{
154 if (!aAdditionsVersion)
155 return E_POINTER;
156
157 AutoCaller autoCaller (this);
158 CheckComRCReturnRC (autoCaller.rc());
159
160 AutoReadLock alock (this);
161
162 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
163
164 return S_OK;
165}
166
167STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
168{
169 if (!aSupportsSeamless)
170 return E_POINTER;
171
172 AutoCaller autoCaller (this);
173 CheckComRCReturnRC (autoCaller.rc());
174
175 AutoReadLock alock (this);
176
177 *aSupportsSeamless = mData.mSupportsSeamless;
178
179 return S_OK;
180}
181
182STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
183{
184 if (!aSupportsGraphics)
185 return E_POINTER;
186
187 AutoCaller autoCaller (this);
188 CheckComRCReturnRC (autoCaller.rc());
189
190 AutoReadLock alock (this);
191
192 *aSupportsGraphics = mData.mSupportsGraphics;
193
194 return S_OK;
195}
196
197STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
198{
199 if (!aMemoryBalloonSize)
200 return E_POINTER;
201
202 AutoCaller autoCaller (this);
203 CheckComRCReturnRC (autoCaller.rc());
204
205 AutoReadLock alock (this);
206
207 *aMemoryBalloonSize = mMemoryBalloonSize;
208
209 return S_OK;
210}
211
212STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
213{
214 AutoCaller autoCaller (this);
215 CheckComRCReturnRC (autoCaller.rc());
216
217 AutoWriteLock alock (this);
218
219 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
220 if (ret == S_OK)
221 {
222 mMemoryBalloonSize = aMemoryBalloonSize;
223 /* forward the information to the VMM device */
224 VMMDev *vmmDev = mParent->getVMMDev();
225 if (vmmDev)
226 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
227 }
228
229 return ret;
230}
231
232STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
233{
234 if (!aUpdateInterval)
235 return E_POINTER;
236
237 AutoCaller autoCaller (this);
238 CheckComRCReturnRC (autoCaller.rc());
239
240 AutoReadLock alock (this);
241
242 *aUpdateInterval = mStatUpdateInterval;
243
244 return S_OK;
245}
246
247STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
248{
249 AutoCaller autoCaller (this);
250 CheckComRCReturnRC (autoCaller.rc());
251
252 AutoWriteLock alock (this);
253
254 HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
255 if (ret == S_OK)
256 {
257 mStatUpdateInterval = aUpdateInterval;
258 /* forward the information to the VMM device */
259 VMMDev *vmmDev = mParent->getVMMDev();
260 if (vmmDev)
261 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
262 }
263
264 return ret;
265}
266
267STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
268 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
269{
270 if (!aUserName || !aPassword || !aDomain)
271 return E_INVALIDARG;
272
273 AutoCaller autoCaller (this);
274 CheckComRCReturnRC (autoCaller.rc());
275
276 /* forward the information to the VMM device */
277 VMMDev *vmmDev = mParent->getVMMDev();
278 if (vmmDev)
279 {
280 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
281 if (!aAllowInteractiveLogon)
282 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
283
284 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
285 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
286 Utf8Str(aDomain).raw(), u32Flags);
287 return S_OK;
288 }
289
290 return setError (E_FAIL,
291 tr ("VMM device is not available (is the VM running?)"));
292}
293
294STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
295{
296 if (!aStatVal)
297 return E_INVALIDARG;
298
299 if (aCpuId != 0)
300 return E_INVALIDARG;
301
302 if (aStatistic >= GuestStatisticType_MaxVal)
303 return E_INVALIDARG;
304
305 /* not available or not yet reported? */
306 if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
307 return E_INVALIDARG;
308
309 *aStatVal = mCurrentGuestStat[aStatistic];
310 return S_OK;
311}
312
313STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
314{
315 if (aCpuId != 0)
316 return E_INVALIDARG;
317
318 if (aStatistic >= GuestStatisticType_MaxVal)
319 return E_INVALIDARG;
320
321 /* internal method assumes that the caller known what he's doing (no boundary checks) */
322 mCurrentGuestStat[aStatistic] = aStatVal;
323 return S_OK;
324}
325
326// public methods only for internal purposes
327/////////////////////////////////////////////////////////////////////////////
328
329void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType)
330{
331 Assert(aVersion.isNull() || !aVersion.isEmpty());
332
333 AutoCaller autoCaller (this);
334 AssertComRCReturnVoid (autoCaller.rc());
335
336 AutoWriteLock alock (this);
337
338 mData.mAdditionsVersion = aVersion;
339 mData.mAdditionsActive = !aVersion.isNull();
340
341 mData.mOSTypeId = Global::OSTypeId (aOsType);
342}
343
344void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
345{
346 AutoCaller autoCaller (this);
347 AssertComRCReturnVoid (autoCaller.rc());
348
349 AutoWriteLock alock (this);
350
351 mData.mSupportsSeamless = aSupportsSeamless;
352}
353
354void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
355{
356 AutoCaller autoCaller (this);
357 AssertComRCReturnVoid (autoCaller.rc());
358
359 AutoWriteLock alock (this);
360
361 mData.mSupportsGraphics = aSupportsGraphics;
362}
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