summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/include/VirtualBoxImpl.h
blob: e75f11f032da9f48b8a2e8d81ad9628cde545cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/* $Id: VirtualBoxImpl.h $ */
/** @file
 * VirtualBox COM class implementation
 */

/*
 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef MAIN_INCLUDED_VirtualBoxImpl_h
#define MAIN_INCLUDED_VirtualBoxImpl_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <VBox/VBoxCryptoIf.h>

#include "VirtualBoxBase.h"
#include "objectslist.h"
#include "VirtualBoxWrap.h"

#ifdef RT_OS_WINDOWS
# include "win/resource.h"
#endif

//#ifdef DEBUG_bird
//# define VBOXSVC_WITH_CLIENT_WATCHER
//#endif

namespace com
{
    class Event;
    class EventQueue;
}

class SessionMachine;
class GuestOSType;
class Progress;
class Host;
class SystemProperties;
class DHCPServer;
class PerformanceCollector;
class CloudProviderManager;
#ifdef VBOX_WITH_EXTPACK
class ExtPackManager;
#endif
class AutostartDb;
class NATNetwork;
#ifdef VBOX_WITH_CLOUD_NET
class CloudNetwork;
#endif /* VBOX_WITH_CLOUD_NET */


typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;

#ifdef RT_OS_WINDOWS
class SVCHlpClient;
#endif

namespace settings
{
    class MainConfigFile;
    struct MediaRegistry;
}


#if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_XPCOM)
class VirtualBoxClassFactory; /* See ../src-server/win/svcmain.cpp  */
#endif

class ATL_NO_VTABLE VirtualBox :
    public VirtualBoxWrap
#ifdef RT_OS_WINDOWS
     , public ATL::CComCoClass<VirtualBox, &CLSID_VirtualBox>
#endif
{

public:

    typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
    typedef ObjectsList<Machine> MachinesOList;

#if 0 /* obsoleted by AsyncEvent */
    class CallbackEvent;
    friend class CallbackEvent;
#endif
    class AsyncEvent;
    friend class AsyncEvent;

#ifndef VBOX_WITH_XPCOM
# ifdef VBOX_WITH_SDS
    DECLARE_CLASSFACTORY_EX(VirtualBoxClassFactory)
# else
    DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
# endif
#endif

    // Do not use any ATL registry support.
    //DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)

    // Kind of redundant (VirtualBoxWrap declares itself not aggregatable and
    // CComCoClass<VirtualBox, &CLSID_VirtualBox> as aggregatable, the former
    // is the first inheritance), but the C++ multiple inheritance rules and
    // the class factory in svcmain.cpp needs this to disambiguate.
    DECLARE_NOT_AGGREGATABLE(VirtualBox)

    // to postpone generation of the default ctor/dtor
    DECLARE_COMMON_CLASS_METHODS(VirtualBox)

    HRESULT FinalConstruct();
    void FinalRelease();

    // public initializer/uninitializer for internal purposes only
    HRESULT init();
    HRESULT initMachines();
    HRESULT initMedia(const Guid &uuidMachineRegistry,
                      const settings::MediaRegistry &mediaRegistry,
                      const Utf8Str &strMachineFolder);
    void uninit();

    // public methods only for internal purposes

    /**
     * Override of the default locking class to be used for validating lock
     * order with the standard member lock handle.
     */
    virtual VBoxLockingClass getLockingClass() const
    {
        return LOCKCLASS_VIRTUALBOXOBJECT;
    }

#ifdef DEBUG
    void i_dumpAllBackRefs();
#endif

    HRESULT i_postEvent(Event *event);

    HRESULT i_addProgress(IProgress *aProgress);
    HRESULT i_removeProgress(IN_GUID aId);

#ifdef RT_OS_WINDOWS
    typedef HRESULT (*PFN_SVC_HELPER_CLIENT_T)(SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
    HRESULT i_startSVCHelperClient(bool aPrivileged,
                                   PFN_SVC_HELPER_CLIENT_T aFunc,
                                   void *aUser, Progress *aProgress);
#endif

    void i_addProcessToReap(RTPROCESS pid);
    void i_updateClientWatcher();

    int i_loadVDPlugin(const char *pszPluginLibrary);
    int i_unloadVDPlugin(const char *pszPluginLibrary);

    void i_onMediumRegistered(const Guid &aMediumId, const DeviceType_T aDevType, BOOL aRegistered);
    void i_onMediumConfigChanged(IMedium *aMedium);
    void i_onMediumChanged(IMediumAttachment* aMediumAttachment);
    void i_onStorageControllerChanged(const Guid &aMachineId, const com::Utf8Str &aControllerName);
    void i_onStorageDeviceChanged(IMediumAttachment* aStorageDevice, BOOL fRemoved, BOOL fSilent);
    void i_onMachineStateChanged(const Guid &aId, MachineState_T aState);
    void i_onMachineDataChanged(const Guid &aId, BOOL aTemporary = FALSE);
    void i_onMachineGroupsChanged(const Guid &aId);
    BOOL i_onExtraDataCanChange(const Guid &aId, const Utf8Str &aKey, const Utf8Str &aValue, Bstr &aError);
    void i_onExtraDataChanged(const Guid &aId, const Utf8Str &aKey, const Utf8Str &aValue);
    void i_onMachineRegistered(const Guid &aId, BOOL aRegistered);
    void i_onSessionStateChanged(const Guid &aId, SessionState_T aState);

    void i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
    void i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
    void i_onSnapshotRestored(const Guid &aMachineId, const Guid &aSnapshotId);
    void i_onSnapshotChanged(const Guid &aMachineId, const Guid &aSnapshotId);

    void i_onGuestPropertyChanged(const Guid &aMachineId, const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags,
                                  const BOOL fWasDeleted);
    void i_onNatRedirectChanged(const Guid &aMachineId, ULONG ulSlot, bool fRemove, const Utf8Str &aName,
                                NATProtocol_T aProto, const Utf8Str &aHostIp, uint16_t aHostPort,
                                const Utf8Str &aGuestIp, uint16_t aGuestPort);
    void i_onNATNetworkChanged(const Utf8Str &aNetworkName);
    void i_onNATNetworkStartStop(const Utf8Str &aNetworkName, BOOL aStart);
    void i_onNATNetworkSetting(const Utf8Str &aNetworkName, BOOL aEnabled, const Utf8Str &aNetwork,
                               const Utf8Str &aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
                               BOOL fNeedDhcpServer);
    void i_onNATNetworkPortForward(const Utf8Str &aNetworkName, BOOL create, BOOL fIpv6,
                                   const Utf8Str &aRuleName, NATProtocol_T proto,
                                   const Utf8Str &aHostIp, LONG aHostPort,
                                   const Utf8Str &aGuestIp, LONG aGuestPort);
    void i_onHostNameResolutionConfigurationChange();

    int i_natNetworkRefInc(const Utf8Str &aNetworkName);
    int i_natNetworkRefDec(const Utf8Str &aNetworkName);

    RWLockHandle *i_getNatNetLock() const;
    bool i_isNatNetStarted(const Utf8Str &aNetworkName) const;

    void i_onCloudProviderListChanged(BOOL aRegistered);
    void i_onCloudProviderRegistered(const Utf8Str &aProviderId, BOOL aRegistered);
    void i_onCloudProviderUninstall(const Utf8Str &aProviderId);

    void i_onProgressCreated(const Guid &aId, BOOL aCreated);

    void i_onLanguageChanged(const Utf8Str &aLanguageId);

#ifdef VBOX_WITH_UPDATE_AGENT
    void i_onUpdateAgentAvailable(IUpdateAgent *aAgent,
                                  const Utf8Str &aVer, UpdateChannel_T aChannel, UpdateSeverity_T aSev,
                                  const Utf8Str &aDownloadURL, const Utf8Str &aWebURL, const Utf8Str &aReleaseNotes);
    void i_onUpdateAgentError(IUpdateAgent *aAgent, const Utf8Str &aErrMsg, LONG aRc);
    void i_onUpdateAgentStateChanged(IUpdateAgent *aAgent, UpdateState_T aState);
    void i_onUpdateAgentSettingsChanged(IUpdateAgent *aAgent, const Utf8Str &aAttributeHint);
#endif /* VBOX_WITH_UPDATE_AGENT */

#ifdef VBOX_WITH_CLOUD_NET
    HRESULT i_findCloudNetworkByName(const com::Utf8Str &aNetworkName,
                                     ComObjPtr<CloudNetwork> *aNetwork = NULL);
    HRESULT i_getEventSource(ComPtr<IEventSource>& aSource);
#endif /* VBOX_WITH_CLOUD_NET */

    ComObjPtr<GuestOSType> i_getUnknownOSType();

    void i_getOpenedMachines(SessionMachinesList &aMachines,
                           InternalControlList *aControls = NULL);
    MachinesOList &i_getMachinesList();

    HRESULT i_findMachine(const Guid &aId,
                          bool fPermitInaccessible,
                          bool aSetError,
                          ComObjPtr<Machine> *aMachine = NULL);

    HRESULT i_findMachineByName(const Utf8Str &aName,
                                bool aSetError,
                                ComObjPtr<Machine> *aMachine = NULL);

    HRESULT i_validateMachineGroup(const com::Utf8Str &aGroup, bool fPrimary);
    HRESULT i_convertMachineGroups(const std::vector<com::Utf8Str> aMachineGroups, StringsList *pllMachineGroups);

    HRESULT i_findHardDiskById(const Guid &id,
                               bool aSetError,
                               ComObjPtr<Medium> *aHardDisk = NULL);
    HRESULT i_findHardDiskByLocation(const Utf8Str &strLocation,
                                     bool aSetError,
                                     ComObjPtr<Medium> *aHardDisk = NULL);
    HRESULT i_findDVDOrFloppyImage(DeviceType_T mediumType,
                                   const Guid *aId,
                                   const Utf8Str &aLocation,
                                   bool aSetError,
                                   ComObjPtr<Medium> *aImage = NULL);
    HRESULT i_findRemoveableMedium(DeviceType_T mediumType,
                                   const Guid &uuid,
                                   bool fRefresh,
                                   bool aSetError,
                                   ComObjPtr<Medium> &pMedium);

    HRESULT i_findGuestOSType(const Utf8Str &strOSType,
                              ComObjPtr<GuestOSType> &guestOSType);

    const Guid &i_getGlobalRegistryId() const;

    const ComObjPtr<Host> &i_host() const;
    SystemProperties *i_getSystemProperties() const;
    CloudProviderManager *i_getCloudProviderManager() const;
#ifdef VBOX_WITH_EXTPACK
    ExtPackManager *i_getExtPackManager() const;
#endif
#ifdef VBOX_WITH_RESOURCE_USAGE_API
    const ComObjPtr<PerformanceCollector> &i_performanceCollector() const;
#endif /* VBOX_WITH_RESOURCE_USAGE_API */

    void i_getDefaultMachineFolder(Utf8Str &str) const;
    void i_getDefaultHardDiskFormat(Utf8Str &str) const;

    /** Returns the VirtualBox home directory */
    const Utf8Str &i_homeDir() const;
    int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
    void i_copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
    HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium,
                             AutoWriteLock &mediaTreeLock, bool fCalledFromMediumInit = false);
    HRESULT i_unregisterMedium(Medium *pMedium);
    HRESULT i_unregisterMachineMedia(const Guid &id);
    HRESULT i_unregisterMachine(Machine *pMachine, CleanupMode_T aCleanupMode, const Guid &id);
    void i_rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
                                             const Utf8Str &strNewConfigDir);
    void i_saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
                             const Guid &uuidRegistry,
                             const Utf8Str &strMachineFolder);
    HRESULT i_saveSettings();
    void i_markRegistryModified(const Guid &uuid);
    void i_unmarkRegistryModified(const Guid &uuid);
    void i_saveModifiedRegistries();
    static const com::Utf8Str &i_getVersionNormalized();
    static HRESULT i_ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
    const Utf8Str& i_settingsFilePath();
    AutostartDb* i_getAutostartDb() const;
    RWLockHandle& i_getMachinesListLockHandle();
    RWLockHandle& i_getMediaTreeLockHandle();
    int  i_encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
    int  i_decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
    void i_storeSettingsKey(const Utf8Str &aKey);
    bool i_isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
    HRESULT i_retainCryptoIf(PCVBOXCRYPTOIF *ppCryptoIf);
    HRESULT i_releaseCryptoIf(PCVBOXCRYPTOIF pCryptoIf);
    HRESULT i_unloadCryptoIfModule(void);



private:
    class ClientWatcher;

    // wrapped IVirtualBox properties
    HRESULT getVersion(com::Utf8Str &aVersion);
    HRESULT getVersionNormalized(com::Utf8Str &aVersionNormalized);
    HRESULT getRevision(ULONG *aRevision);
    HRESULT getPackageType(com::Utf8Str &aPackageType);
    HRESULT getAPIVersion(com::Utf8Str &aAPIVersion);
    HRESULT getAPIRevision(LONG64 *aAPIRevision);
    HRESULT getHomeFolder(com::Utf8Str &aHomeFolder);
    HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
    HRESULT getHost(ComPtr<IHost> &aHost);
    HRESULT getSystemProperties(ComPtr<ISystemProperties> &aSystemProperties);
    HRESULT getMachines(std::vector<ComPtr<IMachine> > &aMachines);
    HRESULT getMachineGroups(std::vector<com::Utf8Str> &aMachineGroups);
    HRESULT getHardDisks(std::vector<ComPtr<IMedium> > &aHardDisks);
    HRESULT getDVDImages(std::vector<ComPtr<IMedium> > &aDVDImages);
    HRESULT getFloppyImages(std::vector<ComPtr<IMedium> > &aFloppyImages);
    HRESULT getProgressOperations(std::vector<ComPtr<IProgress> > &aProgressOperations);
    HRESULT getGuestOSTypes(std::vector<ComPtr<IGuestOSType> > &aGuestOSTypes);
    HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
    HRESULT getPerformanceCollector(ComPtr<IPerformanceCollector> &aPerformanceCollector);
    HRESULT getDHCPServers(std::vector<ComPtr<IDHCPServer> > &aDHCPServers);
    HRESULT getNATNetworks(std::vector<ComPtr<INATNetwork> > &aNATNetworks);
    HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
    HRESULT getExtensionPackManager(ComPtr<IExtPackManager> &aExtensionPackManager);
    HRESULT getHostOnlyNetworks(std::vector<ComPtr<IHostOnlyNetwork> > &aHostOnlyNetworks);
    HRESULT getInternalNetworks(std::vector<com::Utf8Str> &aInternalNetworks);
    HRESULT getGenericNetworkDrivers(std::vector<com::Utf8Str> &aGenericNetworkDrivers);
    HRESULT getCloudNetworks(std::vector<ComPtr<ICloudNetwork> > &aCloudNetworks);
    HRESULT getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager);

   // wrapped IVirtualBox methods
    HRESULT composeMachineFilename(const com::Utf8Str &aName,
                                   const com::Utf8Str &aGroup,
                                   const com::Utf8Str &aCreateFlags,
                                   const com::Utf8Str &aBaseFolder,
                                   com::Utf8Str &aFile);
    HRESULT createMachine(const com::Utf8Str &aSettingsFile,
                          const com::Utf8Str &aName,
                          const std::vector<com::Utf8Str> &aGroups,
                          const com::Utf8Str &aOsTypeId,
                          const com::Utf8Str &aFlags,
                          const com::Utf8Str &aCipher,
                          const com::Utf8Str &aPasswordId,
                          const com::Utf8Str &aPassword,
                          ComPtr<IMachine> &aMachine);
    HRESULT openMachine(const com::Utf8Str &aSettingsFile,
                        const com::Utf8Str &aPassword,
                        ComPtr<IMachine> &aMachine);
    HRESULT registerMachine(const ComPtr<IMachine> &aMachine);
    HRESULT findMachine(const com::Utf8Str &aNameOrId,
                        ComPtr<IMachine> &aMachine);
    HRESULT getMachinesByGroups(const std::vector<com::Utf8Str> &aGroups,
                                std::vector<ComPtr<IMachine> > &aMachines);
    HRESULT getMachineStates(const std::vector<ComPtr<IMachine> > &aMachines,
                             std::vector<MachineState_T> &aStates);
    HRESULT createAppliance(ComPtr<IAppliance> &aAppliance);
    HRESULT createUnattendedInstaller(ComPtr<IUnattended> &aUnattended);
    HRESULT createMedium(const com::Utf8Str &aFormat,
                         const com::Utf8Str &aLocation,
                         AccessMode_T aAccessMode,
                         DeviceType_T aDeviceType,
                         ComPtr<IMedium> &aMedium);
    HRESULT openMedium(const com::Utf8Str &aLocation,
                       DeviceType_T aDeviceType,
                       AccessMode_T aAccessMode,
                       BOOL aForceNewUuid,
                       ComPtr<IMedium> &aMedium);
    HRESULT getGuestOSType(const com::Utf8Str &aId,
                           ComPtr<IGuestOSType> &aType);
    HRESULT createSharedFolder(const com::Utf8Str &aName,
                               const com::Utf8Str &aHostPath,
                               BOOL aWritable,
                               BOOL aAutomount,
                               const com::Utf8Str &aAutoMountPoint);
    HRESULT removeSharedFolder(const com::Utf8Str &aName);
    HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
    HRESULT getExtraData(const com::Utf8Str &aKey,
                         com::Utf8Str &aValue);
    HRESULT setExtraData(const com::Utf8Str &aKey,
                         const com::Utf8Str &aValue);
    HRESULT setSettingsSecret(const com::Utf8Str &aPassword);
    HRESULT createDHCPServer(const com::Utf8Str &aName,
                             ComPtr<IDHCPServer> &aServer);
    HRESULT findDHCPServerByNetworkName(const com::Utf8Str &aName,
                                        ComPtr<IDHCPServer> &aServer);
    HRESULT removeDHCPServer(const ComPtr<IDHCPServer> &aServer);
    HRESULT createNATNetwork(const com::Utf8Str &aNetworkName,
                             ComPtr<INATNetwork> &aNetwork);
    HRESULT findNATNetworkByName(const com::Utf8Str &aNetworkName,
                                 ComPtr<INATNetwork> &aNetwork);
    HRESULT removeNATNetwork(const ComPtr<INATNetwork> &aNetwork);
    HRESULT createHostOnlyNetwork(const com::Utf8Str &aNetworkName,
                                  ComPtr<IHostOnlyNetwork> &aNetwork);
    HRESULT findHostOnlyNetworkByName(const com::Utf8Str &aNetworkName,
                                     ComPtr<IHostOnlyNetwork> &aNetwork);
    HRESULT findHostOnlyNetworkById(const com::Guid &aId,
                                   ComPtr<IHostOnlyNetwork> &aNetwork);
    HRESULT removeHostOnlyNetwork(const ComPtr<IHostOnlyNetwork> &aNetwork);
    HRESULT createCloudNetwork(const com::Utf8Str &aNetworkName,
                               ComPtr<ICloudNetwork> &aNetwork);
    HRESULT findCloudNetworkByName(const com::Utf8Str &aNetworkName,
                                   ComPtr<ICloudNetwork> &aNetwork);
    HRESULT removeCloudNetwork(const ComPtr<ICloudNetwork> &aNetwork);
    HRESULT checkFirmwarePresent(FirmwareType_T aFirmwareType,
                                 const com::Utf8Str &aVersion,
                                 com::Utf8Str &aUrl,
                                 com::Utf8Str &aFile,
                                 BOOL *aResult);
    HRESULT findProgressById(const com::Guid &aId,
                             ComPtr<IProgress> &aProgressObject);

    static HRESULT i_setErrorStaticBoth(HRESULT aResultCode, int vrc, const char *aText, ...)
    {
        va_list va;
        va_start (va, aText);
        HRESULT hrc = setErrorInternalV(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, va, false, true, vrc);
        va_end(va);
        return hrc;
    }

    HRESULT i_registerMachine(Machine *aMachine);
    HRESULT i_registerDHCPServer(DHCPServer *aDHCPServer,
                                 bool aSaveRegistry = true);
    HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer);
    HRESULT i_registerNATNetwork(NATNetwork *aNATNetwork,
                                 bool aSaveRegistry = true);
    HRESULT i_unregisterNATNetwork(NATNetwork *aNATNetwork,
                                   bool aSaveRegistry = true);
    HRESULT i_checkMediaForConflicts(const Guid &aId,
                                     const Utf8Str &aLocation,
                                     Utf8Str &aConflictType,
                                     ComObjPtr<Medium> *pDupMedium);
    int  i_decryptSettings();
    int  i_decryptMediumSettings(Medium *pMedium);
    int  i_decryptSettingBytes(uint8_t *aPlaintext,
                               const uint8_t *aCiphertext,
                               size_t aCiphertextSize) const;
    int  i_encryptSettingBytes(const uint8_t *aPlaintext,
                               uint8_t *aCiphertext,
                               size_t aPlaintextSize,
                               size_t aCiphertextSize) const;
    void i_reportDriverVersions(void);

    struct Data;            // opaque data structure, defined in VirtualBoxImpl.cpp

    Data *m;

    /* static variables (defined in VirtualBoxImpl.cpp) */
    static com::Utf8Str sVersion;
    static com::Utf8Str sVersionNormalized;
    static ULONG sRevision;
    static com::Utf8Str sPackageType;
    static com::Utf8Str sAPIVersion;
    static std::map<com::Utf8Str, int> sNatNetworkNameToRefCount;
    static RWLockHandle* spMtxNatNetworkNameToRefCountLock;

    static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);

#ifdef RT_OS_WINDOWS
    friend class StartSVCHelperClientData;
    static void i_SVCHelperClientThreadTask(StartSVCHelperClientData *pTask);
#endif

#if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER)
protected:
    void i_callHook(const char *a_pszFunction) RT_OVERRIDE;
    bool i_watchClientProcess(RTPROCESS a_pidClient, const char *a_pszFunction);
public:
    static void i_logCaller(const char *a_pszFormat, ...);
private:

#endif
};

////////////////////////////////////////////////////////////////////////////////

#endif /* !MAIN_INCLUDED_VirtualBoxImpl_h */