VirtualBox

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

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

fa -> af. comment.

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