VirtualBox

source: vbox/trunk/src/VBox/Main/ConsoleImpl2.cpp@ 5332

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

Make PXE booting in NAT mode work without much hassle.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 68.9 KB
Line 
1/** $Id: ConsoleImpl2.cpp 5332 2007-10-16 17:00:04Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler
6 * finds problematic to optimize so we can disable optimizations
7 * and later, perhaps, find a real solution for it.
8 */
9
10/*
11 * Copyright (C) 2006-2007 innotek GmbH
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License as published by the Free Software Foundation,
17 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
18 * distribution. VirtualBox OSE is distributed in the hope that it will
19 * be useful, but WITHOUT ANY WARRANTY of any kind.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include "ConsoleImpl.h"
26#include "DisplayImpl.h"
27#include "VMMDev.h"
28
29// generated header
30#include "SchemaDefs.h"
31
32#include "Logging.h"
33
34#include <iprt/string.h>
35#include <iprt/path.h>
36#include <iprt/dir.h>
37#include <iprt/param.h>
38
39#include <VBox/vmapi.h>
40#include <VBox/err.h>
41#include <VBox/version.h>
42#include <VBox/HostServices/VBoxClipboardSvc.h>
43
44
45/*
46 * VC++ 8 / amd64 has some serious trouble with this function.
47 * As a temporary measure, we'll drop global optimizations.
48 */
49#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
50# pragma optimize("g", off)
51#endif
52
53/**
54 * Construct the VM configuration tree (CFGM).
55 *
56 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
57 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
58 * is done here.
59 *
60 * @param pVM VM handle.
61 * @param pvConsole Pointer to the VMPowerUpTask object.
62 * @return VBox status code.
63 *
64 * @note Locks the Console object for writing.
65 */
66DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
67{
68 LogFlowFuncEnter();
69
70#if defined(RT_OS_WINDOWS)
71 {
72 /* initialize COM */
73 HRESULT hrc = CoInitializeEx(NULL,
74 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
75 COINIT_SPEED_OVER_MEMORY);
76 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
77 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
78 }
79#endif
80
81 AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
82 ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
83
84 AutoCaller autoCaller (pConsole);
85 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
86
87 /* lock the console because we widely use internal fields and methods */
88 AutoLock alock (pConsole);
89
90 ComPtr <IMachine> pMachine = pConsole->machine();
91
92 int rc;
93 HRESULT hrc;
94 char *psz = NULL;
95 BSTR str = NULL;
96 unsigned i;
97
98#define STR_CONV() do { rc = RTStrUcs2ToUtf8(&psz, str); RC_CHECK(); } while (0)
99#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
100#define RC_CHECK() do { if (VBOX_FAILURE(rc)) { AssertMsgFailed(("rc=%Vrc\n", rc)); STR_FREE(); return rc; } } while (0)
101#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
102
103 /*
104 * Get necessary objects and frequently used parameters.
105 */
106 ComPtr<IVirtualBox> virtualBox;
107 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
108
109 ComPtr<IHost> host;
110 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
111
112 ComPtr <ISystemProperties> systemProperties;
113 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
114
115 ComPtr<IBIOSSettings> biosSettings;
116 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
117
118 Guid uuid;
119 hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
120 PCRTUUID pUuid = uuid.raw();
121
122 ULONG cRamMBs;
123 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
124
125
126 /*
127 * Get root node first.
128 * This is the only node in the tree.
129 */
130 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
131 Assert(pRoot);
132
133 /*
134 * Set the root level values.
135 */
136 hrc = pMachine->COMGETTER(Name)(&str); H();
137 STR_CONV();
138 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
139 STR_FREE();
140 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
141 rc = CFGMR3InsertInteger(pRoot, "RamSize", cRamMBs * _1M); RC_CHECK();
142 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
143 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
144 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
145 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
146 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
147 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
148
149 /* hardware virtualization extensions */
150 TriStateBool_T hwVirtExEnabled;
151 BOOL fHWVirtExEnabled;
152 hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
153 if (hwVirtExEnabled == TriStateBool_Default)
154 {
155 /* check the default value */
156 hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
157 }
158 else
159 fHWVirtExEnabled = (hwVirtExEnabled == TriStateBool_True);
160#ifndef RT_OS_DARWIN /** @todo Implement HWVirtExt on darwin. See #1865. */
161 if (fHWVirtExEnabled)
162 {
163 PCFGMNODE pHWVirtExt;
164 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
165 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
166 }
167#endif
168
169 BOOL fIOAPIC;
170 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
171
172 BOOL fPXEDebug;
173 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
174
175 /*
176 * PDM config.
177 * Load drivers in VBoxC.[so|dll]
178 */
179 PCFGMNODE pPDM;
180 PCFGMNODE pDrivers;
181 PCFGMNODE pMod;
182 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
183 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
184 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
185#ifdef VBOX_WITH_XPCOM
186 // VBoxC is located in the components subdirectory
187 char szPathVBoxC[RTPATH_MAX];
188 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
189 strcat(szPathVBoxC, "/components/VBoxC");
190 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
191#else
192 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
193#endif
194
195 /*
196 * Devices
197 */
198 PCFGMNODE pDevices = NULL; /* /Devices */
199 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
200 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
201 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
202 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
203 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
204 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
205
206 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
207
208 /*
209 * PC Arch.
210 */
211 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
212 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
213 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
214 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
215
216 /*
217 * PC Bios.
218 */
219 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
220 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
221 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
222 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
223 rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
224 rc = CFGMR3InsertString(pCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
225 rc = CFGMR3InsertString(pCfg, "FloppyDevice", "i82078"); RC_CHECK();
226 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
227 rc = CFGMR3InsertInteger(pCfg, "PXEDebug", fPXEDebug); RC_CHECK();
228 rc = CFGMR3InsertBytes(pCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
229
230 DeviceType_T bootDevice;
231 if (SchemaDefs::MaxBootPosition > 9)
232 {
233 AssertMsgFailed (("Too many boot devices %d\n",
234 SchemaDefs::MaxBootPosition));
235 return VERR_INVALID_PARAMETER;
236 }
237
238 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
239 {
240 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
241
242 char szParamName[] = "BootDeviceX";
243 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
244
245 const char *pszBootDevice;
246 switch (bootDevice)
247 {
248 case DeviceType_NoDevice:
249 pszBootDevice = "NONE";
250 break;
251 case DeviceType_HardDiskDevice:
252 pszBootDevice = "IDE";
253 break;
254 case DeviceType_DVDDevice:
255 pszBootDevice = "DVD";
256 break;
257 case DeviceType_FloppyDevice:
258 pszBootDevice = "FLOPPY";
259 break;
260 case DeviceType_NetworkDevice:
261 pszBootDevice = "LAN";
262 break;
263 default:
264 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
265 return VERR_INVALID_PARAMETER;
266 }
267 rc = CFGMR3InsertString(pCfg, szParamName, pszBootDevice); RC_CHECK();
268 }
269
270 /*
271 * BIOS logo
272 */
273 BOOL fFadeIn;
274 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
275 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
276 BOOL fFadeOut;
277 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
278 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
279 ULONG logoDisplayTime;
280 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
281 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
282 Bstr logoImagePath;
283 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
284 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
285
286 /*
287 * Boot menu
288 */
289 BIOSBootMenuMode_T bootMenuMode;
290 int value;
291 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
292 switch (bootMenuMode)
293 {
294 case BIOSBootMenuMode_Disabled:
295 value = 0;
296 break;
297 case BIOSBootMenuMode_MenuOnly:
298 value = 1;
299 break;
300 default:
301 value = 2;
302 }
303 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
304
305 /*
306 * The time offset
307 */
308 LONG64 timeOffset;
309 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
310 PCFGMNODE pTMNode;
311 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
312 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
313
314 /*
315 * ACPI
316 */
317 BOOL fACPI;
318 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
319 if (fACPI)
320 {
321 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
322 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
323 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
324 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
325 rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
326 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
327 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
328 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
329
330 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
331 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
332 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
333 }
334
335 /*
336 * DMA
337 */
338 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
339 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
340 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
341
342 /*
343 * PCI bus.
344 */
345 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
346 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
347 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
348 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
349 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
350
351 /*
352 * PS/2 keyboard & mouse.
353 */
354 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
355 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
356 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
357 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
358
359 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
360 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
361 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
362 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
363
364 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
365 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
366 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
367 Keyboard *pKeyboard = pConsole->mKeyboard;
368 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
369
370 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
371 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
372 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
373 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
374
375 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
376 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
377 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
378 Mouse *pMouse = pConsole->mMouse;
379 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
380
381 /*
382 * i82078 Floppy drive controller
383 */
384 ComPtr<IFloppyDrive> floppyDrive;
385 hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
386 BOOL fFloppyEnabled;
387 hrc = floppyDrive->COMGETTER(Enabled)(&fFloppyEnabled); H();
388 if (fFloppyEnabled)
389 {
390 rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
391 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
392 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
393 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
394 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
395 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
396 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
397 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
398
399 /* Attach the status driver */
400 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
401 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
402 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
403 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
404 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
405 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
406
407 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
408
409 ComPtr<IFloppyImage> floppyImage;
410 hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
411 if (floppyImage)
412 {
413 pConsole->meFloppyState = DriveState_ImageMounted;
414 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
415 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
416 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
417 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
418
419 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
420 rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
421 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
422 hrc = floppyImage->COMGETTER(FilePath)(&str); H();
423 STR_CONV();
424 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
425 STR_FREE();
426 }
427 else
428 {
429 ComPtr<IHostFloppyDrive> hostFloppyDrive;
430 hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
431 if (hostFloppyDrive)
432 {
433 pConsole->meFloppyState = DriveState_HostDriveCaptured;
434 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
435 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
436 hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
437 STR_CONV();
438 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
439 STR_FREE();
440 }
441 else
442 {
443 pConsole->meFloppyState = DriveState_NotMounted;
444 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
445 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
446 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
447 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
448 }
449 }
450 }
451
452 /*
453 * i8254 Programmable Interval Timer And Dummy Speaker
454 */
455 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
456 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
457 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
458#ifdef DEBUG
459 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
460#endif
461
462 /*
463 * i8259 Programmable Interrupt Controller.
464 */
465 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
466 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
467 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
468 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
469
470 /*
471 * Advanced Programmable Interrupt Controller.
472 */
473 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
474 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
475 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
476 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
477 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
478
479 if (fIOAPIC)
480 {
481 /*
482 * I/O Advanced Programmable Interrupt Controller.
483 */
484 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
485 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
486 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
487 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
488 }
489
490 /*
491 * RTC MC146818.
492 */
493 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
494 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
495 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
496
497 /*
498 * VGA.
499 */
500 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
501 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
502 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
503 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
504 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
505 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
506 hrc = pMachine->COMGETTER(VRAMSize)(&cRamMBs); H();
507 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cRamMBs * _1M); RC_CHECK();
508
509 /* Custom VESA mode list */
510 unsigned cModes = 0;
511 for (unsigned iMode = 1; iMode <= 16; iMode++)
512 {
513 char szExtraDataKey[sizeof("CustomVideoModeXX")];
514 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
515 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
516 if (!str || !*str)
517 break;
518 STR_CONV();
519 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
520 STR_FREE();
521 cModes++;
522 }
523 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
524
525 /* VESA height reduction */
526 ULONG ulHeightReduction;
527 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
528 if (pFramebuffer)
529 {
530 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
531 }
532 else
533 {
534 /* If framebuffer is not available, there is no height reduction. */
535 ulHeightReduction = 0;
536 }
537 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
538
539 /* Attach the display. */
540 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
541 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
542 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
543 Display *pDisplay = pConsole->mDisplay;
544 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
545
546 /*
547 * IDE (update this when the main interface changes)
548 */
549 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
550 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
551 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
552 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
553 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 1); RC_CHECK();
554 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
555
556 /* Attach the status driver */
557 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
558 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
559 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
560 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
561 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
562 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
563
564 /* Attach the harddisks */
565 ComPtr<IHardDiskAttachmentCollection> hdaColl;
566 hrc = pMachine->COMGETTER(HardDiskAttachments)(hdaColl.asOutParam()); H();
567 ComPtr<IHardDiskAttachmentEnumerator> hdaEnum;
568 hrc = hdaColl->Enumerate(hdaEnum.asOutParam()); H();
569
570 BOOL fMore = FALSE;
571 while ( SUCCEEDED(hrc = hdaEnum->HasMore(&fMore))
572 && fMore)
573 {
574 ComPtr<IHardDiskAttachment> hda;
575 hrc = hdaEnum->GetNext(hda.asOutParam()); H();
576 ComPtr<IHardDisk> hardDisk;
577 hrc = hda->COMGETTER(HardDisk)(hardDisk.asOutParam()); H();
578 DiskControllerType_T enmCtl;
579 hrc = hda->COMGETTER(Controller)(&enmCtl); H();
580 LONG lDev;
581 hrc = hda->COMGETTER(DeviceNumber)(&lDev); H();
582
583 switch (enmCtl)
584 {
585 case DiskControllerType_IDE0Controller:
586 i = 0;
587 break;
588 case DiskControllerType_IDE1Controller:
589 i = 2;
590 break;
591 default:
592 AssertMsgFailed(("invalid disk controller type: %d\n", enmCtl));
593 return VERR_GENERAL_FAILURE;
594 }
595
596 if (lDev < 0 || lDev >= 2)
597 {
598 AssertMsgFailed(("invalid controller device number: %d\n", lDev));
599 return VERR_GENERAL_FAILURE;
600 }
601
602 i = i + lDev;
603
604 char szLUN[16];
605 RTStrPrintf(szLUN, sizeof(szLUN), "LUN#%d", i);
606 rc = CFGMR3InsertNode(pInst, szLUN, &pLunL0); RC_CHECK();
607 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
608 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
609 rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
610 rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
611
612 HardDiskStorageType_T hddType;
613 hardDisk->COMGETTER(StorageType)(&hddType);
614 if (hddType == HardDiskStorageType_VirtualDiskImage)
615 {
616 ComPtr<IVirtualDiskImage> vdiDisk = hardDisk;
617 AssertBreak (!vdiDisk.isNull(), hrc = E_FAIL);
618
619 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
620 rc = CFGMR3InsertString(pLunL1, "Driver", "VBoxHDD"); RC_CHECK();
621 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
622 hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
623 STR_CONV();
624 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
625 STR_FREE();
626
627 /* Create an inversed tree of parents. */
628 ComPtr<IHardDisk> parentHardDisk = hardDisk;
629 for (PCFGMNODE pParent = pCfg;;)
630 {
631 ComPtr<IHardDisk> curHardDisk;
632 hrc = parentHardDisk->COMGETTER(Parent)(curHardDisk.asOutParam()); H();
633 if (!curHardDisk)
634 break;
635
636 vdiDisk = curHardDisk;
637 AssertBreak (!vdiDisk.isNull(), hrc = E_FAIL);
638
639 PCFGMNODE pCur;
640 rc = CFGMR3InsertNode(pParent, "Parent", &pCur); RC_CHECK();
641 hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
642 STR_CONV();
643 rc = CFGMR3InsertString(pCur, "Path", psz); RC_CHECK();
644 STR_FREE();
645 rc = CFGMR3InsertInteger(pCur, "ReadOnly", 1); RC_CHECK();
646
647 /* next */
648 pParent = pCur;
649 parentHardDisk = curHardDisk;
650 }
651 }
652 else if (hddType == HardDiskStorageType_ISCSIHardDisk)
653 {
654 ComPtr<IISCSIHardDisk> iSCSIDisk = hardDisk;
655 AssertBreak (!iSCSIDisk.isNull(), hrc = E_FAIL);
656
657 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
658 rc = CFGMR3InsertString(pLunL1, "Driver", "iSCSI"); RC_CHECK();
659 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
660
661 /* Set up the iSCSI initiator driver configuration. */
662 hrc = iSCSIDisk->COMGETTER(Target)(&str); H();
663 STR_CONV();
664 rc = CFGMR3InsertString(pCfg, "TargetName", psz); RC_CHECK();
665 STR_FREE();
666
667 // @todo currently there is no Initiator name config.
668 rc = CFGMR3InsertString(pCfg, "InitiatorName", "iqn.2006-02.de.innotek.initiator"); RC_CHECK();
669
670 ULONG64 lun;
671 hrc = iSCSIDisk->COMGETTER(Lun)(&lun); H();
672 rc = CFGMR3InsertInteger(pCfg, "LUN", lun); RC_CHECK();
673
674 hrc = iSCSIDisk->COMGETTER(Server)(&str); H();
675 STR_CONV();
676 USHORT port;
677 hrc = iSCSIDisk->COMGETTER(Port)(&port); H();
678 if (port != 0)
679 {
680 char *pszTN;
681 RTStrAPrintf(&pszTN, "%s:%u", psz, port);
682 rc = CFGMR3InsertString(pCfg, "TargetAddress", pszTN); RC_CHECK();
683 RTStrFree(pszTN);
684 }
685 else
686 {
687 rc = CFGMR3InsertString(pCfg, "TargetAddress", psz); RC_CHECK();
688 }
689 STR_FREE();
690
691 hrc = iSCSIDisk->COMGETTER(UserName)(&str); H();
692 if (str)
693 {
694 STR_CONV();
695 rc = CFGMR3InsertString(pCfg, "InitiatorUsername", psz); RC_CHECK();
696 STR_FREE();
697 }
698
699 hrc = iSCSIDisk->COMGETTER(Password)(&str); H();
700 if (str)
701 {
702 STR_CONV();
703 rc = CFGMR3InsertString(pCfg, "InitiatorSecret", psz); RC_CHECK();
704 STR_FREE();
705 }
706
707 // @todo currently there is no target username config.
708 //rc = CFGMR3InsertString(pCfg, "TargetUsername", ""); RC_CHECK();
709
710 // @todo currently there is no target password config.
711 //rc = CFGMR3InsertString(pCfg, "TargetSecret", ""); RC_CHECK();
712
713 /* The iSCSI initiator needs an attached iSCSI transport driver. */
714 rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
715 rc = CFGMR3InsertString(pLunL2, "Driver", "iSCSITCP"); RC_CHECK();
716 /* Currently the transport driver has no config options. */
717 }
718 else if (hddType == HardDiskStorageType_VMDKImage)
719 {
720 ComPtr<IVMDKImage> vmdkDisk = hardDisk;
721 AssertBreak (!vmdkDisk.isNull(), hrc = E_FAIL);
722
723 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
724#if 1 /* Enable new VD container code (and new VMDK), as the bugs are fixed. */
725 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
726#else
727 rc = CFGMR3InsertString(pLunL1, "Driver", "VmdkHDD"); RC_CHECK();
728#endif
729 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
730 hrc = vmdkDisk->COMGETTER(FilePath)(&str); H();
731 STR_CONV();
732 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
733 STR_FREE();
734 }
735 else if (hddType == HardDiskStorageType_CustomHardDisk)
736 {
737 ComPtr<ICustomHardDisk> customHardDisk = hardDisk;
738 AssertBreak (!customHardDisk.isNull(), hrc = E_FAIL);
739
740 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
741 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
742 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
743 hrc = customHardDisk->COMGETTER(Location)(&str); H();
744 STR_CONV();
745 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
746 STR_FREE();
747 hrc = customHardDisk->COMGETTER(Format)(&str); H();
748 STR_CONV();
749 rc = CFGMR3InsertString(pCfg, "Format", psz); RC_CHECK();
750 STR_FREE();
751 }
752 else
753 AssertFailed();
754 }
755 H();
756
757 ComPtr<IDVDDrive> dvdDrive;
758 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
759 if (dvdDrive)
760 {
761 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
762 rc = CFGMR3InsertNode(pInst, "LUN#2", &pLunL0); RC_CHECK();
763 ComPtr<IHostDVDDrive> hostDvdDrive;
764 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
765 if (hostDvdDrive)
766 {
767 pConsole->meDVDState = DriveState_HostDriveCaptured;
768 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
769 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
770 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
771 STR_CONV();
772 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
773 STR_FREE();
774 BOOL fPassthrough;
775 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
776 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
777 }
778 else
779 {
780 pConsole->meDVDState = DriveState_NotMounted;
781 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
782 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
783 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
784 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
785
786 ComPtr<IDVDImage> dvdImage;
787 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
788 if (dvdImage)
789 {
790 pConsole->meDVDState = DriveState_ImageMounted;
791 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
792 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
793 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
794 hrc = dvdImage->COMGETTER(FilePath)(&str); H();
795 STR_CONV();
796 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
797 STR_FREE();
798 }
799 }
800 }
801
802 /*
803 * Network adapters
804 */
805 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDev); RC_CHECK();
806 //rc = CFGMR3InsertNode(pDevices, "ne2000", &pDev); RC_CHECK();
807 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
808 {
809 ComPtr<INetworkAdapter> networkAdapter;
810 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
811 BOOL fEnabled = FALSE;
812 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
813 if (!fEnabled)
814 continue;
815
816 char szInstance[4]; Assert(ulInstance <= 999);
817 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
818 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
819 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
820 /* the first network card gets the PCI ID 3, the followings starting from 8 */
821 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", !ulInstance ? 3 : ulInstance - 1 + 8); RC_CHECK();
822 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
823 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
824
825 /*
826 * The virtual hardware type.
827 */
828 NetworkAdapterType_T adapterType;
829 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
830 switch (adapterType)
831 {
832 case NetworkAdapterType_NetworkAdapterAm79C970A:
833 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
834 break;
835 case NetworkAdapterType_NetworkAdapterAm79C973:
836 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
837 break;
838 default:
839 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
840 adapterType, ulInstance));
841 return VERR_GENERAL_FAILURE;
842 }
843
844 /*
845 * Get the MAC address and convert it to binary representation
846 */
847 Bstr macAddr;
848 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
849 Assert(macAddr);
850 Utf8Str macAddrUtf8 = macAddr;
851 char *macStr = (char*)macAddrUtf8.raw();
852 Assert(strlen(macStr) == 12);
853 PDMMAC Mac;
854 memset(&Mac, 0, sizeof(Mac));
855 char *pMac = (char*)&Mac;
856 for (uint32_t i = 0; i < 6; i++)
857 {
858 char c1 = *macStr++ - '0';
859 if (c1 > 9)
860 c1 -= 7;
861 char c2 = *macStr++ - '0';
862 if (c2 > 9)
863 c2 -= 7;
864 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
865 }
866 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
867
868 /*
869 * Check if the cable is supposed to be unplugged
870 */
871 BOOL fCableConnected;
872 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
873 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
874
875 /*
876 * Line speed to report from custom drivers
877 */
878 ULONG ulLineSpeed;
879 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
880 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
881
882 /*
883 * Attach the status driver.
884 */
885 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
886 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
887 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
888 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
889
890 /*
891 * Enable the packet sniffer if requested.
892 */
893 BOOL fSniffer;
894 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
895 if (fSniffer)
896 {
897 /* insert the sniffer filter driver. */
898 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
899 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
900 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
901 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
902 if (str) /* check convention for indicating default file. */
903 {
904 STR_CONV();
905 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
906 STR_FREE();
907 }
908 }
909
910 NetworkAttachmentType_T networkAttachment;
911 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
912 switch (networkAttachment)
913 {
914 case NetworkAttachmentType_NoNetworkAttachment:
915 break;
916
917 case NetworkAttachmentType_NATNetworkAttachment:
918 {
919 if (fSniffer)
920 {
921 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
922 }
923 else
924 {
925 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
926 }
927 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
928 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
929 /* (Port forwarding goes here.) */
930
931 /* Configure TFTP prefix and boot filename. */
932 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
933 STR_CONV();
934 if (psz && *psz)
935 {
936 char *pszTFTPPrefix = NULL;
937 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
938 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
939 RTStrFree(pszTFTPPrefix);
940 }
941 STR_FREE();
942 hrc = pMachine->COMGETTER(Name)(&str); H();
943 STR_CONV();
944 char *pszBootFile = NULL;
945 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
946 STR_FREE();
947 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
948 RTStrFree(pszBootFile);
949 break;
950 }
951
952 case NetworkAttachmentType_HostInterfaceNetworkAttachment:
953 {
954 /*
955 * Perform the attachment if required (don't return on error!)
956 */
957 hrc = pConsole->attachToHostInterface(networkAdapter);
958 if (SUCCEEDED(hrc))
959 {
960#ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
961 Assert (pConsole->maTapFD[ulInstance] >= 0);
962 if (pConsole->maTapFD[ulInstance] >= 0)
963 {
964 if (fSniffer)
965 {
966 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
967 }
968 else
969 {
970 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
971 }
972 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
973 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
974# if defined(RT_OS_SOLARIS)
975 /* Device name/number is required for Solaris as we need it for TAP PPA. */
976 Bstr tapDeviceName;
977 networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam());
978 if (!tapDeviceName.isEmpty())
979 rc = CFGMR3InsertString(pCfg, "Device", Utf8Str(tapDeviceName)); RC_CHECK();
980
981 /* TAP setup application/script */
982 Bstr tapSetupApp;
983 networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApp.asOutParam());
984 if (!tapSetupApp.isEmpty())
985 rc = CFGMR3InsertString(pCfg, "TAPSetupApplication", Utf8Str(tapSetupApp)); RC_CHECK();
986
987 /* TAP terminate application/script */
988 Bstr tapTerminateApp;
989 networkAdapter->COMGETTER(TAPTerminateApplication)(tapTerminateApp.asOutParam());
990 if (!tapTerminateApp.isEmpty())
991 rc = CFGMR3InsertString(pCfg, "TAPTerminateApplication", Utf8Str(tapTerminateApp)); RC_CHECK();
992
993 /* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
994
995# else
996 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
997# endif
998 }
999#elif defined(RT_OS_WINDOWS)
1000 if (fSniffer)
1001 {
1002 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1003 }
1004 else
1005 {
1006 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1007 }
1008 Bstr hostInterfaceName;
1009 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1010 ComPtr<IHostNetworkInterfaceCollection> coll;
1011 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1012 ComPtr<IHostNetworkInterface> hostInterface;
1013 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1014 if (!SUCCEEDED(rc))
1015 {
1016 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1017 hrc = networkAdapter->Detach(); H();
1018 }
1019 else
1020 {
1021 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1022 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1023 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1024 Guid hostIFGuid;
1025 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1026 char szDriverGUID[256] = {0};
1027 /* add curly brackets */
1028 szDriverGUID[0] = '{';
1029 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1030 strcat(szDriverGUID, "}");
1031 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1032 }
1033#else
1034# error "Port me"
1035#endif
1036 }
1037 else
1038 {
1039 switch (hrc)
1040 {
1041#ifdef RT_OS_LINUX
1042 case VERR_ACCESS_DENIED:
1043 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1044 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1045 "permissions of that node. Either do 'chmod 0666 /dev/net/tun' or "
1046 "change the group of that node and get member of that group. Make "
1047 "sure that these changes are permanently in particular if you are "
1048 "using udev"));
1049#endif /* RT_OS_LINUX */
1050 default:
1051 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1052 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1053 "Failed to initialize Host Interface Networking"));
1054 }
1055 }
1056 break;
1057 }
1058
1059 case NetworkAttachmentType_InternalNetworkAttachment:
1060 {
1061 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1062 STR_CONV();
1063 if (psz && *psz)
1064 {
1065 if (fSniffer)
1066 {
1067 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1068 }
1069 else
1070 {
1071 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1072 }
1073 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1074 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1075 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1076 }
1077 STR_FREE();
1078 break;
1079 }
1080
1081 default:
1082 AssertMsgFailed(("should not get here!\n"));
1083 break;
1084 }
1085 }
1086
1087 /*
1088 * Serial (UART) Ports
1089 */
1090 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1091 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1092 {
1093 ComPtr<ISerialPort> serialPort;
1094 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1095 BOOL fEnabled = FALSE;
1096 if (serialPort)
1097 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1098 if (!fEnabled)
1099 continue;
1100
1101 char szInstance[4]; Assert(ulInstance <= 999);
1102 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1103
1104 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1105 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1106
1107 ULONG ulIRQ, ulIOBase;
1108 PortMode_T HostMode;
1109 Bstr path;
1110 BOOL fServer;
1111 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1112 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1113 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1114 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1115 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1116 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1117 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1118 if (HostMode != PortMode_DisconnectedPort)
1119 {
1120 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1121 if (HostMode == PortMode_HostPipePort)
1122 {
1123 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1124 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1125 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1126 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1127 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1128 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1129 }
1130 else if (HostMode == PortMode_HostDevicePort)
1131 {
1132 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1133 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1134 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1135 }
1136 }
1137 }
1138
1139 /*
1140 * Parallel (LPT) Ports
1141 */
1142 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1143 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1144 {
1145 ComPtr<IParallelPort> parallelPort;
1146 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1147 BOOL fEnabled = FALSE;
1148 if (parallelPort)
1149 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1150 if (!fEnabled)
1151 continue;
1152
1153 char szInstance[4]; Assert(ulInstance <= 999);
1154 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1155
1156 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1157 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1158
1159 ULONG ulIRQ, ulIOBase;
1160 Bstr DevicePath;
1161 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1162 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1163 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1164 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1165 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1166 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1167 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1168 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1169 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1170 }
1171
1172 /*
1173 * VMM Device
1174 */
1175 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1176 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1177 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1178 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1179 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1180 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1181
1182 /* the VMM device's Main driver */
1183 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1184 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1185 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1186 VMMDev *pVMMDev = pConsole->mVMMDev;
1187 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1188
1189 /*
1190 * Attach the status driver.
1191 */
1192 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1193 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1194 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1195 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1196 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1197 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1198
1199 /*
1200 * Audio Sniffer Device
1201 */
1202 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1203 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1204 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1205
1206 /* the Audio Sniffer device's Main driver */
1207 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1208 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1209 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1210 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1211 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1212
1213 /*
1214 * AC'97 ICH audio
1215 */
1216 ComPtr<IAudioAdapter> audioAdapter;
1217 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1218 BOOL enabled = FALSE;
1219 if (audioAdapter)
1220 {
1221 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1222 }
1223 if (enabled)
1224 {
1225 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); /* ichac97 */
1226 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1227 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1228 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1229 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1230 rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
1231
1232 /* the Audio driver */
1233 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1234 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1235 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1236 AudioDriverType_T audioDriver;
1237 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1238 switch (audioDriver)
1239 {
1240 case AudioDriverType_NullAudioDriver:
1241 {
1242 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1243 break;
1244 }
1245#ifdef RT_OS_WINDOWS
1246#ifdef VBOX_WITH_WINMM
1247 case AudioDriverType_WINMMAudioDriver:
1248 {
1249 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1250 break;
1251 }
1252#endif
1253 case AudioDriverType_DSOUNDAudioDriver:
1254 {
1255 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1256 break;
1257 }
1258#endif /* RT_OS_WINDOWS */
1259#ifdef RT_OS_LINUX
1260 case AudioDriverType_OSSAudioDriver:
1261 {
1262 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1263 break;
1264 }
1265# ifdef VBOX_WITH_ALSA
1266 case AudioDriverType_ALSAAudioDriver:
1267 {
1268 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1269 break;
1270 }
1271# endif
1272#endif /* RT_OS_LINUX */
1273#ifdef RT_OS_DARWIN
1274 case AudioDriverType_CoreAudioDriver:
1275 {
1276 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1277 break;
1278 }
1279#endif
1280 }
1281 }
1282
1283 /*
1284 * The USB Controller.
1285 */
1286 ComPtr<IUSBController> USBCtlPtr;
1287 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1288 if (USBCtlPtr)
1289 {
1290 BOOL fEnabled;
1291 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1292 if (fEnabled)
1293 {
1294 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1295 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1296 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1297 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1298 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1299 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1300
1301 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1302 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1303 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1304
1305 /*
1306 * Attach the status driver.
1307 */
1308 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1309 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1310 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1311 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed);RC_CHECK();
1312 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1313 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1314 }
1315 }
1316
1317 /*
1318 * Clipboard
1319 */
1320 {
1321 ClipboardMode_T mode = ClipboardMode_ClipDisabled;
1322 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1323
1324 if (mode != ClipboardMode_ClipDisabled)
1325 {
1326 /* Load the service */
1327 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1328
1329 if (VBOX_FAILURE (rc))
1330 {
1331 LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
1332 /* That is not a fatal failure. */
1333 rc = VINF_SUCCESS;
1334 }
1335 else
1336 {
1337 /* Setup the service. */
1338 VBOXHGCMSVCPARM parm;
1339
1340 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1341
1342 switch (mode)
1343 {
1344 default:
1345 case ClipboardMode_ClipDisabled:
1346 {
1347 LogRel(("VBoxSharedClipboard mode: Off\n"));
1348 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1349 break;
1350 }
1351 case ClipboardMode_ClipGuestToHost:
1352 {
1353 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1354 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1355 break;
1356 }
1357 case ClipboardMode_ClipHostToGuest:
1358 {
1359 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1360 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1361 break;
1362 }
1363 case ClipboardMode_ClipBidirectional:
1364 {
1365 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1366 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1367 break;
1368 }
1369 }
1370
1371 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1372
1373 Log(("Set VBoxSharedClipboard mode\n"));
1374 }
1375 }
1376 }
1377
1378 /*
1379 * CFGM overlay handling.
1380 *
1381 * Here we check the extra data entries for CFGM values
1382 * and create the nodes and insert the values on the fly. Existing
1383 * values will be removed and reinserted. If a value is a valid number,
1384 * it will be inserted as a number, otherwise as a string.
1385 *
1386 * We first perform a run on global extra data, then on the machine
1387 * extra data to support global settings with local overrides.
1388 *
1389 */
1390 Bstr strExtraDataKey;
1391 bool fGlobalExtraData = true;
1392 for (;;)
1393 {
1394 Bstr strNextExtraDataKey;
1395 Bstr strExtraDataValue;
1396
1397 /* get the next key */
1398 if (fGlobalExtraData)
1399 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1400 strExtraDataValue.asOutParam());
1401 else
1402 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1403 strExtraDataValue.asOutParam());
1404
1405 /* stop if for some reason there's nothing more to request */
1406 if (FAILED(hrc) || !strNextExtraDataKey)
1407 {
1408 /* if we're out of global keys, continue with machine, otherwise we're done */
1409 if (fGlobalExtraData)
1410 {
1411 fGlobalExtraData = false;
1412 strExtraDataKey.setNull();
1413 continue;
1414 }
1415 break;
1416 }
1417
1418 strExtraDataKey = strNextExtraDataKey;
1419 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1420
1421 /* we only care about keys starting with "VBoxInternal/" */
1422 if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
1423 continue;
1424 char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
1425
1426 /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
1427 PCFGMNODE pNode;
1428 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1429 if (pszCFGMValueName)
1430 {
1431 /* terminate the node and advance to the value */
1432 *pszCFGMValueName = '\0';
1433 pszCFGMValueName++;
1434
1435 /* does the node already exist? */
1436 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1437 if (pNode)
1438 {
1439 /* the value might already exist, remove it to be safe */
1440 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1441 }
1442 else
1443 {
1444 /* create the node */
1445 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1446 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1447 if (VBOX_FAILURE(rc) || !pNode)
1448 continue;
1449 }
1450 }
1451 else
1452 {
1453 pNode = pRoot;
1454 pszCFGMValueName = pszExtraDataKey;
1455 pszExtraDataKey--;
1456
1457 /* the value might already exist, remove it to be safe */
1458 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1459 }
1460
1461 /* now let's have a look at the value */
1462 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1463 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1464 /* empty value means remove value which we've already done */
1465 if (pszCFGMValue && *pszCFGMValue)
1466 {
1467 /* if it's a valid number, we'll insert it as such, otherwise string */
1468 uint64_t u64Value;
1469 if (RTStrToUInt64Ex(pszCFGMValue, NULL, 0, &u64Value) == VINF_SUCCESS)
1470 {
1471 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1472 }
1473 else
1474 {
1475 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1476 }
1477 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1478 }
1479 }
1480
1481#undef H
1482#undef RC_CHECK
1483#undef STR_FREE
1484#undef STR_CONV
1485
1486 /* Register VM state change handler */
1487 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
1488 AssertRC (rc2);
1489 if (VBOX_SUCCESS (rc))
1490 rc = rc2;
1491
1492 /* Register VM runtime error handler */
1493 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
1494 AssertRC (rc2);
1495 if (VBOX_SUCCESS (rc))
1496 rc = rc2;
1497
1498 /* Save the VM pointer in the machine object */
1499 pConsole->mpVM = pVM;
1500
1501 LogFlowFunc (("vrc = %Vrc\n", rc));
1502 LogFlowFuncLeave();
1503
1504 return rc;
1505}
1506
1507
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