VirtualBox

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

Last change on this file since 4571 was 4571, checked in by vboxsync, 18 years ago

Future proof

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "GuestImpl.h"
19#include "ConsoleImpl.h"
20#include "VMMDev.h"
21
22#include "Logging.h"
23
24#include <VBox/VBoxDev.h>
25#include <iprt/cpputils.h>
26
27// defines
28/////////////////////////////////////////////////////////////////////////////
29
30// constructor / destructor
31/////////////////////////////////////////////////////////////////////////////
32
33DEFINE_EMPTY_CTOR_DTOR (Guest)
34
35HRESULT Guest::FinalConstruct()
36{
37 return S_OK;
38}
39
40void Guest::FinalRelease()
41{
42 uninit ();
43}
44
45// public methods only for internal purposes
46/////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Initializes the guest object.
50 */
51HRESULT Guest::init (Console *aParent)
52{
53 LogFlowThisFunc (("aParent=%p\n", aParent));
54
55 ComAssertRet (aParent, E_INVALIDARG);
56
57 /* Enclose the state transition NotReady->InInit->Ready */
58 AutoInitSpan autoInitSpan (this);
59 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
60
61 unconst (mParent) = aParent;
62
63 /* mData.mAdditionsActive is FALSE */
64
65 /* Confirm a successful initialization when it's the case */
66 autoInitSpan.setSucceeded();
67
68 ULONG aMemoryBalloonSize;
69 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
70 if (ret == S_OK)
71 mMemoryBalloonSize = aMemoryBalloonSize;
72 else
73 mMemoryBalloonSize = 0; /* Default is no ballooning */
74
75 ULONG aStatUpdateInterval;
76 ret = mParent->machine()->COMGETTER(StatisticsUpdateInterval)(&aStatUpdateInterval);
77 if (ret == S_OK)
78 mStatUpdateInterval = aStatUpdateInterval;
79 else
80 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
81
82 return S_OK;
83}
84
85/**
86 * Uninitializes the instance and sets the ready flag to FALSE.
87 * Called either from FinalRelease() or by the parent when it gets destroyed.
88 */
89void Guest::uninit()
90{
91 LogFlowThisFunc (("\n"));
92
93 /* Enclose the state transition Ready->InUninit->NotReady */
94 AutoUninitSpan autoUninitSpan (this);
95 if (autoUninitSpan.uninitDone())
96 return;
97
98 unconst (mParent).setNull();
99}
100
101// IGuest properties
102/////////////////////////////////////////////////////////////////////////////
103
104STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
105{
106 if (!aOSTypeId)
107 return E_POINTER;
108
109 AutoCaller autoCaller (this);
110 CheckComRCReturnRC (autoCaller.rc());
111
112 AutoReaderLock alock (this);
113
114 // redirect the call to IMachine if no additions are installed
115 if (mData.mAdditionsVersion.isNull())
116 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
117
118 mData.mOSTypeId.cloneTo (aOSTypeId);
119
120 return S_OK;
121}
122
123STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
124{
125 if (!aAdditionsActive)
126 return E_POINTER;
127
128 AutoCaller autoCaller (this);
129 CheckComRCReturnRC (autoCaller.rc());
130
131 AutoReaderLock alock (this);
132
133 *aAdditionsActive = mData.mAdditionsActive;
134
135 return S_OK;
136}
137
138STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
139{
140 if (!aAdditionsVersion)
141 return E_POINTER;
142
143 AutoCaller autoCaller (this);
144 CheckComRCReturnRC (autoCaller.rc());
145
146 AutoReaderLock alock (this);
147
148 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
149
150 return S_OK;
151}
152
153STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
154{
155 if (!aSupportsSeamless)
156 return E_POINTER;
157
158 AutoCaller autoCaller (this);
159 CheckComRCReturnRC (autoCaller.rc());
160
161 AutoReaderLock alock (this);
162
163 *aSupportsSeamless = mData.mSupportsSeamless;
164
165 return S_OK;
166}
167
168STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
169{
170 if (!aMemoryBalloonSize)
171 return E_POINTER;
172
173 AutoCaller autoCaller (this);
174 CheckComRCReturnRC (autoCaller.rc());
175
176 AutoReaderLock alock (this);
177
178 *aMemoryBalloonSize = mMemoryBalloonSize;
179
180 return S_OK;
181}
182
183STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
184{
185 AutoCaller autoCaller (this);
186 CheckComRCReturnRC (autoCaller.rc());
187
188 AutoLock alock (this);
189
190 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
191 if (ret == S_OK)
192 {
193 mMemoryBalloonSize = aMemoryBalloonSize;
194 /* forward the information to the VMM device */
195 VMMDev *vmmDev = mParent->getVMMDev();
196 if (vmmDev)
197 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
198 }
199
200 return ret;
201}
202
203STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
204{
205 if (!aUpdateInterval)
206 return E_POINTER;
207
208 AutoCaller autoCaller (this);
209 CheckComRCReturnRC (autoCaller.rc());
210
211 AutoReaderLock alock (this);
212
213 *aUpdateInterval = mStatUpdateInterval;
214
215 return S_OK;
216}
217
218STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
219{
220 AutoCaller autoCaller (this);
221 CheckComRCReturnRC (autoCaller.rc());
222
223 AutoLock alock (this);
224
225 HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
226 if (ret == S_OK)
227 {
228 mStatUpdateInterval = aUpdateInterval;
229 /* forward the information to the VMM device */
230 VMMDev *vmmDev = mParent->getVMMDev();
231 if (vmmDev)
232 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
233 }
234
235 return ret;
236}
237
238STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
239 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
240{
241 if (!aUserName || !aPassword || !aDomain)
242 return E_INVALIDARG;
243
244 AutoCaller autoCaller (this);
245 CheckComRCReturnRC (autoCaller.rc());
246
247 /* forward the information to the VMM device */
248 VMMDev *vmmDev = mParent->getVMMDev();
249 if (vmmDev)
250 {
251 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
252 if (!aAllowInteractiveLogon)
253 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
254
255 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
256 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
257 Utf8Str(aDomain).raw(), u32Flags);
258 return S_OK;
259 }
260
261 return setError (E_FAIL,
262 tr ("VMM device is not available (is the VM running?)"));
263}
264
265STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
266{
267 if (!aStatVal)
268 return E_INVALIDARG;
269
270 if (aCpuId != 0)
271 return E_INVALIDARG;
272
273 switch(aStatistic)
274 {
275 case GuestStatisticType_CPULoad_Idle:
276 case GuestStatisticType_CPULoad_Kernel:
277 case GuestStatisticType_CPULoad_User:
278 case GuestStatisticType_Threads:
279 case GuestStatisticType_Processes:
280 case GuestStatisticType_PhysMemTotal:
281 case GuestStatisticType_PhysMemAvailable:
282 case GuestStatisticType_PageFileSize:
283 *aStatVal = 0;
284 break;
285
286 default:
287 AssertFailed();
288 return E_INVALIDARG;
289 }
290 return S_OK;
291}
292
293STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
294{
295 if (aCpuId != 0)
296 return E_INVALIDARG;
297
298 switch(aStatistic)
299 {
300 case GuestStatisticType_CPULoad_Idle:
301 case GuestStatisticType_CPULoad_Kernel:
302 case GuestStatisticType_CPULoad_User:
303 case GuestStatisticType_Threads:
304 case GuestStatisticType_Processes:
305 case GuestStatisticType_PhysMemTotal:
306 case GuestStatisticType_PhysMemAvailable:
307 case GuestStatisticType_PageFileSize:
308 break;
309
310 default:
311 AssertFailed();
312 return E_INVALIDARG;
313 }
314 return S_OK;
315}
316
317// public methods only for internal purposes
318/////////////////////////////////////////////////////////////////////////////
319
320void Guest::setAdditionsVersion (Bstr aVersion)
321{
322 AssertReturnVoid (!aVersion.isEmpty());
323
324 AutoCaller autoCaller (this);
325 AssertComRCReturnVoid (autoCaller.rc());
326
327 AutoLock alock (this);
328
329 mData.mAdditionsVersion = aVersion;
330 /* this implies that Additions are active */
331 mData.mAdditionsActive = TRUE;
332}
333
334void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
335{
336 AutoCaller autoCaller (this);
337 AssertComRCReturnVoid (autoCaller.rc());
338
339 AutoLock alock (this);
340
341 mData.mSupportsSeamless = aSupportsSeamless;
342}
Note: See TracBrowser for help on using the repository browser.

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