VirtualBox

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

Last change on this file since 4615 was 4608, checked in by vboxsync, 17 years ago

Missing stat

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 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_Handles:
281 case GuestStatisticType_MemoryLoad:
282 case GuestStatisticType_PhysMemTotal:
283 case GuestStatisticType_PhysMemAvailable:
284 case GuestStatisticType_PhysMemBalloon:
285 case GuestStatisticType_MemCommitTotal:
286 case GuestStatisticType_MemKernelTotal:
287 case GuestStatisticType_MemKernelPaged:
288 case GuestStatisticType_MemKernelNonpaged:
289 case GuestStatisticType_MemSystemCache:
290 case GuestStatisticType_PageFileSize:
291 *aStatVal = 0;
292 break;
293
294 default:
295 AssertFailed();
296 return E_INVALIDARG;
297 }
298 return S_OK;
299}
300
301STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
302{
303 if (aCpuId != 0)
304 return E_INVALIDARG;
305
306 switch(aStatistic)
307 {
308 case GuestStatisticType_CPULoad_Idle:
309 case GuestStatisticType_CPULoad_Kernel:
310 case GuestStatisticType_CPULoad_User:
311 case GuestStatisticType_Threads:
312 case GuestStatisticType_Processes:
313 case GuestStatisticType_Handles:
314 case GuestStatisticType_MemoryLoad:
315 case GuestStatisticType_PhysMemTotal:
316 case GuestStatisticType_PhysMemAvailable:
317 case GuestStatisticType_PhysMemBalloon:
318 case GuestStatisticType_MemCommitTotal:
319 case GuestStatisticType_MemKernelTotal:
320 case GuestStatisticType_MemKernelPaged:
321 case GuestStatisticType_MemKernelNonpaged:
322 case GuestStatisticType_MemSystemCache:
323 case GuestStatisticType_PageFileSize:
324 break;
325
326 default:
327 AssertFailed();
328 return E_INVALIDARG;
329 }
330 return S_OK;
331}
332
333// public methods only for internal purposes
334/////////////////////////////////////////////////////////////////////////////
335
336void Guest::setAdditionsVersion (Bstr aVersion)
337{
338 AssertReturnVoid (!aVersion.isEmpty());
339
340 AutoCaller autoCaller (this);
341 AssertComRCReturnVoid (autoCaller.rc());
342
343 AutoLock alock (this);
344
345 mData.mAdditionsVersion = aVersion;
346 /* this implies that Additions are active */
347 mData.mAdditionsActive = TRUE;
348}
349
350void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
351{
352 AutoCaller autoCaller (this);
353 AssertComRCReturnVoid (autoCaller.rc());
354
355 AutoLock alock (this);
356
357 mData.mSupportsSeamless = aSupportsSeamless;
358}
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