VirtualBox

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

最後變更 在這個檔案從8350是 8350,由 vboxsync 提交於 17 年 前

Main: revert r30118, as we already log this in VMMDev

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.1 KB
 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "GuestImpl.h"
23#include "ConsoleImpl.h"
24#include "VMMDev.h"
25
26#include "Logging.h"
27
28#include <VBox/VBoxDev.h>
29#include <iprt/cpputils.h>
30
31// defines
32/////////////////////////////////////////////////////////////////////////////
33
34// constructor / destructor
35/////////////////////////////////////////////////////////////////////////////
36
37DEFINE_EMPTY_CTOR_DTOR (Guest)
38
39HRESULT Guest::FinalConstruct()
40{
41 return S_OK;
42}
43
44void Guest::FinalRelease()
45{
46 uninit ();
47}
48
49// public methods only for internal purposes
50/////////////////////////////////////////////////////////////////////////////
51
52/**
53 * Initializes the guest object.
54 */
55HRESULT Guest::init (Console *aParent)
56{
57 LogFlowThisFunc (("aParent=%p\n", aParent));
58
59 ComAssertRet (aParent, E_INVALIDARG);
60
61 /* Enclose the state transition NotReady->InInit->Ready */
62 AutoInitSpan autoInitSpan (this);
63 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
64
65 unconst (mParent) = aParent;
66
67 /* mData.mAdditionsActive is FALSE */
68
69 /* Confirm a successful initialization when it's the case */
70 autoInitSpan.setSucceeded();
71
72 ULONG aMemoryBalloonSize;
73 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
74 if (ret == S_OK)
75 mMemoryBalloonSize = aMemoryBalloonSize;
76 else
77 mMemoryBalloonSize = 0; /* Default is no ballooning */
78
79 ULONG aStatUpdateInterval;
80 ret = mParent->machine()->COMGETTER(StatisticsUpdateInterval)(&aStatUpdateInterval);
81 if (ret == S_OK)
82 mStatUpdateInterval = aStatUpdateInterval;
83 else
84 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
85
86 /* invalidate all stats */
87 for (int i=0;i<GuestStatisticType_MaxVal;i++)
88 mCurrentGuestStat[i] = GUEST_STAT_INVALID;
89
90 /* start with sample 0 */
91 mCurrentGuestStat[GuestStatisticType_SampleNumber] = 0;
92 return S_OK;
93}
94
95/**
96 * Uninitializes the instance and sets the ready flag to FALSE.
97 * Called either from FinalRelease() or by the parent when it gets destroyed.
98 */
99void Guest::uninit()
100{
101 LogFlowThisFunc (("\n"));
102
103 /* Enclose the state transition Ready->InUninit->NotReady */
104 AutoUninitSpan autoUninitSpan (this);
105 if (autoUninitSpan.uninitDone())
106 return;
107
108 unconst (mParent).setNull();
109}
110
111// IGuest properties
112/////////////////////////////////////////////////////////////////////////////
113
114STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
115{
116 if (!aOSTypeId)
117 return E_POINTER;
118
119 AutoCaller autoCaller (this);
120 CheckComRCReturnRC (autoCaller.rc());
121
122 AutoReadLock alock (this);
123
124 // redirect the call to IMachine if no additions are installed
125 if (mData.mAdditionsVersion.isNull())
126 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
127
128 mData.mOSTypeId.cloneTo (aOSTypeId);
129
130 return S_OK;
131}
132
133STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
134{
135 if (!aAdditionsActive)
136 return E_POINTER;
137
138 AutoCaller autoCaller (this);
139 CheckComRCReturnRC (autoCaller.rc());
140
141 AutoReadLock alock (this);
142
143 *aAdditionsActive = mData.mAdditionsActive;
144
145 return S_OK;
146}
147
148STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
149{
150 if (!aAdditionsVersion)
151 return E_POINTER;
152
153 AutoCaller autoCaller (this);
154 CheckComRCReturnRC (autoCaller.rc());
155
156 AutoReadLock alock (this);
157
158 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
159
160 return S_OK;
161}
162
163STDMETHODIMP Guest::COMGETTER(MaxGuestWidth) (ULONG *aMaxWidth)
164{
165 if (!VALID_PTR(aMaxWidth))
166 return E_POINTER;
167
168 AutoCaller autoCaller (this);
169 CheckComRCReturnRC (autoCaller.rc());
170
171 AutoReadLock alock (this);
172
173 *aMaxWidth = mData.mMaxWidth;
174
175 return S_OK;
176}
177
178STDMETHODIMP Guest::COMGETTER(MaxGuestHeight) (ULONG *aMaxHeight)
179{
180 if (!VALID_PTR(aMaxHeight))
181 return E_POINTER;
182
183 AutoCaller autoCaller (this);
184 CheckComRCReturnRC (autoCaller.rc());
185
186 AutoReadLock alock (this);
187
188 *aMaxHeight = mData.mMaxHeight;
189
190 return S_OK;
191}
192
193STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
194{
195 if (!aSupportsSeamless)
196 return E_POINTER;
197
198 AutoCaller autoCaller (this);
199 CheckComRCReturnRC (autoCaller.rc());
200
201 AutoReadLock alock (this);
202
203 *aSupportsSeamless = mData.mSupportsSeamless;
204
205 return S_OK;
206}
207
208STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
209{
210 if (!aSupportsGraphics)
211 return E_POINTER;
212
213 AutoCaller autoCaller (this);
214 CheckComRCReturnRC (autoCaller.rc());
215
216 AutoReadLock alock (this);
217
218 *aSupportsGraphics = mData.mSupportsGraphics;
219
220 return S_OK;
221}
222
223STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
224{
225 if (!aMemoryBalloonSize)
226 return E_POINTER;
227
228 AutoCaller autoCaller (this);
229 CheckComRCReturnRC (autoCaller.rc());
230
231 AutoReadLock alock (this);
232
233 *aMemoryBalloonSize = mMemoryBalloonSize;
234
235 return S_OK;
236}
237
238STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
239{
240 AutoCaller autoCaller (this);
241 CheckComRCReturnRC (autoCaller.rc());
242
243 AutoWriteLock alock (this);
244
245 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
246 if (ret == S_OK)
247 {
248 mMemoryBalloonSize = aMemoryBalloonSize;
249 /* forward the information to the VMM device */
250 VMMDev *vmmDev = mParent->getVMMDev();
251 if (vmmDev)
252 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
253 }
254
255 return ret;
256}
257
258STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
259{
260 if (!aUpdateInterval)
261 return E_POINTER;
262
263 AutoCaller autoCaller (this);
264 CheckComRCReturnRC (autoCaller.rc());
265
266 AutoReadLock alock (this);
267
268 *aUpdateInterval = mStatUpdateInterval;
269
270 return S_OK;
271}
272
273STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
274{
275 AutoCaller autoCaller (this);
276 CheckComRCReturnRC (autoCaller.rc());
277
278 AutoWriteLock alock (this);
279
280 HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
281 if (ret == S_OK)
282 {
283 mStatUpdateInterval = aUpdateInterval;
284 /* forward the information to the VMM device */
285 VMMDev *vmmDev = mParent->getVMMDev();
286 if (vmmDev)
287 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
288 }
289
290 return ret;
291}
292
293STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
294 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
295{
296 if (!aUserName || !aPassword || !aDomain)
297 return E_INVALIDARG;
298
299 AutoCaller autoCaller (this);
300 CheckComRCReturnRC (autoCaller.rc());
301
302 /* forward the information to the VMM device */
303 VMMDev *vmmDev = mParent->getVMMDev();
304 if (vmmDev)
305 {
306 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
307 if (!aAllowInteractiveLogon)
308 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
309
310 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
311 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
312 Utf8Str(aDomain).raw(), u32Flags);
313 return S_OK;
314 }
315
316 return setError (E_FAIL,
317 tr ("VMM device is not available (is the VM running?)"));
318}
319
320STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
321{
322 if (!aStatVal)
323 return E_INVALIDARG;
324
325 if (aCpuId != 0)
326 return E_INVALIDARG;
327
328 if (aStatistic >= GuestStatisticType_MaxVal)
329 return E_INVALIDARG;
330
331 /* not available or not yet reported? */
332 if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
333 return E_INVALIDARG;
334
335 *aStatVal = mCurrentGuestStat[aStatistic];
336 return S_OK;
337}
338
339STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
340{
341 if (aCpuId != 0)
342 return E_INVALIDARG;
343
344 if (aStatistic >= GuestStatisticType_MaxVal)
345 return E_INVALIDARG;
346
347 /* internal method assumes that the caller known what he's doing (no boundary checks) */
348 mCurrentGuestStat[aStatistic] = aStatVal;
349 return S_OK;
350}
351
352// public methods only for internal purposes
353/////////////////////////////////////////////////////////////////////////////
354
355void Guest::setAdditionsVersion (Bstr aVersion)
356{
357 AssertReturnVoid (!aVersion.isEmpty());
358
359 AutoCaller autoCaller (this);
360 AssertComRCReturnVoid (autoCaller.rc());
361
362 AutoWriteLock alock (this);
363
364 mData.mAdditionsVersion = aVersion;
365 /* this implies that Additions are active */
366 mData.mAdditionsActive = TRUE;
367}
368
369void Guest::setMaxGuestResolution (ULONG aMaxWidth, ULONG aMaxHeight)
370{
371 AutoCaller autoCaller (this);
372 AssertComRCReturnVoid (autoCaller.rc());
373
374 AutoWriteLock alock (this);
375
376 mData.mMaxWidth = aMaxWidth;
377 mData.mMaxHeight = aMaxHeight;
378}
379
380void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
381{
382 AutoCaller autoCaller (this);
383 AssertComRCReturnVoid (autoCaller.rc());
384
385 AutoWriteLock alock (this);
386
387 mData.mSupportsSeamless = aSupportsSeamless;
388}
389
390void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
391{
392 AutoCaller autoCaller (this);
393 AssertComRCReturnVoid (autoCaller.rc());
394
395 AutoWriteLock alock (this);
396
397 mData.mSupportsGraphics = aSupportsGraphics;
398}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette