VirtualBoxClientImpl.cpp revision 1d4505464a0a7d7d91227d55871ca7a0ab65aeb5
/* $Id$ */
/** @file
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "VirtualBoxClientImpl.h"
#include "AutoCaller.h"
#include "VBoxEvents.h"
#include "Logging.h"
#include <iprt/critsect.h>
#include <iprt/semaphore.h>
/** Waiting time between probing whether VBoxSVC is alive. */
#define VBOXCLIENT_DEFAULT_INTERVAL 30000
/** Initialize instance counter class variable */
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return init();
}
void VirtualBoxClient::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the VirtualBoxClient object.
*
* @returns COM result indicator
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Setting up the VBoxSVC watcher thread. If anything goes wrong here it
* is not considered important enough to cause any sort of visible
* failure. The monitoring will not be done, but that's all. */
if (RT_SUCCESS(vrc))
{
this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
RTTHREADFLAGS_WAITABLE, "VBoxSVCWatcher");
}
else
{
}
/* Confirm a successful initialization */
return rc;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void VirtualBoxClient::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
{
/* Signal the event semaphore and wait for the thread to terminate.
* if it hangs for some reason exit anyway, this can cause a crash
* though as the object will no longer be available. */
}
}
// IVirtualBoxClient properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns a reference to the VirtualBox object.
*
* @returns COM status code
* @param aVirtualBox Address of result variable.
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Create a new Session object and return a reference to it.
*
* @returns COM status code
* @param aSession Address of result variable.
*/
{
AutoCaller autoCaller(this);
/* this is not stored in this object, no need to lock */
return rc;
}
/**
* Return reference to the EventSource associated with this object.
*
* @returns COM status code
* @param aEventSource Address of result variable.
*/
{
AutoCaller autoCaller(this);
/* this is const, no need to lock */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/*static*/
void *pvUser)
{
int vrc;
/* The likelihood of early crashes are high, so start with a short wait. */
/* As long as the waiting times out keep retrying the wait. */
while (RT_FAILURE(vrc))
{
{
{
}
{
if (FAILED_DEAD_INTERFACE(rc))
{
{
/* Throw away the VirtualBox reference, it's no longer
* usable as VBoxSVC terminated in the mean time. */
}
}
}
else
{
/* Try to get a new VirtualBox reference straight away, and if
* this fails use an increased waiting time as very frequent
* restart attempts in some wedged config can cause high CPU
* and disk load. */
else
{
{
/* Update the VirtualBox reference, there's a working
* VBoxSVC again from now on. */
}
}
}
}
}
return 0;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */