VirtualBoxImpl.h revision f5142bcd021af846b8085af6686d7c8067c9d185
2N/A/* $Id$ */
2N/A
2N/A/** @file
2N/A *
2N/A * VirtualBox COM class implementation
2N/A */
2N/A
2N/A/*
2N/A * Copyright (C) 2006-2010 Oracle Corporation
2N/A *
2N/A * This file is part of VirtualBox Open Source Edition (OSE), as
2N/A * available from http://www.virtualbox.org. This file is free software;
2N/A * you can redistribute it and/or modify it under the terms of the GNU
2N/A * General Public License (GPL) as published by the Free Software
2N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
2N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2N/A */
2N/A
2N/A#ifndef ____H_VIRTUALBOXIMPL
2N/A#define ____H_VIRTUALBOXIMPL
2N/A
2N/A#include "VirtualBoxBase.h"
2N/A
2N/A#ifdef RT_OS_WINDOWS
2N/A# include "win/resource.h"
2N/A#endif
2N/A
2N/Anamespace com
2N/A{
2N/A class Event;
2N/A class EventQueue;
2N/A}
2N/A
2N/Aclass SessionMachine;
2N/Aclass GuestOSType;
2N/Aclass SharedFolder;
2N/Aclass Progress;
2N/Aclass Host;
2N/Aclass SystemProperties;
2N/Aclass DHCPServer;
2N/Aclass PerformanceCollector;
2N/Aclass VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
2N/A
2N/Atypedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
2N/A
2N/A#ifdef RT_OS_WINDOWS
2N/Aclass SVCHlpClient;
2N/A#endif
2N/A
2N/Astruct VMClientWatcherData;
2N/A
2N/Anamespace settings
2N/A{
2N/A class MainConfigFile;
2N/A}
2N/A
2N/Aclass ATL_NO_VTABLE VirtualBox :
2N/A public VirtualBoxBase,
2N/A public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
2N/A public VirtualBoxSupportTranslation<VirtualBox>,
2N/A VBOX_SCRIPTABLE_IMPL(IVirtualBox)
2N/A#ifdef RT_OS_WINDOWS
2N/A , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
2N/A#endif
2N/A{
2N/A
2N/Apublic:
2N/A
2N/A typedef std::list< VirtualBoxCallbackRegistration > CallbackList;
2N/A typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
2N/A
2N/A class CallbackEvent;
2N/A friend class CallbackEvent;
2N/A
2N/A VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox)
2N/A
2N/A DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
2N/A
2N/A DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
2N/A DECLARE_NOT_AGGREGATABLE(VirtualBox)
2N/A
2N/A DECLARE_PROTECT_FINAL_CONSTRUCT()
2N/A
2N/A BEGIN_COM_MAP(VirtualBox)
2N/A COM_INTERFACE_ENTRY(IDispatch)
2N/A COM_INTERFACE_ENTRY(ISupportErrorInfo)
2N/A COM_INTERFACE_ENTRY(IVirtualBox)
2N/A END_COM_MAP()
2N/A
2N/A // to postpone generation of the default ctor/dtor
2N/A VirtualBox();
2N/A ~VirtualBox();
2N/A
2N/A HRESULT FinalConstruct();
2N/A void FinalRelease();
2N/A
2N/A /* public initializer/uninitializer for internal purposes only */
2N/A HRESULT init();
2N/A HRESULT initMachines();
2N/A HRESULT initMedia();
2N/A void uninit();
2N/A
2N/A /* IVirtualBox properties */
2N/A STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
2N/A STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
2N/A STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
2N/A STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
2N/A STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
2N/A STDMETHOD(COMGETTER(Host)) (IHost **aHost);
2N/A STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
2N/A STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
2N/A STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
2N/A STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
2N/A STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
2N/A STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
2N/A STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
2N/A STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
2N/A STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
2N/A STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
2N/A
2N/A /* IVirtualBox methods */
2N/A
2N/A STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
2N/A IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
2N/A STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
2N/A IN_BSTR aId, IMachine **aMachine);
2N/A STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
2N/A STDMETHOD(RegisterMachine) (IMachine *aMachine);
2N/A STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
2N/A STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
2N/A STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
2N/A STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
2N/A
2N/A STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
2N/A IMedium **aHardDisk);
2N/A STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
2N/A BOOL aSetImageId, IN_BSTR aImageId,
2N/A BOOL aSetParentId, IN_BSTR aParentId,
2N/A IMedium **aHardDisk);
2N/A STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
2N/A STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
2N/A
2N/A STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
2N/A IMedium **aDVDImage);
2N/A STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
2N/A STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
2N/A
2N/A STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
2N/A IMedium **aFloppyImage);
2N/A STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
2N/A STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
2N/A
2N/A STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
2N/A STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
2N/A STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
2N/A STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
2N/A STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
2N/A STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
2N/A STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
2N/A STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
2N/A IN_BSTR aType, IN_BSTR aEnvironment,
2N/A IProgress **aProgress);
2N/A STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
2N/A
2N/A STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
2N/A STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
2N/A
2N/A STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
2N/A BSTR *aChanged, BSTR *aValues);
2N/A
2N/A STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
2N/A STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
2N/A STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
2N/A STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
2N/A BSTR * aUrl, BSTR * aFile, BOOL * aResult);
2N/A
2N/A /* public methods only for internal purposes */
2N/A
2N/A /**
2N/A * Simple run-time type identification without having to enable C++ RTTI.
2N/A * The class IDs are defined in VirtualBoxBase.h.
2N/A * @return
2N/A */
2N/A virtual VBoxClsID getClassID() const
2N/A {
2N/A return clsidVirtualBox;
2N/A }
2N/A
2N/A /**
2N/A * Override of the default locking class to be used for validating lock
2N/A * order with the standard member lock handle.
2N/A */
2N/A virtual VBoxLockingClass getLockingClass() const
2N/A {
2N/A return LOCKCLASS_VIRTUALBOXOBJECT;
2N/A }
2N/A
2N/A#ifdef DEBUG
2N/A void dumpAllBackRefs();
2N/A#endif
2N/A
2N/A HRESULT postEvent(Event *event);
2N/A
2N/A HRESULT addProgress(IProgress *aProgress);
2N/A HRESULT removeProgress(IN_GUID aId);
2N/A
2N/A#ifdef RT_OS_WINDOWS
2N/A typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
2N/A (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
2N/A HRESULT startSVCHelperClient(bool aPrivileged,
2N/A SVCHelperClientFunc aFunc,
2N/A void *aUser, Progress *aProgress);
2N/A#endif
2N/A
2N/A void addProcessToReap (RTPROCESS pid);
2N/A void updateClientWatcher();
2N/A
2N/A void removeDeadCallback(const ComPtr<IVirtualBoxCallback> &aCallback);
2N/A
2N/A void onMachineStateChange(const Guid &aId, MachineState_T aState);
2N/A void onMachineDataChange(const Guid &aId);
2N/A BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
2N/A Bstr &aError);
2N/A void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
2N/A void onMachineRegistered(const Guid &aId, BOOL aRegistered);
2N/A void onSessionStateChange(const Guid &aId, SessionState_T aState);
2N/A
2N/A void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
2N/A void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
2N/A void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
2N/A void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
2N/A IN_BSTR aFlags);
2N/A
2N/A ComObjPtr<GuestOSType> getUnknownOSType();
2N/A
2N/A void getOpenedMachines(SessionMachinesList &aMachines,
2N/A InternalControlList *aControls = NULL);
2N/A
2N/A bool isMachineIdValid(const Guid &aId)
2N/A {
2N/A return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
2N/A }
2N/A
2N/A HRESULT findMachine (const Guid &aId, bool aSetError,
2N/A ComObjPtr<Machine> *machine = NULL);
2N/A
2N/A HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
2N/A bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
2N/A HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
2N/A bool aSetError, ComObjPtr<Medium> *aImage = NULL);
2N/A HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
2N/A bool aSetError, ComObjPtr<Medium> *aImage = NULL);
2N/A
2N/A HRESULT findGuestOSType(const Bstr &bstrOSType,
2N/A GuestOSType*& pGuestOSType);
2N/A
2N/A const ComObjPtr<Host>& host() const;
2N/A const ComObjPtr<SystemProperties>& systemProperties() const;
2N/A#ifdef VBOX_WITH_RESOURCE_USAGE_API
2N/A const ComObjPtr<PerformanceCollector>& performanceCollector() const;
2N/A#endif /* VBOX_WITH_RESOURCE_USAGE_API */
2N/A
2N/A const Utf8Str& getDefaultMachineFolder() const;
2N/A const Utf8Str& getDefaultHardDiskFolder() const;
2N/A const Utf8Str& getDefaultHardDiskFormat() const;
2N/A
2N/A /** Returns the VirtualBox home directory */
2N/A const Utf8Str& homeDir() const;
2N/A
2N/A int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
2N/A void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
2N/A
2N/A HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
2N/A HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
2N/A
2N/A HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
2N/A HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
2N/A
2N/A void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
2N/A const Utf8Str &strNewConfigDir);
2N/A
2N/A HRESULT saveSettings();
2N/A
2N/A static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
2N/A
2N/A static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
2N/A
const Utf8Str& settingsFilePath();
RWLockHandle& getMediaTreeLockHandle();
/* for VirtualBoxSupportErrorInfoImpl */
static const wchar_t *getComponentName() { return L"VirtualBox"; }
private:
HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
Utf8Str &aConflictType);
HRESULT registerMachine (Machine *aMachine);
HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
bool aSaveRegistry = true);
HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
bool aSaveRegistry = true);
struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
Data *m;
/* static variables (defined in VirtualBoxImpl.cpp) */
static Bstr sVersion;
static ULONG sRevision;
static Bstr sPackageType;
static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
#ifdef RT_OS_WINDOWS
static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
#endif
};
////////////////////////////////////////////////////////////////////////////////
#endif // !____H_VIRTUALBOXIMPL