VirtualBox

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

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

Solaris crossbow changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.5 KB
Line 
1/** $Id: ConsoleImpl2.cpp 5698 2007-11-12 06:31:09Z 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 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1029# endif
1030# else
1031 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1032# endif
1033 }
1034#elif defined(RT_OS_WINDOWS)
1035 if (fSniffer)
1036 {
1037 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1038 }
1039 else
1040 {
1041 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1042 }
1043 Bstr hostInterfaceName;
1044 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1045 ComPtr<IHostNetworkInterfaceCollection> coll;
1046 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1047 ComPtr<IHostNetworkInterface> hostInterface;
1048 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1049 if (!SUCCEEDED(rc))
1050 {
1051 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1052 hrc = networkAdapter->Detach(); H();
1053 }
1054 else
1055 {
1056 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1057 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1058 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1059 Guid hostIFGuid;
1060 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1061 char szDriverGUID[256] = {0};
1062 /* add curly brackets */
1063 szDriverGUID[0] = '{';
1064 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1065 strcat(szDriverGUID, "}");
1066 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1067 }
1068#else
1069# error "Port me"
1070#endif
1071 }
1072 else
1073 {
1074 switch (hrc)
1075 {
1076#ifdef RT_OS_LINUX
1077 case VERR_ACCESS_DENIED:
1078 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1079 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1080 "permissions of that node. Either do 'chmod 0666 /dev/net/tun' or "
1081 "change the group of that node and get member of that group. Make "
1082 "sure that these changes are permanently in particular if you are "
1083 "using udev"));
1084#endif /* RT_OS_LINUX */
1085 default:
1086 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1087 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1088 "Failed to initialize Host Interface Networking"));
1089 }
1090 }
1091 break;
1092 }
1093
1094 case NetworkAttachmentType_InternalNetworkAttachment:
1095 {
1096 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1097 STR_CONV();
1098 if (psz && *psz)
1099 {
1100 if (fSniffer)
1101 {
1102 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1103 }
1104 else
1105 {
1106 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1107 }
1108 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1109 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1110 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1111 }
1112 STR_FREE();
1113 break;
1114 }
1115
1116 default:
1117 AssertMsgFailed(("should not get here!\n"));
1118 break;
1119 }
1120 }
1121
1122 /*
1123 * Serial (UART) Ports
1124 */
1125 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1126 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1127 {
1128 ComPtr<ISerialPort> serialPort;
1129 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1130 BOOL fEnabled = FALSE;
1131 if (serialPort)
1132 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1133 if (!fEnabled)
1134 continue;
1135
1136 char szInstance[4]; Assert(ulInstance <= 999);
1137 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1138
1139 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1140 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1141
1142 ULONG ulIRQ, ulIOBase;
1143 PortMode_T HostMode;
1144 Bstr path;
1145 BOOL fServer;
1146 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1147 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1148 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1149 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1150 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1151 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1152 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1153 if (HostMode != PortMode_DisconnectedPort)
1154 {
1155 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1156 if (HostMode == PortMode_HostPipePort)
1157 {
1158 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1159 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1160 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1161 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1162 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1163 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1164 }
1165 else if (HostMode == PortMode_HostDevicePort)
1166 {
1167 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1168 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1169 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1170 }
1171 }
1172 }
1173
1174 /*
1175 * Parallel (LPT) Ports
1176 */
1177 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1178 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1179 {
1180 ComPtr<IParallelPort> parallelPort;
1181 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1182 BOOL fEnabled = FALSE;
1183 if (parallelPort)
1184 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1185 if (!fEnabled)
1186 continue;
1187
1188 char szInstance[4]; Assert(ulInstance <= 999);
1189 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1190
1191 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1192 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1193
1194 ULONG ulIRQ, ulIOBase;
1195 Bstr DevicePath;
1196 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1197 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1198 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1199 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1200 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1201 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1202 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1203 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1204 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1205 }
1206
1207 /*
1208 * VMM Device
1209 */
1210 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1211 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1212 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1213 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1214 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1215 Assert(!afPciDeviceNo[4]);
1216 afPciDeviceNo[4] = true;
1217 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1218
1219 /* the VMM device's Main driver */
1220 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1221 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1222 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1223 VMMDev *pVMMDev = pConsole->mVMMDev;
1224 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1225
1226 /*
1227 * Attach the status driver.
1228 */
1229 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1230 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1231 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1232 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1233 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1234 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1235
1236 /*
1237 * Audio Sniffer Device
1238 */
1239 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1240 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1241 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1242
1243 /* the Audio Sniffer device's Main driver */
1244 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1245 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1246 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1247 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1248 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1249
1250 /*
1251 * AC'97 ICH audio
1252 */
1253 ComPtr<IAudioAdapter> audioAdapter;
1254 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1255 BOOL enabled = FALSE;
1256 if (audioAdapter)
1257 {
1258 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1259 }
1260 if (enabled)
1261 {
1262 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); /* ichac97 */
1263 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1264 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1265 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1266 Assert(!afPciDeviceNo[5]);
1267 afPciDeviceNo[5] = true;
1268 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1269 rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
1270
1271 /* the Audio driver */
1272 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1273 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1274 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1275 AudioDriverType_T audioDriver;
1276 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1277 switch (audioDriver)
1278 {
1279 case AudioDriverType_NullAudioDriver:
1280 {
1281 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1282 break;
1283 }
1284#ifdef RT_OS_WINDOWS
1285#ifdef VBOX_WITH_WINMM
1286 case AudioDriverType_WINMMAudioDriver:
1287 {
1288 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1289 break;
1290 }
1291#endif
1292 case AudioDriverType_DSOUNDAudioDriver:
1293 {
1294 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1295 break;
1296 }
1297#endif /* RT_OS_WINDOWS */
1298#ifdef RT_OS_LINUX
1299 case AudioDriverType_OSSAudioDriver:
1300 {
1301 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1302 break;
1303 }
1304# ifdef VBOX_WITH_ALSA
1305 case AudioDriverType_ALSAAudioDriver:
1306 {
1307 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1308 break;
1309 }
1310# endif
1311#endif /* RT_OS_LINUX */
1312#ifdef RT_OS_DARWIN
1313 case AudioDriverType_CoreAudioDriver:
1314 {
1315 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1316 break;
1317 }
1318#endif
1319 }
1320 }
1321
1322 /*
1323 * The USB Controller.
1324 */
1325 ComPtr<IUSBController> USBCtlPtr;
1326 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1327 if (USBCtlPtr)
1328 {
1329 BOOL fEnabled;
1330 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1331 if (fEnabled)
1332 {
1333 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1334 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1335 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1336 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1337 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1338 Assert(!afPciDeviceNo[6]);
1339 afPciDeviceNo[6] = true;
1340 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1341
1342 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1343 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1344 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1345
1346 /*
1347 * Attach the status driver.
1348 */
1349 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1350 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1351 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1352 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed);RC_CHECK();
1353 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1354 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1355
1356#ifdef VBOX_WITH_EHCI
1357 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1358 if (fEnabled)
1359 {
1360 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1361 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1362 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1363 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1364 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1365 Assert(!afPciDeviceNo[11]);
1366 afPciDeviceNo[11] = true;
1367 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1368
1369 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1370 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1371 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1372
1373 /*
1374 * Attach the status driver.
1375 */
1376 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1377 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1378 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1379 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed);RC_CHECK();
1380 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1381 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1382 }
1383#endif
1384 }
1385 }
1386
1387 /*
1388 * Clipboard
1389 */
1390 {
1391 ClipboardMode_T mode = ClipboardMode_ClipDisabled;
1392 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1393
1394 if (mode != ClipboardMode_ClipDisabled)
1395 {
1396 /* Load the service */
1397 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1398
1399 if (VBOX_FAILURE (rc))
1400 {
1401 LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
1402 /* That is not a fatal failure. */
1403 rc = VINF_SUCCESS;
1404 }
1405 else
1406 {
1407 /* Setup the service. */
1408 VBOXHGCMSVCPARM parm;
1409
1410 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1411
1412 switch (mode)
1413 {
1414 default:
1415 case ClipboardMode_ClipDisabled:
1416 {
1417 LogRel(("VBoxSharedClipboard mode: Off\n"));
1418 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1419 break;
1420 }
1421 case ClipboardMode_ClipGuestToHost:
1422 {
1423 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1424 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1425 break;
1426 }
1427 case ClipboardMode_ClipHostToGuest:
1428 {
1429 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1430 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1431 break;
1432 }
1433 case ClipboardMode_ClipBidirectional:
1434 {
1435 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1436 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1437 break;
1438 }
1439 }
1440
1441 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1442
1443 Log(("Set VBoxSharedClipboard mode\n"));
1444 }
1445 }
1446 }
1447
1448 /*
1449 * CFGM overlay handling.
1450 *
1451 * Here we check the extra data entries for CFGM values
1452 * and create the nodes and insert the values on the fly. Existing
1453 * values will be removed and reinserted. If a value is a valid number,
1454 * it will be inserted as a number, otherwise as a string.
1455 *
1456 * We first perform a run on global extra data, then on the machine
1457 * extra data to support global settings with local overrides.
1458 *
1459 */
1460 Bstr strExtraDataKey;
1461 bool fGlobalExtraData = true;
1462 for (;;)
1463 {
1464 Bstr strNextExtraDataKey;
1465 Bstr strExtraDataValue;
1466
1467 /* get the next key */
1468 if (fGlobalExtraData)
1469 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1470 strExtraDataValue.asOutParam());
1471 else
1472 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1473 strExtraDataValue.asOutParam());
1474
1475 /* stop if for some reason there's nothing more to request */
1476 if (FAILED(hrc) || !strNextExtraDataKey)
1477 {
1478 /* if we're out of global keys, continue with machine, otherwise we're done */
1479 if (fGlobalExtraData)
1480 {
1481 fGlobalExtraData = false;
1482 strExtraDataKey.setNull();
1483 continue;
1484 }
1485 break;
1486 }
1487
1488 strExtraDataKey = strNextExtraDataKey;
1489 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1490
1491 /* we only care about keys starting with "VBoxInternal/" */
1492 if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
1493 continue;
1494 char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
1495
1496 /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
1497 PCFGMNODE pNode;
1498 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1499 if (pszCFGMValueName)
1500 {
1501 /* terminate the node and advance to the value */
1502 *pszCFGMValueName = '\0';
1503 pszCFGMValueName++;
1504
1505 /* does the node already exist? */
1506 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1507 if (pNode)
1508 {
1509 /* the value might already exist, remove it to be safe */
1510 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1511 }
1512 else
1513 {
1514 /* create the node */
1515 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1516 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1517 if (VBOX_FAILURE(rc) || !pNode)
1518 continue;
1519 }
1520 }
1521 else
1522 {
1523 pNode = pRoot;
1524 pszCFGMValueName = pszExtraDataKey;
1525 pszExtraDataKey--;
1526
1527 /* the value might already exist, remove it to be safe */
1528 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1529 }
1530
1531 /* now let's have a look at the value */
1532 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1533 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1534 /* empty value means remove value which we've already done */
1535 if (pszCFGMValue && *pszCFGMValue)
1536 {
1537 /* if it's a valid number, we'll insert it as such, otherwise string */
1538 uint64_t u64Value;
1539 char *pszNext = NULL;
1540 if ( RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
1541 && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
1542 )
1543 {
1544 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1545 }
1546 else
1547 {
1548 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1549 }
1550 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1551 }
1552 }
1553
1554#undef H
1555#undef RC_CHECK
1556#undef STR_FREE
1557#undef STR_CONV
1558
1559 /* Register VM state change handler */
1560 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
1561 AssertRC (rc2);
1562 if (VBOX_SUCCESS (rc))
1563 rc = rc2;
1564
1565 /* Register VM runtime error handler */
1566 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
1567 AssertRC (rc2);
1568 if (VBOX_SUCCESS (rc))
1569 rc = rc2;
1570
1571 /* Save the VM pointer in the machine object */
1572 pConsole->mpVM = pVM;
1573
1574 LogFlowFunc (("vrc = %Vrc\n", rc));
1575 LogFlowFuncLeave();
1576
1577 return rc;
1578}
1579
1580
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