VirtualBox

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

Last change on this file since 8217 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
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.virtualbox.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(SupportsSeamless) (BOOL *aSupportsSeamless)
164{
165 if (!aSupportsSeamless)
166 return E_POINTER;
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 if (!aSupportsGraphics)
181 return E_POINTER;
182
183 AutoCaller autoCaller (this);
184 CheckComRCReturnRC (autoCaller.rc());
185
186 AutoReadLock alock (this);
187
188 *aSupportsGraphics = mData.mSupportsGraphics;
189
190 return S_OK;
191}
192
193STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
194{
195 if (!aMemoryBalloonSize)
196 return E_POINTER;
197
198 AutoCaller autoCaller (this);
199 CheckComRCReturnRC (autoCaller.rc());
200
201 AutoReadLock alock (this);
202
203 *aMemoryBalloonSize = mMemoryBalloonSize;
204
205 return S_OK;
206}
207
208STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
209{
210 AutoCaller autoCaller (this);
211 CheckComRCReturnRC (autoCaller.rc());
212
213 AutoWriteLock alock (this);
214
215 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
216 if (ret == S_OK)
217 {
218 mMemoryBalloonSize = aMemoryBalloonSize;
219 /* forward the information to the VMM device */
220 VMMDev *vmmDev = mParent->getVMMDev();
221 if (vmmDev)
222 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
223 }
224
225 return ret;
226}
227
228STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
229{
230 if (!aUpdateInterval)
231 return E_POINTER;
232
233 AutoCaller autoCaller (this);
234 CheckComRCReturnRC (autoCaller.rc());
235
236 AutoReadLock alock (this);
237
238 *aUpdateInterval = mStatUpdateInterval;
239
240 return S_OK;
241}
242
243STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
244{
245 AutoCaller autoCaller (this);
246 CheckComRCReturnRC (autoCaller.rc());
247
248 AutoWriteLock alock (this);
249
250 HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
251 if (ret == S_OK)
252 {
253 mStatUpdateInterval = aUpdateInterval;
254 /* forward the information to the VMM device */
255 VMMDev *vmmDev = mParent->getVMMDev();
256 if (vmmDev)
257 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
258 }
259
260 return ret;
261}
262
263STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
264 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
265{
266 if (!aUserName || !aPassword || !aDomain)
267 return E_INVALIDARG;
268
269 AutoCaller autoCaller (this);
270 CheckComRCReturnRC (autoCaller.rc());
271
272 /* forward the information to the VMM device */
273 VMMDev *vmmDev = mParent->getVMMDev();
274 if (vmmDev)
275 {
276 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
277 if (!aAllowInteractiveLogon)
278 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
279
280 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
281 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
282 Utf8Str(aDomain).raw(), u32Flags);
283 return S_OK;
284 }
285
286 return setError (E_FAIL,
287 tr ("VMM device is not available (is the VM running?)"));
288}
289
290STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
291{
292 if (!aStatVal)
293 return E_INVALIDARG;
294
295 if (aCpuId != 0)
296 return E_INVALIDARG;
297
298 if (aStatistic >= GuestStatisticType_MaxVal)
299 return E_INVALIDARG;
300
301 /* not available or not yet reported? */
302 if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
303 return E_INVALIDARG;
304
305 *aStatVal = mCurrentGuestStat[aStatistic];
306 return S_OK;
307}
308
309STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
310{
311 if (aCpuId != 0)
312 return E_INVALIDARG;
313
314 if (aStatistic >= GuestStatisticType_MaxVal)
315 return E_INVALIDARG;
316
317 /* internal method assumes that the caller known what he's doing (no boundary checks) */
318 mCurrentGuestStat[aStatistic] = aStatVal;
319 return S_OK;
320}
321
322// public methods only for internal purposes
323/////////////////////////////////////////////////////////////////////////////
324
325void Guest::setAdditionsVersion (Bstr aVersion)
326{
327 AssertReturnVoid (!aVersion.isEmpty());
328
329 AutoCaller autoCaller (this);
330 AssertComRCReturnVoid (autoCaller.rc());
331
332 AutoWriteLock alock (this);
333
334 mData.mAdditionsVersion = aVersion;
335 /* this implies that Additions are active */
336 mData.mAdditionsActive = TRUE;
337}
338
339void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
340{
341 AutoCaller autoCaller (this);
342 AssertComRCReturnVoid (autoCaller.rc());
343
344 AutoWriteLock alock (this);
345
346 mData.mSupportsSeamless = aSupportsSeamless;
347}
348
349void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
350{
351 AutoCaller autoCaller (this);
352 AssertComRCReturnVoid (autoCaller.rc());
353
354 AutoWriteLock alock (this);
355
356 mData.mSupportsGraphics = aSupportsGraphics;
357}
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