VirtualBox

source: vbox/trunk/src/VBox/Main/SystemPropertiesImpl.cpp@ 2705

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

Implemented new 'MonitorCount' VM setting, to be used by VGA device and NT guest driver.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "SystemPropertiesImpl.h"
23#include "VirtualBoxImpl.h"
24#include "MachineImpl.h"
25#include "Logging.h"
26
27// generated header
28#include "SchemaDefs.h"
29
30#include <iprt/path.h>
31#include <iprt/dir.h>
32#include <VBox/param.h>
33#include <VBox/err.h>
34
35// defines
36/////////////////////////////////////////////////////////////////////////////
37
38// constructor / destructor
39/////////////////////////////////////////////////////////////////////////////
40
41HRESULT SystemProperties::FinalConstruct()
42{
43 return S_OK;
44}
45
46void SystemProperties::FinalRelease()
47{
48 if (isReady())
49 uninit ();
50}
51
52// public methods only for internal purposes
53/////////////////////////////////////////////////////////////////////////////
54
55/**
56 * Initializes the system information object.
57 *
58 * @returns COM result indicator
59 */
60HRESULT SystemProperties::init (VirtualBox *aParent)
61{
62 LogFlowMember (("SystemProperties::init()\n"));
63
64 ComAssertRet (aParent, E_FAIL);
65
66 AutoLock alock (this);
67 ComAssertRet (!isReady(), E_UNEXPECTED);
68
69 mParent = aParent;
70
71 setDefaultVDIFolder (NULL);
72 setDefaultMachineFolder (NULL);
73 setRemoteDisplayAuthLibrary (NULL);
74
75 mHWVirtExEnabled = false;
76
77 setReady(true);
78 return S_OK;
79}
80
81/**
82 * Uninitializes the instance and sets the ready flag to FALSE.
83 * Called either from FinalRelease() or by the parent when it gets destroyed.
84 */
85void SystemProperties::uninit()
86{
87 LogFlowMember (("SystemProperties::uninit()\n"));
88
89 AutoLock alock (this);
90 AssertReturn (isReady(), (void) 0);
91
92 setReady (false);
93}
94
95// ISystemProperties properties
96/////////////////////////////////////////////////////////////////////////////
97
98
99STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
100{
101 if (!minRAM)
102 return E_POINTER;
103 AutoLock lock(this);
104 CHECK_READY();
105
106 *minRAM = SchemaDefs::MinGuestRAM;
107
108 return S_OK;
109}
110
111STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
112{
113 if (!maxRAM)
114 return E_POINTER;
115 AutoLock lock(this);
116 CHECK_READY();
117
118 *maxRAM = SchemaDefs::MaxGuestRAM;
119
120 return S_OK;
121}
122
123STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
124{
125 if (!minVRAM)
126 return E_POINTER;
127 AutoLock lock(this);
128 CHECK_READY();
129
130 *minVRAM = SchemaDefs::MinGuestVRAM;
131
132 return S_OK;
133}
134
135STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
136{
137 if (!maxVRAM)
138 return E_POINTER;
139 AutoLock lock(this);
140 CHECK_READY();
141
142 *maxVRAM = SchemaDefs::MaxGuestVRAM;
143
144 return S_OK;
145}
146
147STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
148{
149 if (!maxMonitors)
150 return E_POINTER;
151 AutoLock lock(this);
152 CHECK_READY();
153
154 *maxMonitors = SchemaDefs::MaxGuestMonitors;
155
156 return S_OK;
157}
158
159STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
160{
161 if (!maxVDISize)
162 return E_POINTER;
163 AutoLock lock(this);
164 CHECK_READY();
165
166 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
167 * 48 bit range is in theory trivial, but the crappy compiler makes things
168 * more difficult). This translates to almost 2 TBytes (to be on the safe
169 * side, the reported limit is 1 MiByte less than that, as the total number
170 * of sectors should fit in 32 bits, too), which should bei enough for
171 * the moment. The virtual ATA disks support complete LBA48 (although for
172 * example iSCSI is also currently limited to 32 bit LBA), so the
173 * theoretical maximum disk size is 128 PiByte. The user interface cannot
174 * cope with this in a reasonable way yet. */
175 *maxVDISize = 2048 * 1024 - 1;
176
177 return S_OK;
178}
179
180STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
181{
182 if (!count)
183 return E_POINTER;
184 AutoLock lock (this);
185 CHECK_READY();
186
187 *count = SchemaDefs::NetworkAdapterCount;
188
189 return S_OK;
190}
191
192
193STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
194{
195 if (!aMaxBootPosition)
196 return E_POINTER;
197 AutoLock lock (this);
198 CHECK_READY();
199
200 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
201
202 return S_OK;
203}
204
205STDMETHODIMP SystemProperties::COMGETTER(DefaultVDIFolder) (BSTR *aDefaultVDIFolder)
206{
207 if (!aDefaultVDIFolder)
208 return E_POINTER;
209
210 AutoLock alock (this);
211 CHECK_READY();
212
213 mDefaultVDIFolderFull.cloneTo (aDefaultVDIFolder);
214
215 return S_OK;
216}
217
218STDMETHODIMP SystemProperties::COMSETTER(DefaultVDIFolder) (INPTR BSTR aDefaultVDIFolder)
219{
220 AutoLock alock (this);
221 CHECK_READY();
222
223 HRESULT rc = setDefaultVDIFolder (aDefaultVDIFolder);
224 if (FAILED (rc))
225 return rc;
226
227 alock.unlock();
228 return mParent->saveSettings();
229}
230
231STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
232{
233 if (!aDefaultMachineFolder)
234 return E_POINTER;
235
236 AutoLock alock (this);
237 CHECK_READY();
238
239 mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
240
241 return S_OK;
242}
243
244STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (INPTR BSTR aDefaultMachineFolder)
245{
246 AutoLock alock (this);
247 CHECK_READY();
248
249 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
250 if (FAILED (rc))
251 return rc;
252
253 alock.unlock();
254 return mParent->saveSettings();
255}
256
257STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
258{
259 if (!aRemoteDisplayAuthLibrary)
260 return E_POINTER;
261
262 AutoLock alock (this);
263 CHECK_READY();
264
265 mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
266
267 return S_OK;
268}
269
270STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (INPTR BSTR aRemoteDisplayAuthLibrary)
271{
272 AutoLock alock (this);
273 CHECK_READY();
274
275 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
276 if (FAILED (rc))
277 return rc;
278
279 alock.unlock();
280 return mParent->saveSettings();
281}
282
283STDMETHODIMP SystemProperties::COMGETTER(HWVirtExEnabled) (BOOL *enabled)
284{
285 if (!enabled)
286 return E_POINTER;
287
288 AutoLock alock (this);
289 CHECK_READY();
290
291 *enabled = mHWVirtExEnabled;
292
293 return S_OK;
294}
295
296STDMETHODIMP SystemProperties::COMSETTER(HWVirtExEnabled) (BOOL enabled)
297{
298 AutoLock alock (this);
299 CHECK_READY();
300
301 mHWVirtExEnabled = enabled;
302
303 alock.unlock();
304 return mParent->saveSettings();
305}
306
307// public methods only for internal purposes
308/////////////////////////////////////////////////////////////////////////////
309
310HRESULT SystemProperties::loadSettings (CFGNODE aGlobal)
311{
312 AutoLock lock (this);
313 CHECK_READY();
314
315 ComAssertRet (aGlobal, E_FAIL);
316
317 CFGNODE properties = NULL;
318 CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
319 ComAssertRet (properties, E_FAIL);
320
321 HRESULT rc = E_FAIL;
322
323 do
324 {
325 Bstr bstr;
326
327 CFGLDRQueryBSTR (properties, "defaultVDIFolder",
328 bstr.asOutParam());
329 rc = setDefaultVDIFolder (bstr);
330 if (FAILED (rc))
331 break;
332
333 CFGLDRQueryBSTR (properties, "defaultMachineFolder",
334 bstr.asOutParam());
335 rc = setDefaultMachineFolder (bstr);
336 if (FAILED (rc))
337 break;
338
339 CFGLDRQueryBSTR (properties, "remoteDisplayAuthLibrary",
340 bstr.asOutParam());
341 rc = setRemoteDisplayAuthLibrary (bstr);
342 if (FAILED (rc))
343 break;
344
345 CFGLDRQueryBool (properties, "HWVirtExEnabled", (bool*)&mHWVirtExEnabled);
346
347 }
348 while (0);
349
350 CFGLDRReleaseNode (properties);
351
352 return rc;
353}
354
355HRESULT SystemProperties::saveSettings (CFGNODE aGlobal)
356{
357 AutoLock lock (this);
358 CHECK_READY();
359
360 ComAssertRet (aGlobal, E_FAIL);
361
362 // first, delete the entry
363 CFGNODE properties = NULL;
364 int vrc = CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
365 if (VBOX_SUCCESS (vrc))
366 {
367 vrc = CFGLDRDeleteNode (properties);
368 ComAssertRCRet (vrc, E_FAIL);
369 }
370 // then, recreate it
371 vrc = CFGLDRCreateChildNode (aGlobal, "SystemProperties", &properties);
372 ComAssertRCRet (vrc, E_FAIL);
373
374 if (mDefaultVDIFolder)
375 CFGLDRSetBSTR (properties, "defaultVDIFolder",
376 mDefaultVDIFolder);
377
378 if (mDefaultMachineFolder)
379 CFGLDRSetBSTR (properties, "defaultMachineFolder",
380 mDefaultMachineFolder);
381
382 if (mRemoteDisplayAuthLibrary)
383 CFGLDRSetBSTR (properties, "remoteDisplayAuthLibrary",
384 mRemoteDisplayAuthLibrary);
385
386 CFGLDRSetBool (properties, "HWVirtExEnabled", !!mHWVirtExEnabled);
387
388 return S_OK;
389}
390
391// private methods
392/////////////////////////////////////////////////////////////////////////////
393
394HRESULT SystemProperties::setDefaultVDIFolder (const BSTR aPath)
395{
396 Utf8Str path;
397 if (aPath && *aPath)
398 path = aPath;
399 else
400 path = "VDI";
401
402 // get the full file name
403 char folder [RTPATH_MAX];
404 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
405 if (VBOX_FAILURE (vrc))
406 return setError (E_FAIL,
407 tr ("Cannot set the default VDI folder to '%ls' (%Vrc)"),
408 path.raw(), vrc);
409
410 mDefaultVDIFolder = path;
411 mDefaultVDIFolderFull = folder;
412
413 return S_OK;
414}
415
416HRESULT SystemProperties::setDefaultMachineFolder (const BSTR aPath)
417{
418 Utf8Str path;
419 if (aPath && *aPath)
420 path = aPath;
421 else
422 path = "Machines";
423
424 // get the full file name
425 char folder [RTPATH_MAX];
426 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
427 if (VBOX_FAILURE (vrc))
428 return setError (E_FAIL,
429 tr ("Cannot set the default machines folder to '%ls' (%Vrc)"),
430 path.raw(), vrc);
431
432 mDefaultMachineFolder = path;
433 mDefaultMachineFolderFull = folder;
434
435 return S_OK;
436}
437
438HRESULT SystemProperties::setRemoteDisplayAuthLibrary (const BSTR aPath)
439{
440 Utf8Str path;
441 if (aPath && *aPath)
442 path = aPath;
443 else
444 path = "VRDPAuth";
445
446 mRemoteDisplayAuthLibrary = path;
447
448 return S_OK;
449}
450
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