server.cpp revision 058a831b4157c028dcb920c3898f1d4d426c2301
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * XPCOM server process start point
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * Copyright (C) 2006-2007 innotek GmbH
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * available from http://www.virtualbox.org. This file is free software;
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * General Public License as published by the Free Software Foundation,
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
430474e5ec398f769830a548d818d75ff37d5113vboxsync * If you received this file as part of a commercial VirtualBox
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * distribution, then only the terms of your commercial VirtualBox
430474e5ec398f769830a548d818d75ff37d5113vboxsync * license agreement apply instead of the previous paragraph.
459e93059a8be95d20eda3d1dad52187595a688cvboxsync// for nsMyFactory
459e93059a8be95d20eda3d1dad52187595a688cvboxsync// for the signal handler
459e93059a8be95d20eda3d1dad52187595a688cvboxsync// for the backtrace signal handler
58fd0712f38839a3228583267d39e0f20d41f36cvboxsync/////////////////////////////////////////////////////////////////////////////
58fd0712f38839a3228583267d39e0f20d41f36cvboxsync// VirtualBox component instantiation
58fd0712f38839a3228583267d39e0f20d41f36cvboxsync/////////////////////////////////////////////////////////////////////////////
459e93059a8be95d20eda3d1dad52187595a688cvboxsync// implement nsISupports parts of our objects with support for nsIClassInfo
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(VirtualBox, IVirtualBox)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS2_CI(SessionMachine, IMachine, IInternalMachineControl)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(SnapshotMachine, IMachine)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(Snapshot, ISnapshot)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(HardDisk, IHardDisk)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS2_CI(HVirtualDiskImage, IHardDisk, IVirtualDiskImage)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS2_CI(HISCSIHardDisk, IHardDisk, IISCSIHardDisk)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS2_CI(HVMDKImage, IHardDisk, IVMDKImage)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(HardDiskAttachment, IHardDiskAttachment)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(Progress, IProgress)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(CombinedProgress, IProgress)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(DVDDrive, IDVDDrive)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(FloppyDrive, IFloppyDrive)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(SharedFolder, ISharedFolder)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(VRDPServer, IVRDPServer)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(DVDImage, IDVDImage)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(FloppyImage, IFloppyImage)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(HostDVDDrive, IHostDVDDrive)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(HostFloppyDrive, IHostFloppyDrive)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(GuestOSType, IGuestOSType)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(NetworkAdapter, INetworkAdapter)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(SerialPort, ISerialPort)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(ParallelPort, IParallelPort)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(USBController, IUSBController)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(USBDeviceFilter, IUSBDeviceFilter)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS2_CI(HostUSBDevice, IUSBDevice, IHostUSBDevice)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(HostUSBDeviceFilter, IHostUSBDeviceFilter)
430474e5ec398f769830a548d818d75ff37d5113vboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(AudioAdapter, IAudioAdapter)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(SystemProperties, ISystemProperties)
430474e5ec398f769830a548d818d75ff37d5113vboxsyncNS_IMPL_THREADSAFE_ISUPPORTS1_CI(BIOSSettings, IBIOSSettings)
5638779fc90f0e0e702176680e16b1888ce23580vboxsync// collections and enumerators
f0057abac56417c558ea84f3a1c0995e73390152vboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION(HardDiskAttachment)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION(USBDeviceFilter)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION(HostFloppyDrive)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION(HostUSBDevice)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION(HostUSBDeviceFilter)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION_AS(Progress, IProgress)
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncCOM_IMPL_READONLY_ENUM_AND_COLLECTION_AS(IfaceUSBDevice, IUSBDevice)
459e93059a8be95d20eda3d1dad52187595a688cvboxsync////////////////////////////////////////////////////////////////////////////////
459e93059a8be95d20eda3d1dad52187595a688cvboxsync /* Delay before shutting down the VirtualBox server after the last
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * VirtualBox instance is released, in ms */
459e93059a8be95d20eda3d1dad52187595a688cvboxsyncstatic bool gAutoShutdown = false;
459e93059a8be95d20eda3d1dad52187595a688cvboxsync/////////////////////////////////////////////////////////////////////////////
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * Simple but smart PLEvent wrapper.
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * @note Instances must be always created with <tt>operator new</tt>!
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * Posts this event to the given message queue. This method may only be
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * called once. @note On success, the event will be deleted automatically
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * after it is delivered and handled. On failure, the event will delete
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * itself before this method returns! The caller must not delete it in
459e93059a8be95d20eda3d1dad52187595a688cvboxsync * either case.
459e93059a8be95d20eda3d1dad52187595a688cvboxsync delete this;
459e93059a8be95d20eda3d1dad52187595a688cvboxsync virtual void *handler() = 0;
459e93059a8be95d20eda3d1dad52187595a688cvboxsync static void *PR_CALLBACK eventHandler (PLEvent *self)
459e93059a8be95d20eda3d1dad52187595a688cvboxsync return reinterpret_cast <Ev *> (self)->that->handler();
459e93059a8be95d20eda3d1dad52187595a688cvboxsync static void PR_CALLBACK eventDestructor (PLEvent *self)
virtual ~VirtualBoxClassFactory()
FinalRelease();
sInstance = 0;
if (gEventQ)
if (!timerStarted)
if (!onMainThread)
return count;
void *handler()
if (count == 0)
if (gAutoShutdown)
return NULL;
return NS_ERROR_OUT_OF_MEMORY;
return NS_ERROR_FAILURE;
return NS_OK;
if (sInstance)
return NS_OK;
if (sInstance == 0)
if (sInstance)
return rv;
nsMyModuleComponentInfo () {}
nsMyModuleComponentInfo (int) {}
const char* aDescription,
const char* aContractID,
* The code below is stolen from nsGenericFactory.h / nsGenericFactory.cpp,
* starts up (somewhere during the initialization of the libipcdc.so module)
~nsMyFactory();
if (mInfo) {
return NS_ERROR_FACTORY_NOT_REGISTERED;
return NS_OK;
*countp = 0;
return NS_OK;
return NS_OK;
if (!*aContractID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
*aClassDescription = (char *)
if (!*aClassDescription)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
*aClassID =
if (! *aClassID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
return NS_OK;
return NS_OK;
return NS_OK;
return NS_OK;
return NS_OK;
delete factory;
return res;
return rv;
return rv;
static nsresult
factory);
return rc;
void *handler()
if (pszPidFile)
return NULL;
#if defined(USE_BACKTRACE)
* the code is taken from http://www.linuxjournal.com/article/6391.
int i, trace_size = 0;
exit (0);
bool fDaemonize = false;
gAutoShutdown = true;
fDaemonize = true;
fDaemonize = true;
#ifdef __OS2__
if (fDaemonize)
if (childpid != 0)
bool fSuccess = false;
fSuccess = true;
if (sid < 0)
#if defined(USE_BACKTRACE)
RTR3Init(false);
int iSize;
for (int i=iSize; i>0; i--)
#ifdef DEBUG
for (int i=iSize; i>0; i--)
if (fDaemonize)
#ifndef __OS2__
if (pszPidFile)
while (gKeepRunning)
if (pszPidFile)
if (fDaemonize)
#ifndef __OS2__