VBoxServiceBalloon.cpp revision 2dbca53b2c122d346cb55db24009d1b1e31e1539
/* $Id: $ */
/** @file
* VBoxMemBalloon - Memory balloon notification.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include <iprt/semaphore.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static uint32_t g_MemBalloonSize = 0;
/** The semaphore we're blocking on. */
/** @copydoc VBOXSERVICE::pfnPreInit */
static DECLCALLBACK(int) VBoxServiceBalloonPreInit(void)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnOption */
static DECLCALLBACK(int) VBoxServiceBalloonOption(const char **ppszShort, int argc, char **argv, int *pi)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnInit */
static DECLCALLBACK(int) VBoxServiceBalloonInit(void)
{
g_MemBalloonSize = 0;
/* Check balloon size */
if (RT_SUCCESS(rc))
else
return rc;
}
{
return g_MemBalloonSize;
}
/** @copydoc VBOXSERVICE::pfnWorker */
{
int rc = VINF_SUCCESS;
/* Start monitoring of the stat event change event. */
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Tell the control thread that it can continue
* spawning services.
*/
/*
* Now enter the loop retrieving runtime data continuously.
*/
for (;;)
{
/* Check if an update interval change is pending. */
if ( RT_SUCCESS(rc)
{
if (RT_SUCCESS(rc))
else
}
/*
* Block for a while.
*
* The event semaphore takes care of ignoring interruptions and it
* allows us to implement service wakeup later.
*/
if (*pfShutdown)
break;
if (*pfShutdown)
break;
{
break;
}
}
/* Cancel monitoring of the memory balloon change event. */
if (RT_FAILURE(rc))
return 0;
}
/** @copydoc VBOXSERVICE::pfnTerm */
static DECLCALLBACK(void) VBoxServiceBalloonTerm(void)
{
return;
}
/** @copydoc VBOXSERVICE::pfnStop */
static DECLCALLBACK(void) VBoxServiceBalloonStop(void)
{
}
/**
* The 'memballoon' service description.
*/
{
/* pszName. */
"memballoon",
/* pszDescription. */
"Memory Ballooning",
/* pszUsage. */
NULL,
/* pszOptions. */
NULL,
/* methods */
};