HostPowerWin.cpp revision eb9e46b094d74ec950d80be5fabe6b0fe4152d4f
/** @file
*
* VirtualBox interface to host's power notification service
*/
/*
* Copyright (C) 2006-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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <windows.h>
/* Some SDK versions lack the extern "C" and thus cause linking failures.
* This workaround isn't pretty, but there are not many options. */
extern "C" {
#include <PowrProf.h>
}
#include "HostPower.h"
#include "Logging.h"
HostPowerServiceWin::HostPowerServiceWin(VirtualBox *aVirtualBox) : HostPowerService(aVirtualBox), mThread(NIL_RTTHREAD)
{
mHwnd = 0;
if (RT_FAILURE(rc))
{
return;
}
}
{
if (mHwnd)
{
/* Is this allowed from another thread? */
SetWindowLongPtr(mHwnd, 0, 0);
/* Send the quit message and wait for it be processed. */
}
}
{
/* Create a window and make it a power event notification handler. */
int rc = VINF_SUCCESS;
/* Register the Window Class. */
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(void *);
if (atomWindowClass == 0)
{
}
else
{
/* Create the window. */
{
}
else
{
{
}
}
}
Log(("HostPowerServiceWin::NotificationThread: exit thread\n"));
if (hwnd)
if (atomWindowClass != 0)
{
atomWindowClass = 0;
}
return 0;
}
{
switch (msg)
{
case WM_POWERBROADCAST:
{
if (pPowerObj)
{
switch(wParam)
{
case PBT_APMSUSPEND:
break;
case PBT_APMRESUMEAUTOMATIC:
break;
case PBT_APMPOWERSTATUSCHANGE:
{
Log(("PBT_APMPOWERSTATUSCHANGE\n"));
{
Log(("PBT_APMPOWERSTATUSCHANGE ACLineStatus=%d BatteryFlag=%d\n", SystemPowerStatus.ACLineStatus, SystemPowerStatus.BatteryFlag));
{
{
rc = CallNtPowerInformation(SystemBatteryState, NULL, 0, (PVOID)&BatteryState, sizeof(BatteryState));
#ifdef LOG_ENABLED
if (rc == 0 /* STATUS_SUCCESS */)
#endif
if ( rc == 0 /* STATUS_SUCCESS */
{
}
}
else
/* If the machine has less than 5% battery left (and is not connected to the AC), then we should save the state. */
{
}
}
}
break;
}
default:
}
}
return TRUE;
}
default:
}
}