VirtualBox

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

Last change on this file since 47100 was 47018, checked in by vboxsync, 12 years ago

Main: re-commit r86967
Main/Network: DHCP server has got the ear in Main, and we able create/describe more complex infrostructures. DHCP server together with Lwip NAT can handle per vm/slot configuration and store them in xml settings.
place-holder: Host interface nameserver list, domain name and search strings, I suppose that this functions should be used on initialization stage and then on host configuration change even or directly from event.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 41.6 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 was all new with VirtualBox 3.1 and allows us
6 * to finally make the XML reader version-independent and read VirtualBox XML files
7 * from earlier and even newer (future) versions without requiring complicated,
8 * tedious and error-prone XSLT conversions.
9 *
10 * It is this file that defines all structures that map VirtualBox global and
11 * machine settings to XML files. These structures are used by the rest of Main,
12 * even though this header file does not require anything else in Main.
13 *
14 * Note: Headers in Main code have been tweaked to only declare the structures
15 * defined here so that this header need only be included from code files that
16 * actually use these structures.
17 */
18
19/*
20 * Copyright (C) 2007-2013 Oracle Corporation
21 *
22 * This file is part of VirtualBox Open Source Edition (OSE), as
23 * available from http://www.virtualbox.org. This file is free software;
24 * you can redistribute it and/or modify it under the terms of the GNU
25 * General Public License (GPL) as published by the Free Software
26 * Foundation, in version 2 as it comes in the "COPYING" file of the
27 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
28 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29 *
30 * The contents of this file may alternatively be used under the terms
31 * of the Common Development and Distribution License Version 1.0
32 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
33 * VirtualBox OSE distribution, in which case the provisions of the
34 * CDDL are applicable instead of those of the GPL.
35 *
36 * You may elect to license modified versions of this file under the
37 * terms and conditions of either the GPL or the CDDL or both.
38 */
39
40#ifndef ___VBox_settings_h
41#define ___VBox_settings_h
42
43#include <iprt/time.h>
44
45#include "VBox/com/VirtualBox.h"
46
47#include <VBox/com/Guid.h>
48#include <VBox/com/string.h>
49
50#include <list>
51#include <map>
52
53/**
54 * Maximum depth of the snapshot tree, to prevent stack overflows.
55 * XPCOM has a relatively low stack size for its workers, and we have
56 * to avoid crashes due to exceeding the limit both on reading and
57 * writing config files.
58 */
59#define SETTINGS_SNAPSHOT_DEPTH_MAX 250
60
61namespace xml
62{
63 class ElementNode;
64}
65
66namespace settings
67{
68
69class ConfigFileError;
70
71////////////////////////////////////////////////////////////////////////////////
72//
73// Structures shared between Machine XML and VirtualBox.xml
74//
75////////////////////////////////////////////////////////////////////////////////
76
77/**
78 * USB device filter definition. This struct is used both in MainConfigFile
79 * (for global USB filters) and MachineConfigFile (for machine filters).
80 *
81 * NOTE: If you add any fields in here, you must update a) the constructor and b)
82 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
83 * your settings might never get saved.
84 */
85struct USBDeviceFilter
86{
87 USBDeviceFilter()
88 : fActive(false),
89 action(USBDeviceFilterAction_Null),
90 ulMaskedInterfaces(0)
91 {}
92
93 bool operator==(const USBDeviceFilter&u) const;
94
95 com::Utf8Str strName;
96 bool fActive;
97 com::Utf8Str strVendorId,
98 strProductId,
99 strRevision,
100 strManufacturer,
101 strProduct,
102 strSerialNumber,
103 strPort;
104 USBDeviceFilterAction_T action; // only used with host USB filters
105 com::Utf8Str strRemote; // irrelevant for host USB objects
106 uint32_t ulMaskedInterfaces; // irrelevant for host USB objects
107};
108
109typedef std::map<com::Utf8Str, com::Utf8Str> StringsMap;
110typedef std::list<com::Utf8Str> StringsList;
111
112// ExtraDataItem (used by both VirtualBox.xml and machines XML)
113struct USBDeviceFilter;
114typedef std::list<USBDeviceFilter> USBDeviceFiltersList;
115
116struct Medium;
117typedef std::list<Medium> MediaList;
118
119/**
120 * NOTE: If you add any fields in here, you must update a) the constructor and b)
121 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
122 * your settings might never get saved.
123 */
124struct Medium
125{
126 Medium()
127 : fAutoReset(false),
128 hdType(MediumType_Normal)
129 {}
130
131 com::Guid uuid;
132 com::Utf8Str strLocation;
133 com::Utf8Str strDescription;
134
135 // the following are for hard disks only:
136 com::Utf8Str strFormat;
137 bool fAutoReset; // optional, only for diffs, default is false
138 StringsMap properties;
139 MediumType_T hdType;
140
141 MediaList llChildren; // only used with hard disks
142
143 bool operator==(const Medium &m) const;
144};
145
146/**
147 * A media registry. Starting with VirtualBox 3.3, this can appear in both the
148 * VirtualBox.xml file as well as machine XML files with settings version 1.11
149 * or higher, so these lists are now in ConfigFileBase.
150 *
151 * NOTE: If you add any fields in here, you must update a) the constructor and b)
152 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
153 * your settings might never get saved.
154 */
155struct MediaRegistry
156{
157 MediaList llHardDisks,
158 llDvdImages,
159 llFloppyImages;
160
161 bool operator==(const MediaRegistry &m) const;
162};
163
164/**
165 *
166 */
167 struct NATRule
168 {
169 NATRule()
170 : proto(NATProtocol_TCP),
171 u16HostPort(0),
172 u16GuestPort(0)
173 {}
174
175 bool operator==(const NATRule &r) const
176 {
177 return strName == r.strName
178 && proto == r.proto
179 && u16HostPort == r.u16HostPort
180 && strHostIP == r.strHostIP
181 && u16GuestPort == r.u16GuestPort
182 && strGuestIP == r.strGuestIP;
183 }
184
185 com::Utf8Str strName;
186 NATProtocol_T proto;
187 uint16_t u16HostPort;
188 com::Utf8Str strHostIP;
189 uint16_t u16GuestPort;
190 com::Utf8Str strGuestIP;
191 };
192 typedef std::list<NATRule> NATRuleList;
193
194/**
195 * Common base class for both MainConfigFile and MachineConfigFile
196 * which contains some common logic for both.
197 */
198class ConfigFileBase
199{
200public:
201 bool fileExists();
202
203 void copyBaseFrom(const ConfigFileBase &b);
204
205protected:
206 ConfigFileBase(const com::Utf8Str *pstrFilename);
207 /* Note: this copy constructor doesn't create a full copy of other, cause
208 * the file based stuff (xml doc) could not be copied. */
209 ConfigFileBase(const ConfigFileBase &other);
210
211 ~ConfigFileBase();
212
213 void parseUUID(com::Guid &guid,
214 const com::Utf8Str &strUUID) const;
215 void parseTimestamp(RTTIMESPEC &timestamp,
216 const com::Utf8Str &str) const;
217
218 com::Utf8Str makeString(const RTTIMESPEC &tm);
219
220 void readExtraData(const xml::ElementNode &elmExtraData,
221 StringsMap &map);
222 void readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
223 USBDeviceFiltersList &ll);
224 typedef enum {Error, HardDisk, DVDImage, FloppyImage} MediaType;
225 void readMedium(MediaType t, const xml::ElementNode &elmMedium, MediaList &llMedia);
226 void readMediaRegistry(const xml::ElementNode &elmMediaRegistry, MediaRegistry &mr);
227 void readNATForwardRuleList(const xml::ElementNode &elmParent, NATRuleList &llRules);
228
229 void setVersionAttribute(xml::ElementNode &elm);
230 void createStubDocument();
231
232 void buildExtraData(xml::ElementNode &elmParent, const StringsMap &me);
233 void buildUSBDeviceFilters(xml::ElementNode &elmParent,
234 const USBDeviceFiltersList &ll,
235 bool fHostMode);
236 void buildMedium(xml::ElementNode &elmMedium,
237 DeviceType_T devType,
238 const Medium &m,
239 uint32_t level);
240 void buildMediaRegistry(xml::ElementNode &elmParent,
241 const MediaRegistry &mr);
242 void buildNATForwardRuleList(xml::ElementNode &elmParent, const NATRuleList &natRuleList);
243 void clearDocument();
244
245 struct Data;
246 Data *m;
247
248 friend class ConfigFileError;
249};
250
251////////////////////////////////////////////////////////////////////////////////
252//
253// VirtualBox.xml structures
254//
255////////////////////////////////////////////////////////////////////////////////
256
257struct Host
258{
259 USBDeviceFiltersList llUSBDeviceFilters;
260};
261
262struct SystemProperties
263{
264 SystemProperties()
265 : ulLogHistoryCount(3)
266 {}
267
268 com::Utf8Str strDefaultMachineFolder;
269 com::Utf8Str strDefaultHardDiskFolder;
270 com::Utf8Str strDefaultHardDiskFormat;
271 com::Utf8Str strVRDEAuthLibrary;
272 com::Utf8Str strWebServiceAuthLibrary;
273 com::Utf8Str strDefaultVRDEExtPack;
274 com::Utf8Str strAutostartDatabasePath;
275 com::Utf8Str strDefaultAdditionsISO;
276 com::Utf8Str strDefaultFrontend;
277 com::Utf8Str strLoggingLevel;
278 uint32_t ulLogHistoryCount;
279};
280
281struct MachineRegistryEntry
282{
283 com::Guid uuid;
284 com::Utf8Str strSettingsFile;
285};
286typedef std::list<MachineRegistryEntry> MachinesRegistry;
287
288typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap;
289typedef DhcpOptionMap::value_type DhcpOptValuePair;
290typedef DhcpOptionMap::iterator DhcpOptIterator;
291typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
292
293typedef struct VmNameSlotKey
294{
295 VmNameSlotKey(const com::Utf8Str& aVmName, LONG aSlot): VmName(aVmName),
296 Slot(aSlot){}
297 const com::Utf8Str VmName;
298 LONG Slot;
299 bool operator< (const VmNameSlotKey& that) const
300 {
301 if (VmName == that.VmName)
302 return Slot < that.Slot;
303 else return VmName < that.VmName;
304 }
305} VmNameSlotKey;
306typedef std::map<VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
307typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
308typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
309typedef VmSlot2OptionsMap::const_iterator VmSlot2OptionsConstIterator;
310
311struct DHCPServer
312{
313 DHCPServer()
314 : fEnabled(false)
315 {}
316
317 com::Utf8Str strNetworkName,
318 strIPAddress,
319 strIPLower,
320 strIPUpper;
321 bool fEnabled;
322 std::map<DhcpOpt_T, com::Utf8Str> GlobalDhcpOptions;
323 VmSlot2OptionsMap VmSlot2OptionsM;
324};
325typedef std::list<DHCPServer> DHCPServersList;
326
327
328/**
329 * Nat Networking settings (NAT service).
330 */
331struct NATNetwork
332{
333 com::Utf8Str strNetworkName;
334 bool fEnabled;
335 com::Utf8Str strNetwork;
336 bool fIPv6;
337 com::Utf8Str strIPv6Prefix;
338 bool fAdvertiseDefaultIPv6Route;
339 bool fNeedDhcpServer;
340 NATRuleList llPortForwardRules4;
341 NATRuleList llPortForwardRules6;
342 NATNetwork():fEnabled(false),
343 fAdvertiseDefaultIPv6Route(false),
344 fNeedDhcpServer(false)
345 {}
346 bool operator==(const NATNetwork &n) const
347 {
348 return strNetworkName == n.strNetworkName
349 && strNetwork == n.strNetwork;
350 }
351
352};
353typedef std::list<NATNetwork> NATNetworksList;
354
355
356class MainConfigFile : public ConfigFileBase
357{
358public:
359 MainConfigFile(const com::Utf8Str *pstrFilename);
360
361 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
362 void readDHCPServers(const xml::ElementNode &elmDHCPServers);
363 void readDhcpOptions(DhcpOptionMap& map, const xml::ElementNode& options);
364 void readNATNetworks(const xml::ElementNode &elmNATNetworks);
365
366 void write(const com::Utf8Str strFilename);
367
368 Host host;
369 SystemProperties systemProperties;
370 MediaRegistry mediaRegistry;
371 MachinesRegistry llMachines;
372 DHCPServersList llDhcpServers;
373 NATNetworksList llNATNetworks;
374 StringsMap mapExtraDataItems;
375};
376
377////////////////////////////////////////////////////////////////////////////////
378//
379// Machine XML structures
380//
381////////////////////////////////////////////////////////////////////////////////
382
383/**
384 * NOTE: If you add any fields in here, you must update a) the constructor and b)
385 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
386 * your settings might never get saved.
387 */
388struct VRDESettings
389{
390 VRDESettings()
391 : fEnabled(true),
392 authType(AuthType_Null),
393 ulAuthTimeout(5000),
394 fAllowMultiConnection(false),
395 fReuseSingleConnection(false)
396 {}
397
398 bool operator==(const VRDESettings& v) const;
399
400 bool fEnabled;
401 AuthType_T authType;
402 uint32_t ulAuthTimeout;
403 com::Utf8Str strAuthLibrary;
404 bool fAllowMultiConnection,
405 fReuseSingleConnection;
406 com::Utf8Str strVrdeExtPack;
407 StringsMap mapProperties;
408};
409
410/**
411 * NOTE: If you add any fields in here, you must update a) the constructor and b)
412 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
413 * your settings might never get saved.
414 */
415struct BIOSSettings
416{
417 BIOSSettings()
418 : fACPIEnabled(true),
419 fIOAPICEnabled(false),
420 fLogoFadeIn(true),
421 fLogoFadeOut(true),
422 ulLogoDisplayTime(0),
423 biosBootMenuMode(BIOSBootMenuMode_MessageAndMenu),
424 fPXEDebugEnabled(false),
425 llTimeOffset(0)
426 {}
427
428 bool operator==(const BIOSSettings &d) const;
429
430 bool fACPIEnabled,
431 fIOAPICEnabled,
432 fLogoFadeIn,
433 fLogoFadeOut;
434 uint32_t ulLogoDisplayTime;
435 com::Utf8Str strLogoImagePath;
436 BIOSBootMenuMode_T biosBootMenuMode;
437 bool fPXEDebugEnabled;
438 int64_t llTimeOffset;
439};
440
441/**
442 * NOTE: If you add any fields in here, you must update a) the constructor and b)
443 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
444 * your settings might never get saved.
445 */
446struct USBController
447{
448 USBController()
449 : fEnabled(false),
450 fEnabledEHCI(false)
451 {}
452
453 bool operator==(const USBController &u) const;
454
455 bool fEnabled;
456 bool fEnabledEHCI;
457 USBDeviceFiltersList llDeviceFilters;
458};
459
460 struct NAT
461 {
462 NAT()
463 : u32Mtu(0),
464 u32SockRcv(0),
465 u32SockSnd(0),
466 u32TcpRcv(0),
467 u32TcpSnd(0),
468 fDNSPassDomain(true), /* historically this value is true */
469 fDNSProxy(false),
470 fDNSUseHostResolver(false),
471 fAliasLog(false),
472 fAliasProxyOnly(false),
473 fAliasUseSamePorts(false)
474 {}
475
476 bool operator==(const NAT &n) const
477 {
478 return strNetwork == n.strNetwork
479 && strBindIP == n.strBindIP
480 && u32Mtu == n.u32Mtu
481 && u32SockRcv == n.u32SockRcv
482 && u32SockSnd == n.u32SockSnd
483 && u32TcpSnd == n.u32TcpSnd
484 && u32TcpRcv == n.u32TcpRcv
485 && strTFTPPrefix == n.strTFTPPrefix
486 && strTFTPBootFile == n.strTFTPBootFile
487 && strTFTPNextServer == n.strTFTPNextServer
488 && fDNSPassDomain == n.fDNSPassDomain
489 && fDNSProxy == n.fDNSProxy
490 && fDNSUseHostResolver == n.fDNSUseHostResolver
491 && fAliasLog == n.fAliasLog
492 && fAliasProxyOnly == n.fAliasProxyOnly
493 && fAliasUseSamePorts == n.fAliasUseSamePorts
494 && llRules == n.llRules;
495 }
496
497 com::Utf8Str strNetwork;
498 com::Utf8Str strBindIP;
499 uint32_t u32Mtu;
500 uint32_t u32SockRcv;
501 uint32_t u32SockSnd;
502 uint32_t u32TcpRcv;
503 uint32_t u32TcpSnd;
504 com::Utf8Str strTFTPPrefix;
505 com::Utf8Str strTFTPBootFile;
506 com::Utf8Str strTFTPNextServer;
507 bool fDNSPassDomain;
508 bool fDNSProxy;
509 bool fDNSUseHostResolver;
510 bool fAliasLog;
511 bool fAliasProxyOnly;
512 bool fAliasUseSamePorts;
513 NATRuleList llRules;
514 };
515
516/**
517 * NOTE: If you add any fields in here, you must update a) the constructor and b)
518 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
519 * your settings might never get saved.
520 */
521struct NetworkAdapter
522{
523 NetworkAdapter()
524 : ulSlot(0),
525 type(NetworkAdapterType_Am79C970A),
526 fEnabled(false),
527 fCableConnected(false),
528 ulLineSpeed(0),
529 enmPromiscModePolicy(NetworkAdapterPromiscModePolicy_Deny),
530 fTraceEnabled(false),
531 mode(NetworkAttachmentType_Null),
532 ulBootPriority(0)
533 {}
534
535 bool operator==(const NetworkAdapter &n) const;
536
537 uint32_t ulSlot;
538
539 NetworkAdapterType_T type;
540 bool fEnabled;
541 com::Utf8Str strMACAddress;
542 bool fCableConnected;
543 uint32_t ulLineSpeed;
544 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
545 bool fTraceEnabled;
546 com::Utf8Str strTraceFile;
547
548 NetworkAttachmentType_T mode;
549 NAT nat;
550 com::Utf8Str strBridgedName;
551 com::Utf8Str strHostOnlyName;
552 com::Utf8Str strInternalNetworkName;
553 com::Utf8Str strGenericDriver;
554 StringsMap genericProperties;
555 uint32_t ulBootPriority;
556 com::Utf8Str strBandwidthGroup; // requires settings version 1.13 (VirtualBox 4.2)
557};
558typedef std::list<NetworkAdapter> NetworkAdaptersList;
559
560/**
561 * NOTE: If you add any fields in here, you must update a) the constructor and b)
562 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
563 * your settings might never get saved.
564 */
565struct SerialPort
566{
567 SerialPort()
568 : ulSlot(0),
569 fEnabled(false),
570 ulIOBase(0x3f8),
571 ulIRQ(4),
572 portMode(PortMode_Disconnected),
573 fServer(false)
574 {}
575
576 bool operator==(const SerialPort &n) const;
577
578 uint32_t ulSlot;
579
580 bool fEnabled;
581 uint32_t ulIOBase;
582 uint32_t ulIRQ;
583 PortMode_T portMode;
584 com::Utf8Str strPath;
585 bool fServer;
586};
587typedef std::list<SerialPort> SerialPortsList;
588
589/**
590 * NOTE: If you add any fields in here, you must update a) the constructor and b)
591 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
592 * your settings might never get saved.
593 */
594struct ParallelPort
595{
596 ParallelPort()
597 : ulSlot(0),
598 fEnabled(false),
599 ulIOBase(0x378),
600 ulIRQ(7)
601 {}
602
603 bool operator==(const ParallelPort &d) const;
604
605 uint32_t ulSlot;
606
607 bool fEnabled;
608 uint32_t ulIOBase;
609 uint32_t ulIRQ;
610 com::Utf8Str strPath;
611};
612typedef std::list<ParallelPort> ParallelPortsList;
613
614/**
615 * NOTE: If you add any fields in here, you must update a) the constructor and b)
616 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
617 * your settings might never get saved.
618 */
619struct AudioAdapter
620{
621 AudioAdapter()
622 : fEnabled(true),
623 controllerType(AudioControllerType_AC97),
624 driverType(AudioDriverType_Null)
625 {}
626
627 bool operator==(const AudioAdapter &a) const
628 {
629 return (this == &a)
630 || ( (fEnabled == a.fEnabled)
631 && (controllerType == a.controllerType)
632 && (driverType == a.driverType)
633 );
634 }
635
636 bool fEnabled;
637 AudioControllerType_T controllerType;
638 AudioDriverType_T driverType;
639};
640
641/**
642 * NOTE: If you add any fields in here, you must update a) the constructor and b)
643 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
644 * your settings might never get saved.
645 */
646struct SharedFolder
647{
648 SharedFolder()
649 : fWritable(false)
650 , fAutoMount(false)
651 {}
652
653 bool operator==(const SharedFolder &a) const;
654
655 com::Utf8Str strName,
656 strHostPath;
657 bool fWritable;
658 bool fAutoMount;
659};
660typedef std::list<SharedFolder> SharedFoldersList;
661
662/**
663 * NOTE: If you add any fields in here, you must update a) the constructor and b)
664 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
665 * your settings might never get saved.
666 */
667struct GuestProperty
668{
669 GuestProperty()
670 : timestamp(0)
671 {};
672
673 bool operator==(const GuestProperty &g) const;
674
675 com::Utf8Str strName,
676 strValue;
677 uint64_t timestamp;
678 com::Utf8Str strFlags;
679};
680typedef std::list<GuestProperty> GuestPropertiesList;
681
682typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
683
684/**
685 * NOTE: If you add any fields in here, you must update a) the constructor and b)
686 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
687 * your settings might never get saved.
688 */
689struct CpuIdLeaf
690{
691 CpuIdLeaf()
692 : ulId(UINT32_MAX),
693 ulEax(0),
694 ulEbx(0),
695 ulEcx(0),
696 ulEdx(0)
697 {}
698
699 bool operator==(const CpuIdLeaf &c) const
700 {
701 return ( (this == &c)
702 || ( (ulId == c.ulId)
703 && (ulEax == c.ulEax)
704 && (ulEbx == c.ulEbx)
705 && (ulEcx == c.ulEcx)
706 && (ulEdx == c.ulEdx)
707 )
708 );
709 }
710
711 uint32_t ulId;
712 uint32_t ulEax;
713 uint32_t ulEbx;
714 uint32_t ulEcx;
715 uint32_t ulEdx;
716};
717typedef std::list<CpuIdLeaf> CpuIdLeafsList;
718
719/**
720 * NOTE: If you add any fields in here, you must update a) the constructor and b)
721 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
722 * your settings might never get saved.
723 */
724struct Cpu
725{
726 Cpu()
727 : ulId(UINT32_MAX)
728 {}
729
730 bool operator==(const Cpu &c) const
731 {
732 return (ulId == c.ulId);
733 }
734
735 uint32_t ulId;
736};
737typedef std::list<Cpu> CpuList;
738
739/**
740 * NOTE: If you add any fields in here, you must update a) the constructor and b)
741 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
742 * your settings might never get saved.
743 */
744struct BandwidthGroup
745{
746 BandwidthGroup()
747 : cMaxBytesPerSec(0),
748 enmType(BandwidthGroupType_Null)
749 {}
750
751 bool operator==(const BandwidthGroup &i) const
752 {
753 return ( (strName == i.strName)
754 && (cMaxBytesPerSec == i.cMaxBytesPerSec)
755 && (enmType == i.enmType));
756 }
757
758 com::Utf8Str strName;
759 uint64_t cMaxBytesPerSec;
760 BandwidthGroupType_T enmType;
761};
762typedef std::list<BandwidthGroup> BandwidthGroupList;
763
764/**
765 * NOTE: If you add any fields in here, you must update a) the constructor and b)
766 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
767 * your settings might never get saved.
768 */
769struct IOSettings
770{
771 IOSettings();
772
773 bool operator==(const IOSettings &i) const
774 {
775 return ( (fIOCacheEnabled == i.fIOCacheEnabled)
776 && (ulIOCacheSize == i.ulIOCacheSize)
777 && (llBandwidthGroups == i.llBandwidthGroups));
778 }
779
780 bool fIOCacheEnabled;
781 uint32_t ulIOCacheSize;
782 BandwidthGroupList llBandwidthGroups;
783};
784
785/**
786 * NOTE: If you add any fields in here, you must update a) the constructor and b)
787 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
788 * your settings might never get saved.
789 */
790struct HostPCIDeviceAttachment
791{
792 HostPCIDeviceAttachment()
793 : uHostAddress(0),
794 uGuestAddress(0)
795 {}
796
797 bool operator==(const HostPCIDeviceAttachment &a) const
798 {
799 return ( (uHostAddress == a.uHostAddress)
800 && (uGuestAddress == a.uGuestAddress)
801 && (strDeviceName == a.strDeviceName)
802 );
803 }
804
805 com::Utf8Str strDeviceName;
806 uint32_t uHostAddress;
807 uint32_t uGuestAddress;
808};
809typedef std::list<HostPCIDeviceAttachment> HostPCIDeviceAttachmentList;
810
811/**
812 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
813 * field.
814 *
815 * NOTE: If you add any fields in here, you must update a) the constructor and b)
816 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
817 * your settings might never get saved.
818 */
819struct Hardware
820{
821 Hardware();
822
823 bool operator==(const Hardware&) const;
824
825 com::Utf8Str strVersion; // hardware version, optional
826 com::Guid uuid; // hardware uuid, optional (null).
827
828 bool fHardwareVirt,
829 fHardwareVirtExclusive,
830 fNestedPaging,
831 fLargePages,
832 fVPID,
833 fUnrestrictedExecution,
834 fHardwareVirtForce,
835 fSyntheticCpu,
836 fPAE;
837 typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
838 LongModeType enmLongMode;
839 uint32_t cCPUs;
840 bool fCpuHotPlug; // requires settings version 1.10 (VirtualBox 3.2)
841 CpuList llCpus; // requires settings version 1.10 (VirtualBox 3.2)
842 bool fHPETEnabled; // requires settings version 1.10 (VirtualBox 3.2)
843 uint32_t ulCpuExecutionCap; // requires settings version 1.11 (VirtualBox 3.3)
844
845 CpuIdLeafsList llCpuIdLeafs;
846
847 uint32_t ulMemorySizeMB;
848
849 BootOrderMap mapBootOrder; // item 0 has highest priority
850
851 GraphicsControllerType_T graphicsControllerType;
852 uint32_t ulVRAMSizeMB;
853 uint32_t cMonitors;
854 bool fAccelerate3D,
855 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
856
857 uint32_t ulVideoCaptureHorzRes; // requires settings version 1.14 (VirtualBox 4.3)
858 uint32_t ulVideoCaptureVertRes; // requires settings version 1.14 (VirtualBox 4.3)
859 uint32_t ulVideoCaptureRate; // requires settings version 1.14 (VirtualBox 4.3)
860 uint32_t ulVideoCaptureFPS; // requires settings version 1.14 (VirtualBox 4.3)
861 bool fVideoCaptureEnabled; // requires settings version 1.14 (VirtualBox 4.3)
862 uint64_t u64VideoCaptureScreens; // requires settings version 1.14 (VirtualBox 4.3)
863 com::Utf8Str strVideoCaptureFile; // requires settings version 1.14 (VirtualBox 4.3)
864
865 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
866
867 PointingHIDType_T pointingHIDType; // requires settings version 1.10 (VirtualBox 3.2)
868 KeyboardHIDType_T keyboardHIDType; // requires settings version 1.10 (VirtualBox 3.2)
869
870 ChipsetType_T chipsetType; // requires settings version 1.11 (VirtualBox 4.0)
871
872 bool fEmulatedUSBWebcam; // 1.13 (VirtualBox 4.2)
873 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
874
875 VRDESettings vrdeSettings;
876
877 BIOSSettings biosSettings;
878 USBController usbController;
879 NetworkAdaptersList llNetworkAdapters;
880 SerialPortsList llSerialPorts;
881 ParallelPortsList llParallelPorts;
882 AudioAdapter audioAdapter;
883
884 // technically these two have no business in the hardware section, but for some
885 // clever reason <Hardware> is where they are in the XML....
886 SharedFoldersList llSharedFolders;
887 ClipboardMode_T clipboardMode;
888 DragAndDropMode_T dragAndDropMode;
889
890 uint32_t ulMemoryBalloonSize;
891 bool fPageFusionEnabled;
892
893 GuestPropertiesList llGuestProperties;
894 com::Utf8Str strNotificationPatterns;
895
896 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
897 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
898
899 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
900};
901
902/**
903 * A device attached to a storage controller. This can either be a
904 * hard disk or a DVD drive or a floppy drive and also specifies
905 * which medium is "in" the drive; as a result, this is a combination
906 * of the Main IMedium and IMediumAttachment interfaces.
907 *
908 * NOTE: If you add any fields in here, you must update a) the constructor and b)
909 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
910 * your settings might never get saved.
911 */
912struct AttachedDevice
913{
914 AttachedDevice()
915 : deviceType(DeviceType_Null),
916 fPassThrough(false),
917 fTempEject(false),
918 fNonRotational(false),
919 lPort(0),
920 lDevice(0)
921 {}
922
923 bool operator==(const AttachedDevice &a) const;
924
925 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
926
927 // DVDs can be in pass-through mode:
928 bool fPassThrough;
929
930 // Whether guest-triggered eject of DVDs will keep the medium in the
931 // VM config or not:
932 bool fTempEject;
933
934 // Whether the medium is non-rotational:
935 bool fNonRotational;
936
937 // Whether the medium supports discarding unused blocks:
938 bool fDiscard;
939
940 int32_t lPort;
941 int32_t lDevice;
942
943 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
944 // this is its UUID; it depends on deviceType which media registry this then needs to
945 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
946 com::Guid uuid;
947
948 // for DVDs and floppies, the attachment can also be a host device:
949 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
950
951 // Bandwidth group the device is attached to.
952 com::Utf8Str strBwGroup;
953};
954typedef std::list<AttachedDevice> AttachedDevicesList;
955
956/**
957 * NOTE: If you add any fields in here, you must update a) the constructor and b)
958 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
959 * your settings might never get saved.
960 */
961struct StorageController
962{
963 StorageController()
964 : storageBus(StorageBus_IDE),
965 controllerType(StorageControllerType_PIIX3),
966 ulPortCount(2),
967 ulInstance(0),
968 fUseHostIOCache(true),
969 fBootable(true),
970 lIDE0MasterEmulationPort(0),
971 lIDE0SlaveEmulationPort(0),
972 lIDE1MasterEmulationPort(0),
973 lIDE1SlaveEmulationPort(0)
974 {}
975
976 bool operator==(const StorageController &s) const;
977
978 com::Utf8Str strName;
979 StorageBus_T storageBus; // _SATA, _SCSI, _IDE, _SAS
980 StorageControllerType_T controllerType;
981 uint32_t ulPortCount;
982 uint32_t ulInstance;
983 bool fUseHostIOCache;
984 bool fBootable;
985
986 // only for when controllerType == StorageControllerType_IntelAhci:
987 int32_t lIDE0MasterEmulationPort,
988 lIDE0SlaveEmulationPort,
989 lIDE1MasterEmulationPort,
990 lIDE1SlaveEmulationPort;
991
992 AttachedDevicesList llAttachedDevices;
993};
994typedef std::list<StorageController> StorageControllersList;
995
996/**
997 * We wrap the storage controllers list into an extra struct so we can
998 * use an undefined struct without needing std::list<> in all the headers.
999 *
1000 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1001 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1002 * your settings might never get saved.
1003 */
1004struct Storage
1005{
1006 bool operator==(const Storage &s) const;
1007
1008 StorageControllersList llStorageControllers;
1009};
1010
1011/**
1012 * Settings that has to do with debugging.
1013 */
1014struct Debugging
1015{
1016 Debugging()
1017 : fTracingEnabled(false),
1018 fAllowTracingToAccessVM(false),
1019 strTracingConfig()
1020 { }
1021
1022 bool operator==(const Debugging &rOther) const
1023 {
1024 return fTracingEnabled == rOther.fTracingEnabled
1025 && fAllowTracingToAccessVM == rOther.fAllowTracingToAccessVM
1026 && strTracingConfig == rOther.strTracingConfig;
1027 }
1028
1029 bool areDefaultSettings() const
1030 {
1031 return !fTracingEnabled
1032 && !fAllowTracingToAccessVM
1033 && strTracingConfig.isEmpty();
1034 }
1035
1036 bool fTracingEnabled;
1037 bool fAllowTracingToAccessVM;
1038 com::Utf8Str strTracingConfig;
1039};
1040
1041/**
1042 * Settings that has to do with autostart.
1043 */
1044struct Autostart
1045{
1046 Autostart()
1047 : fAutostartEnabled(false),
1048 uAutostartDelay(0),
1049 enmAutostopType(AutostopType_Disabled)
1050 { }
1051
1052 bool operator==(const Autostart &rOther) const
1053 {
1054 return fAutostartEnabled == rOther.fAutostartEnabled
1055 && uAutostartDelay == rOther.uAutostartDelay
1056 && enmAutostopType == rOther.enmAutostopType;
1057 }
1058
1059 bool areDefaultSettings() const
1060 {
1061 return !fAutostartEnabled
1062 && !uAutostartDelay
1063 && enmAutostopType == AutostopType_Disabled;
1064 }
1065
1066 bool fAutostartEnabled;
1067 uint32_t uAutostartDelay;
1068 AutostopType_T enmAutostopType;
1069};
1070
1071struct Snapshot;
1072typedef std::list<Snapshot> SnapshotsList;
1073
1074/**
1075 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1076 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1077 * your settings might never get saved.
1078 */
1079struct Snapshot
1080{
1081 bool operator==(const Snapshot &s) const;
1082
1083 com::Guid uuid;
1084 com::Utf8Str strName,
1085 strDescription; // optional
1086 RTTIMESPEC timestamp;
1087
1088 com::Utf8Str strStateFile; // for online snapshots only
1089
1090 Hardware hardware;
1091 Storage storage;
1092
1093 Debugging debugging;
1094 Autostart autostart;
1095
1096 SnapshotsList llChildSnapshots;
1097};
1098
1099struct MachineUserData
1100{
1101 MachineUserData()
1102 : fDirectoryIncludesUUID(false),
1103 fNameSync(true),
1104 fTeleporterEnabled(false),
1105 uTeleporterPort(0),
1106 enmFaultToleranceState(FaultToleranceState_Inactive),
1107 uFaultTolerancePort(0),
1108 uFaultToleranceInterval(0),
1109 fRTCUseUTC(false)
1110 {
1111 llGroups.push_back("/");
1112 }
1113
1114 bool operator==(const MachineUserData &c) const
1115 {
1116 return (strName == c.strName)
1117 && (fDirectoryIncludesUUID == c.fDirectoryIncludesUUID)
1118 && (fNameSync == c.fNameSync)
1119 && (strDescription == c.strDescription)
1120 && (llGroups == c.llGroups)
1121 && (strOsType == c.strOsType)
1122 && (strSnapshotFolder == c.strSnapshotFolder)
1123 && (fTeleporterEnabled == c.fTeleporterEnabled)
1124 && (uTeleporterPort == c.uTeleporterPort)
1125 && (strTeleporterAddress == c.strTeleporterAddress)
1126 && (strTeleporterPassword == c.strTeleporterPassword)
1127 && (enmFaultToleranceState == c.enmFaultToleranceState)
1128 && (uFaultTolerancePort == c.uFaultTolerancePort)
1129 && (uFaultToleranceInterval == c.uFaultToleranceInterval)
1130 && (strFaultToleranceAddress == c.strFaultToleranceAddress)
1131 && (strFaultTolerancePassword == c.strFaultTolerancePassword)
1132 && (fRTCUseUTC == c.fRTCUseUTC)
1133 && (ovIcon == c.ovIcon);
1134 }
1135
1136 com::Utf8Str strName;
1137 bool fDirectoryIncludesUUID;
1138 bool fNameSync;
1139 com::Utf8Str strDescription;
1140 StringsList llGroups;
1141 com::Utf8Str strOsType;
1142 com::Utf8Str strSnapshotFolder;
1143 bool fTeleporterEnabled;
1144 uint32_t uTeleporterPort;
1145 com::Utf8Str strTeleporterAddress;
1146 com::Utf8Str strTeleporterPassword;
1147 FaultToleranceState_T enmFaultToleranceState;
1148 uint32_t uFaultTolerancePort;
1149 com::Utf8Str strFaultToleranceAddress;
1150 com::Utf8Str strFaultTolerancePassword;
1151 uint32_t uFaultToleranceInterval;
1152 bool fRTCUseUTC;
1153 com::Utf8Str ovIcon;
1154};
1155
1156/**
1157 * MachineConfigFile represents an XML machine configuration. All the machine settings
1158 * that go out to the XML (or are read from it) are in here.
1159 *
1160 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1161 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1162 * might never get saved.
1163 */
1164class MachineConfigFile : public ConfigFileBase
1165{
1166public:
1167 com::Guid uuid;
1168
1169 MachineUserData machineUserData;
1170
1171 com::Utf8Str strStateFile;
1172 bool fCurrentStateModified; // optional, default is true
1173 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1174 bool fAborted; // optional, default is false
1175
1176 com::Guid uuidCurrentSnapshot;
1177
1178 Hardware hardwareMachine;
1179 Storage storageMachine;
1180 MediaRegistry mediaRegistry;
1181 Debugging debugging;
1182 Autostart autostart;
1183
1184 StringsMap mapExtraDataItems;
1185
1186 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1187
1188 MachineConfigFile(const com::Utf8Str *pstrFilename);
1189
1190 bool operator==(const MachineConfigFile &m) const;
1191
1192 bool canHaveOwnMediaRegistry() const;
1193
1194 void importMachineXML(const xml::ElementNode &elmMachine);
1195
1196 void write(const com::Utf8Str &strFilename);
1197
1198 enum
1199 {
1200 BuildMachineXML_IncludeSnapshots = 0x01,
1201 BuildMachineXML_WriteVboxVersionAttribute = 0x02,
1202 BuildMachineXML_SkipRemovableMedia = 0x04,
1203 BuildMachineXML_MediaRegistry = 0x08,
1204 BuildMachineXML_SuppressSavedState = 0x10
1205 };
1206 void buildMachineXML(xml::ElementNode &elmMachine,
1207 uint32_t fl,
1208 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1209
1210 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1211 static AudioDriverType_T getHostDefaultAudioDriver();
1212
1213private:
1214 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1215 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1216 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1217 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1218 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1219 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1220 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1221 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1222 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1223 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw, Storage &strg);
1224 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1225 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1226 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1227 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1228 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1229 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1230 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1231 void readSnapshot(uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1232 void convertOldOSType_pre1_5(com::Utf8Str &str);
1233 void readMachine(const xml::ElementNode &elmMachine);
1234
1235 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg);
1236 void buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, bool fEnabled, const NetworkAdapter &nic);
1237 void buildStorageControllersXML(xml::ElementNode &elmParent,
1238 const Storage &st,
1239 bool fSkipRemovableMedia,
1240 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1241 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1242 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1243 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1244 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1245
1246 void bumpSettingsVersionIfNeeded();
1247};
1248
1249} // namespace settings
1250
1251
1252#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