VirtualBox

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

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

Completed statistic query

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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 for (int i=0;i<GuestStatisticType_MaxVal;i++)
83 mCurrentGuestStat[i] = GUEST_STAT_INVALID;
84
85 return S_OK;
86}
87
88/**
89 * Uninitializes the instance and sets the ready flag to FALSE.
90 * Called either from FinalRelease() or by the parent when it gets destroyed.
91 */
92void Guest::uninit()
93{
94 LogFlowThisFunc (("\n"));
95
96 /* Enclose the state transition Ready->InUninit->NotReady */
97 AutoUninitSpan autoUninitSpan (this);
98 if (autoUninitSpan.uninitDone())
99 return;
100
101 unconst (mParent).setNull();
102}
103
104// IGuest properties
105/////////////////////////////////////////////////////////////////////////////
106
107STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
108{
109 if (!aOSTypeId)
110 return E_POINTER;
111
112 AutoCaller autoCaller (this);
113 CheckComRCReturnRC (autoCaller.rc());
114
115 AutoReaderLock alock (this);
116
117 // redirect the call to IMachine if no additions are installed
118 if (mData.mAdditionsVersion.isNull())
119 return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
120
121 mData.mOSTypeId.cloneTo (aOSTypeId);
122
123 return S_OK;
124}
125
126STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
127{
128 if (!aAdditionsActive)
129 return E_POINTER;
130
131 AutoCaller autoCaller (this);
132 CheckComRCReturnRC (autoCaller.rc());
133
134 AutoReaderLock alock (this);
135
136 *aAdditionsActive = mData.mAdditionsActive;
137
138 return S_OK;
139}
140
141STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
142{
143 if (!aAdditionsVersion)
144 return E_POINTER;
145
146 AutoCaller autoCaller (this);
147 CheckComRCReturnRC (autoCaller.rc());
148
149 AutoReaderLock alock (this);
150
151 mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
152
153 return S_OK;
154}
155
156STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
157{
158 if (!aSupportsSeamless)
159 return E_POINTER;
160
161 AutoCaller autoCaller (this);
162 CheckComRCReturnRC (autoCaller.rc());
163
164 AutoReaderLock alock (this);
165
166 *aSupportsSeamless = mData.mSupportsSeamless;
167
168 return S_OK;
169}
170
171STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
172{
173 if (!aMemoryBalloonSize)
174 return E_POINTER;
175
176 AutoCaller autoCaller (this);
177 CheckComRCReturnRC (autoCaller.rc());
178
179 AutoReaderLock alock (this);
180
181 *aMemoryBalloonSize = mMemoryBalloonSize;
182
183 return S_OK;
184}
185
186STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
187{
188 AutoCaller autoCaller (this);
189 CheckComRCReturnRC (autoCaller.rc());
190
191 AutoLock alock (this);
192
193 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
194 if (ret == S_OK)
195 {
196 mMemoryBalloonSize = aMemoryBalloonSize;
197 /* forward the information to the VMM device */
198 VMMDev *vmmDev = mParent->getVMMDev();
199 if (vmmDev)
200 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
201 }
202
203 return ret;
204}
205
206STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval) (ULONG *aUpdateInterval)
207{
208 if (!aUpdateInterval)
209 return E_POINTER;
210
211 AutoCaller autoCaller (this);
212 CheckComRCReturnRC (autoCaller.rc());
213
214 AutoReaderLock alock (this);
215
216 *aUpdateInterval = mStatUpdateInterval;
217
218 return S_OK;
219}
220
221STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval) (ULONG aUpdateInterval)
222{
223 AutoCaller autoCaller (this);
224 CheckComRCReturnRC (autoCaller.rc());
225
226 AutoLock alock (this);
227
228 HRESULT ret = mParent->machine()->COMSETTER(StatisticsUpdateInterval)(aUpdateInterval);
229 if (ret == S_OK)
230 {
231 mStatUpdateInterval = aUpdateInterval;
232 /* forward the information to the VMM device */
233 VMMDev *vmmDev = mParent->getVMMDev();
234 if (vmmDev)
235 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
236 }
237
238 return ret;
239}
240
241STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
242 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
243{
244 if (!aUserName || !aPassword || !aDomain)
245 return E_INVALIDARG;
246
247 AutoCaller autoCaller (this);
248 CheckComRCReturnRC (autoCaller.rc());
249
250 /* forward the information to the VMM device */
251 VMMDev *vmmDev = mParent->getVMMDev();
252 if (vmmDev)
253 {
254 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
255 if (!aAllowInteractiveLogon)
256 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
257
258 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
259 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
260 Utf8Str(aDomain).raw(), u32Flags);
261 return S_OK;
262 }
263
264 return setError (E_FAIL,
265 tr ("VMM device is not available (is the VM running?)"));
266}
267
268STDMETHODIMP Guest::GetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG *aStatVal)
269{
270 if (!aStatVal)
271 return E_INVALIDARG;
272
273 if (aCpuId != 0)
274 return E_INVALIDARG;
275
276 if (aStatistic >= GuestStatisticType_MaxVal)
277 return E_INVALIDARG;
278
279 /* not available or not yet reported? */
280 if (mCurrentGuestStat[aStatistic] == GUEST_STAT_INVALID)
281 return E_INVALIDARG;
282
283 *aStatVal = mCurrentGuestStat[aStatistic];
284 return S_OK;
285}
286
287STDMETHODIMP Guest::SetStatistic(ULONG aCpuId, GuestStatisticType_T aStatistic, ULONG aStatVal)
288{
289 if (aCpuId != 0)
290 return E_INVALIDARG;
291
292 if (aStatistic >= GuestStatisticType_MaxVal)
293 return E_INVALIDARG;
294
295 /* internal method assumes that the caller known what he's doing (no boundary checks) */
296 mCurrentGuestStat[aStatistic] = aStatVal;
297 return S_OK;
298}
299
300// public methods only for internal purposes
301/////////////////////////////////////////////////////////////////////////////
302
303void Guest::setAdditionsVersion (Bstr aVersion)
304{
305 AssertReturnVoid (!aVersion.isEmpty());
306
307 AutoCaller autoCaller (this);
308 AssertComRCReturnVoid (autoCaller.rc());
309
310 AutoLock alock (this);
311
312 mData.mAdditionsVersion = aVersion;
313 /* this implies that Additions are active */
314 mData.mAdditionsActive = TRUE;
315}
316
317void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
318{
319 AutoCaller autoCaller (this);
320 AssertComRCReturnVoid (autoCaller.rc());
321
322 AutoLock alock (this);
323
324 mData.mSupportsSeamless = aSupportsSeamless;
325}
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