VirtualBox

source: vbox/trunk/include/VBox/settings.h@ 26003

Last change on this file since 26003 was 25901, checked in by vboxsync, 15 years ago

CPU hotplug: Merge 4th patch. Implements the Main API and a VBoxManage interface to turn CPU hotplug on/off and to add/remove CPUs while the VM is running

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 20.1 KB
Line 
1/** @file
2 * Settings file data structures.
3 *
4 * These structures are created by the settings file loader and filled with values
5 * copied from the raw XML data. This allows us to finally make the XML reader
6 * version-independent and read VirtualBox XML files from earlier versions without
7 * requiring complicated, tedious and error-prone XSLT conversions.
8 *
9 * Note: Headers in Main code have been tweaked to only declare the structures
10 * defined here so that this header need only be included from code files that
11 * actually use these structures.
12 */
13
14/*
15 * Copyright (C) 2007-2010 Sun Microsystems, Inc.
16 *
17 * This file is part of VirtualBox Open Source Edition (OSE), as
18 * available from http://www.virtualbox.org. This file is free software;
19 * you can redistribute it and/or modify it under the terms of the GNU
20 * General Public License (GPL) as published by the Free Software
21 * Foundation, in version 2 as it comes in the "COPYING" file of the
22 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
23 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
28 * VirtualBox OSE distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
35 * Clara, CA 95054 USA or visit http://www.sun.com if you need
36 * additional information or have any questions.
37 */
38
39#ifndef ___VBox_settings_h
40#define ___VBox_settings_h
41
42#include <iprt/time.h>
43
44#include "VBox/com/VirtualBox.h"
45
46#include <VBox/com/Guid.h>
47#include <VBox/com/string.h>
48
49#include <list>
50#include <map>
51#include <vector>
52
53namespace xml
54{
55 class ElementNode;
56}
57
58namespace settings
59{
60
61class ConfigFileError;
62
63////////////////////////////////////////////////////////////////////////////////
64//
65// Helper classes
66//
67////////////////////////////////////////////////////////////////////////////////
68
69// ExtraDataItem (used by both VirtualBox.xml and machines XML)
70typedef std::map<com::Utf8Str, com::Utf8Str> ExtraDataItemsMap;
71struct USBDeviceFilter;
72typedef std::list<USBDeviceFilter> USBDeviceFiltersList;
73
74/**
75 * Common base class for both MainConfigFile and MachineConfigFile
76 * which contains some common logic for both.
77 */
78class ConfigFileBase
79{
80public:
81 bool fileExists();
82
83protected:
84 ConfigFileBase(const com::Utf8Str *pstrFilename);
85 ~ConfigFileBase();
86
87 void parseUUID(com::Guid &guid,
88 const com::Utf8Str &strUUID) const;
89 void parseTimestamp(RTTIMESPEC &timestamp,
90 const com::Utf8Str &str) const;
91
92 com::Utf8Str makeString(const RTTIMESPEC &tm);
93 com::Utf8Str makeString(const com::Guid &guid);
94
95 void readExtraData(const xml::ElementNode &elmExtraData,
96 ExtraDataItemsMap &map);
97 void readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
98 USBDeviceFiltersList &ll);
99
100 void createStubDocument();
101
102 void writeExtraData(xml::ElementNode &elmParent, const ExtraDataItemsMap &me);
103 void writeUSBDeviceFilters(xml::ElementNode &elmParent,
104 const USBDeviceFiltersList &ll,
105 bool fHostMode);
106
107 void clearDocument();
108
109 struct Data;
110 Data *m;
111
112 friend class ConfigFileError;
113};
114
115////////////////////////////////////////////////////////////////////////////////
116//
117// VirtualBox.xml structures
118//
119////////////////////////////////////////////////////////////////////////////////
120
121struct USBDeviceFilter
122{
123 USBDeviceFilter()
124 : fActive(false),
125 action(USBDeviceFilterAction_Null),
126 ulMaskedInterfaces(0)
127 {}
128
129 com::Utf8Str strName;
130 bool fActive;
131 com::Utf8Str strVendorId,
132 strProductId,
133 strRevision,
134 strManufacturer,
135 strProduct,
136 strSerialNumber,
137 strPort;
138 USBDeviceFilterAction_T action; // only used with host USB filters
139 com::Utf8Str strRemote; // irrelevant for host USB objects
140 uint32_t ulMaskedInterfaces; // irrelevant for host USB objects
141};
142
143struct Host
144{
145 USBDeviceFiltersList llUSBDeviceFilters;
146};
147
148struct SystemProperties
149{
150 SystemProperties()
151 : ulLogHistoryCount(3)
152 {}
153
154 com::Utf8Str strDefaultMachineFolder;
155 com::Utf8Str strDefaultHardDiskFolder;
156 com::Utf8Str strDefaultHardDiskFormat;
157 com::Utf8Str strRemoteDisplayAuthLibrary;
158 com::Utf8Str strWebServiceAuthLibrary;
159 uint32_t ulLogHistoryCount;
160};
161
162typedef std::map<com::Utf8Str, com::Utf8Str> PropertiesMap;
163
164struct Medium;
165typedef std::list<Medium> MediaList;
166
167struct Medium
168{
169 com::Guid uuid;
170 com::Utf8Str strLocation;
171 com::Utf8Str strDescription;
172
173 // the following are for hard disks only:
174 com::Utf8Str strFormat;
175 bool fAutoReset; // optional, only for diffs, default is false
176 PropertiesMap properties;
177 MediumType_T hdType;
178
179 MediaList llChildren; // only used with hard disks
180};
181
182struct MachineRegistryEntry
183{
184 com::Guid uuid;
185 com::Utf8Str strSettingsFile;
186};
187typedef std::list<MachineRegistryEntry> MachinesRegistry;
188
189struct DHCPServer
190{
191 com::Utf8Str strNetworkName,
192 strIPAddress,
193 strIPNetworkMask,
194 strIPLower,
195 strIPUpper;
196 bool fEnabled;
197};
198typedef std::list<DHCPServer> DHCPServersList;
199
200class MainConfigFile : public ConfigFileBase
201{
202public:
203 MainConfigFile(const com::Utf8Str *pstrFilename);
204
205 typedef enum {Error, HardDisk, DVDImage, FloppyImage} MediaType;
206 void readMedium(MediaType t, const xml::ElementNode &elmMedium, MediaList &llMedia);
207 void readMediaRegistry(const xml::ElementNode &elmMediaRegistry);
208 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
209 void readDHCPServers(const xml::ElementNode &elmDHCPServers);
210
211 void writeHardDisk(xml::ElementNode &elmMedium,
212 const Medium &m,
213 uint32_t level);
214 void write(const com::Utf8Str strFilename);
215
216 Host host;
217 SystemProperties systemProperties;
218 MediaList llHardDisks,
219 llDvdImages,
220 llFloppyImages;
221 MachinesRegistry llMachines;
222 DHCPServersList llDhcpServers;
223 ExtraDataItemsMap mapExtraDataItems;
224};
225
226////////////////////////////////////////////////////////////////////////////////
227//
228// Machine XML structures
229//
230////////////////////////////////////////////////////////////////////////////////
231
232struct VRDPSettings
233{
234 VRDPSettings()
235 : fEnabled(true),
236 authType(VRDPAuthType_Null),
237 ulAuthTimeout(5000),
238 fAllowMultiConnection(false),
239 fReuseSingleConnection(false)
240 {}
241
242 bool fEnabled;
243 com::Utf8Str strPort;
244 com::Utf8Str strNetAddress;
245 VRDPAuthType_T authType;
246 uint32_t ulAuthTimeout;
247 bool fAllowMultiConnection,
248 fReuseSingleConnection;
249};
250
251struct BIOSSettings
252{
253 BIOSSettings()
254 : fACPIEnabled(true),
255 fIOAPICEnabled(false),
256 fLogoFadeIn(true),
257 fLogoFadeOut(false),
258 ulLogoDisplayTime(0),
259 biosBootMenuMode(BIOSBootMenuMode_MessageAndMenu),
260 fPXEDebugEnabled(false),
261 llTimeOffset(0)
262 {}
263
264 bool operator==(const BIOSSettings &d) const
265 {
266 return ( this == &d
267 || ( fACPIEnabled == d.fACPIEnabled
268 && fIOAPICEnabled == d.fIOAPICEnabled
269 && fLogoFadeIn == d.fLogoFadeIn
270 && fLogoFadeOut == d.fLogoFadeOut
271 && ulLogoDisplayTime == d.ulLogoDisplayTime
272 && strLogoImagePath == d.strLogoImagePath
273 && biosBootMenuMode == d.biosBootMenuMode
274 && fPXEDebugEnabled == d.fPXEDebugEnabled
275 && llTimeOffset == d.llTimeOffset)
276 );
277 }
278
279 bool fACPIEnabled,
280 fIOAPICEnabled,
281 fLogoFadeIn,
282 fLogoFadeOut;
283 uint32_t ulLogoDisplayTime;
284 com::Utf8Str strLogoImagePath;
285 BIOSBootMenuMode_T biosBootMenuMode;
286 bool fPXEDebugEnabled;
287 int64_t llTimeOffset;
288};
289
290struct USBController
291{
292 USBController()
293 : fEnabled(false),
294 fEnabledEHCI(false)
295 {}
296
297 bool fEnabled;
298 bool fEnabledEHCI;
299 USBDeviceFiltersList llDeviceFilters;
300};
301
302struct NetworkAdapter
303{
304 NetworkAdapter()
305 : ulSlot(0),
306 type(NetworkAdapterType_Am79C970A),
307 fEnabled(false),
308 fCableConnected(false),
309 ulLineSpeed(0),
310 fTraceEnabled(false),
311 mode(NetworkAttachmentType_Null)
312 {}
313
314 uint32_t ulSlot;
315
316 NetworkAdapterType_T type;
317 bool fEnabled;
318 com::Utf8Str strMACAddress;
319 bool fCableConnected;
320 uint32_t ulLineSpeed;
321 bool fTraceEnabled;
322 com::Utf8Str strTraceFile;
323
324 NetworkAttachmentType_T mode;
325 com::Utf8Str strName; // with NAT: nat network or empty;
326 // with bridged: host interface or empty;
327 // otherwise: network name (required)
328};
329typedef std::list<NetworkAdapter> NetworkAdaptersList;
330
331struct SerialPort
332{
333 SerialPort()
334 : ulSlot(0),
335 fEnabled(false),
336 ulIOBase(4),
337 ulIRQ(0x3f8),
338 portMode(PortMode_Disconnected),
339 fServer(false)
340 {}
341
342 bool operator==(const SerialPort &d) const
343 {
344 return (this == &d)
345 || ( ulSlot == d.ulSlot
346 && fEnabled == d.fEnabled
347 && ulIOBase == d.ulIOBase
348 && ulIRQ == d.ulIRQ
349 && portMode == d.portMode
350 && strPath == d.strPath
351 && fServer == d.fServer
352 );
353 }
354
355 uint32_t ulSlot;
356
357 bool fEnabled;
358 uint32_t ulIOBase;
359 uint32_t ulIRQ;
360 PortMode_T portMode;
361 com::Utf8Str strPath;
362 bool fServer;
363};
364typedef std::list<SerialPort> SerialPortsList;
365
366struct ParallelPort
367{
368 ParallelPort()
369 : ulSlot(0),
370 fEnabled(false),
371 ulIOBase(0x378),
372 ulIRQ(4)
373 {}
374
375 bool operator==(const ParallelPort &d) const
376 {
377 return (this == &d)
378 || ( ulSlot == d.ulSlot
379 && fEnabled == d.fEnabled
380 && ulIOBase == d.ulIOBase
381 && ulIRQ == d.ulIRQ
382 && strPath == d.strPath
383 );
384 }
385
386 uint32_t ulSlot;
387
388 bool fEnabled;
389 uint32_t ulIOBase;
390 uint32_t ulIRQ;
391 com::Utf8Str strPath;
392};
393typedef std::list<ParallelPort> ParallelPortsList;
394
395struct AudioAdapter
396{
397 AudioAdapter()
398 : fEnabled(true),
399 controllerType(AudioControllerType_AC97),
400 driverType(AudioDriverType_Null)
401 {}
402
403 bool fEnabled;
404 AudioControllerType_T controllerType;
405 AudioDriverType_T driverType;
406};
407
408struct SharedFolder
409{
410 SharedFolder()
411 : fWritable(false)
412 {}
413
414 com::Utf8Str strName,
415 strHostPath;
416 bool fWritable;
417};
418typedef std::list<SharedFolder> SharedFoldersList;
419
420struct GuestProperty
421{
422 GuestProperty()
423 : timestamp(0)
424 {};
425
426 com::Utf8Str strName,
427 strValue;
428 uint64_t timestamp;
429 com::Utf8Str strFlags;
430};
431typedef std::list<GuestProperty> GuestPropertiesList;
432
433typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
434
435struct CpuIdLeaf
436{
437 CpuIdLeaf()
438 : ulId(UINT32_MAX),
439 ulEax(0),
440 ulEbx(0),
441 ulEcx(0),
442 ulEdx(0)
443 {}
444
445 uint32_t ulId;
446 uint32_t ulEax;
447 uint32_t ulEbx;
448 uint32_t ulEcx;
449 uint32_t ulEdx;
450};
451typedef std::list<CpuIdLeaf> CpuIdLeafsList;
452
453struct Cpu
454{
455 Cpu()
456 : ulId(UINT32_MAX)
457 {}
458
459 uint32_t ulId;
460};
461typedef std::list<Cpu> CpuList;
462
463struct Hardware
464{
465 Hardware();
466
467 com::Utf8Str strVersion; // hardware version, optional
468 com::Guid uuid; // hardware uuid, optional (null).
469
470 bool fHardwareVirt,
471 fHardwareVirtExclusive,
472 fNestedPaging,
473 fVPID,
474 fSyntheticCpu,
475 fPAE;
476 uint32_t cCPUs;
477 bool fCpuHotPlug; // requires settings version 1.11 (VirtualBox 3.2)
478 CpuList llCpus; // requires settings version 1.11 (VirtualBox 3.2)
479 CpuIdLeafsList llCpuIdLeafs;
480
481 uint32_t ulMemorySizeMB;
482
483 BootOrderMap mapBootOrder; // item 0 has highest priority
484
485 uint32_t ulVRAMSizeMB;
486 uint32_t cMonitors;
487 bool fAccelerate3D,
488 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
489 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
490
491 VRDPSettings vrdpSettings;
492
493 BIOSSettings biosSettings;
494 USBController usbController;
495 NetworkAdaptersList llNetworkAdapters;
496 SerialPortsList llSerialPorts;
497 ParallelPortsList llParallelPorts;
498 AudioAdapter audioAdapter;
499
500 // technically these two have no business in the hardware section, but for some
501 // clever reason <Hardware> is where they are in the XML....
502 SharedFoldersList llSharedFolders;
503 ClipboardMode_T clipboardMode;
504
505 uint32_t ulMemoryBalloonSize;
506 uint32_t ulStatisticsUpdateInterval;
507
508 GuestPropertiesList llGuestProperties;
509 com::Utf8Str strNotificationPatterns;
510};
511
512/**
513 * A device attached to a storage controller. This can either be a
514 * hard disk or a DVD drive or a floppy drive and also specifies
515 * which medium is "in" the drive; as a result, this is a combination
516 * of the Main IMedium and IMediumAttachment interfaces.
517 */
518struct AttachedDevice
519{
520 AttachedDevice()
521 : deviceType(DeviceType_Null),
522 fPassThrough(false),
523 lPort(0),
524 lDevice(0)
525 {}
526
527 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
528
529 // DVDs can be in pass-through mode:
530 bool fPassThrough;
531
532 int32_t lPort;
533 int32_t lDevice;
534
535 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
536 // this is its UUID; it depends on deviceType which media registry this then needs to
537 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
538 com::Guid uuid;
539
540 // for DVDs and floppies, the attachment can also be a host device:
541 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
542};
543typedef std::list<AttachedDevice> AttachedDevicesList;
544
545struct StorageController
546{
547 StorageController()
548 : storageBus(StorageBus_IDE),
549 controllerType(StorageControllerType_PIIX3),
550 ulPortCount(2),
551 ulInstance(0),
552 lIDE0MasterEmulationPort(0),
553 lIDE0SlaveEmulationPort(0),
554 lIDE1MasterEmulationPort(0),
555 lIDE1SlaveEmulationPort(0)
556 {}
557
558 com::Utf8Str strName;
559 StorageBus_T storageBus; // _SATA, _SCSI, _IDE
560 StorageControllerType_T controllerType;
561 uint32_t ulPortCount;
562 uint32_t ulInstance;
563
564 // only for when controllerType == StorageControllerType_IntelAhci:
565 int32_t lIDE0MasterEmulationPort,
566 lIDE0SlaveEmulationPort,
567 lIDE1MasterEmulationPort,
568 lIDE1SlaveEmulationPort;
569
570 AttachedDevicesList llAttachedDevices;
571};
572typedef std::list<StorageController> StorageControllersList;
573
574// wrap the list into an extra struct so we can use the struct without
575// having to define the typedef above in headers
576struct Storage
577{
578 StorageControllersList llStorageControllers;
579};
580
581struct Snapshot;
582typedef std::list<Snapshot> SnapshotsList;
583
584struct Snapshot
585{
586 com::Guid uuid;
587 com::Utf8Str strName,
588 strDescription; // optional
589 RTTIMESPEC timestamp;
590
591 com::Utf8Str strStateFile; // for online snapshots only
592
593 Hardware hardware;
594 Storage storage;
595
596 SnapshotsList llChildSnapshots;
597};
598
599
600class MachineConfigFile : public ConfigFileBase
601{
602public:
603 MachineConfigFile(const com::Utf8Str *pstrFilename);
604
605 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
606 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
607 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
608 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
609 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
610 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
611 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
612 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw, Storage &strg);
613 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
614 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
615 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
616 void readSnapshot(const xml::ElementNode &elmSnapshot, Snapshot &snap);
617 void convertOldOSType_pre1_5(com::Utf8Str &str);
618 void readMachine(const xml::ElementNode &elmMachine);
619
620 void writeHardware(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg);
621 void writeStorageControllers(xml::ElementNode &elmParent, const Storage &st);
622 void writeSnapshot(xml::ElementNode &elmParent, const Snapshot &snap);
623 void bumpSettingsVersionIfNeeded();
624 void write(const com::Utf8Str &strFilename);
625
626 com::Guid uuid;
627 com::Utf8Str strName;
628 bool fNameSync;
629 com::Utf8Str strDescription;
630 com::Utf8Str strOsType;
631 com::Utf8Str strStateFile;
632 com::Guid uuidCurrentSnapshot;
633 com::Utf8Str strSnapshotFolder;
634 bool fTeleporterEnabled;
635 uint32_t uTeleporterPort;
636 com::Utf8Str strTeleporterAddress;
637 com::Utf8Str strTeleporterPassword;
638 bool fRTCUseUTC;
639
640 bool fCurrentStateModified; // optional, default is true
641 RTTIMESPEC timeLastStateChange; // optional, defaults to now
642 bool fAborted; // optional, default is false
643
644 Hardware hardwareMachine;
645 Storage storageMachine;
646
647 ExtraDataItemsMap mapExtraDataItems;
648
649 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
650};
651
652} // namespace settings
653
654
655#endif /* ___VBox_settings_h */
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