HostPower.cpp revision 38b6aca02e74e058825195fb25e23c2bee6f45fa
/** @file
*
* VirtualBox interface to host's power notification service
*/
/*
* Copyright (C) 2006-2013 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "HostPower.h"
#include "Logging.h"
#include "VirtualBoxImpl.h"
#include "MachineImpl.h"
{
}
{
}
{
switch (aReason)
{
case Reason_HostSuspend:
{
LogFunc(("HOST SUSPEND\n"));
#ifdef VBOX_WITH_RESOURCE_USAGE_API
/* Suspend performance sampling to avoid unnecessary callbacks due to jumps in time. */
if (perfcollector)
#endif
/* pause running VMs */
++it)
{
/* PauseWithReason() will simply return a failure if
* the VM is in an inappropriate state */
continue;
/* save the control to un-pause the VM later */
}
break;
}
case Reason_HostResume:
{
LogFunc(("HOST RESUME\n"));
/* go through VMs we paused on Suspend */
{
/* note that Resume() will simply return a failure if the VM is
* in an inappropriate state (it will also fail if the VM has
* been somehow closed by this time already so that the
* console reference we have is dead) */
continue;
++resumed;
}
#ifdef VBOX_WITH_RESOURCE_USAGE_API
/* Resume the performance sampling. */
if (perfcollector)
#endif
break;
}
case Reason_HostBatteryLow:
{
LogFunc(("BATTERY LOW\n"));
value.asOutParam());
int fGlobal = 0;
{
if (value != "0")
fGlobal = 1;
else if (value == "0")
fGlobal = -1;
}
/* save running VMs */
{
value.asOutParam());
int fPerVM = 0;
{
/* per-VM overrides global */
if (value != "0")
fPerVM = 2;
else if (value == "0")
fPerVM = -2;
}
/* default is true */
{
/* note that SaveStateWithReason() will simply return a failure
* if the VM is in an inappropriate state */
{
continue;
}
/* Wait until the operation has been completed. */
{
}
{
++saved;
}
}
}
break;
}
default:
/* nothing */;
}
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */