VirtualBox

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

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

Backed out 24093

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