📄 poweridledevice.cpp
字号:
// PowerIdleDevice.cpp
// Implementation of PowerIdleDevice device class
//
// Generated by DriverWizard version DriverStudio 2.6.0 (Build 336)
// Requires Compuware's DriverWorks classes
//
#pragma warning(disable:4065) // Allow switch statement with no cases
#include <vdw.h>
#include "..\PowerIdleDeviceinterface.h"
#include "PowerIdle.h"
#include "PowerIdleDevice.h"
#include "..\PowerIdleioctl.h"
#pragma hdrstop("PowerIdle.pch")
extern KTrace t; // Global driver trace object
GUID PowerIdleDevice_Guid = PowerIdleDevice_CLASS_GUID;
PowerIdleDevice::PowerIdleDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
KPnpDevice(Pdo, &PowerIdleDevice_Guid)
{
t << "PowerIdleDevice (constructor)\n";
// Check constructor status
if ( ! NT_SUCCESS(m_ConstructorStatus) )
{
return;
}
// Remember our unit number
m_Unit = Unit;
// Initialize the lower device
m_Lower.Initialize(this, Pdo);
// Inform the base class of the lower edge device object
SetLowerDevice(&m_Lower);
// Initialize the PnP Policy settings to the "standard" policy
SetPnpPolicy();
// TODO: Customize the PnP Policy for this device by setting
// flags in m_Policies.
// Initialize the Power Policy settings to the "standard" policy
SetPowerPolicy();
// TODO: Customize the Power Policy for this device by setting
// flags in m_PowerPolicies.
}
PowerIdleDevice::~PowerIdleDevice()
{
t << "~PowerIdleDevice() (destructor)\n";
}
NTSTATUS PowerIdleDevice::DefaultPnp(KIrp I)
{
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);
}
NTSTATUS PowerIdleDevice::DefaultPower(KIrp I)
{
t << "DefaultPower\n";
I.IndicatePowerIrpProcessed();
I.CopyParametersDown();
return m_Lower.PnpPowerCall(this, I);
}
NTSTATUS PowerIdleDevice::SystemControl(KIrp I)
{
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);
}
NTSTATUS PowerIdleDevice::OnStartDevice(KIrp I)
{
t << "OnStartDevice\n";
return STATUS_SUCCESS;
}
NTSTATUS PowerIdleDevice::OnStopDevice(KIrp I)
{
t << "OnStopDevice\n";
return STATUS_SUCCESS;
}
NTSTATUS PowerIdleDevice::OnRemoveDevice(KIrp I)
{
t << "OnRemoveDevice\n";
return STATUS_SUCCESS;
}
NTSTATUS PowerIdleDevice::Create(KIrp I)
{
NTSTATUS status;
t << "Create\n";
status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);
return status;
}
NTSTATUS PowerIdleDevice::Close(KIrp I)
{
NTSTATUS status;
t << "Close\n";
status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);
return status;
}
NTSTATUS PowerIdleDevice::DeviceControl(KIrp I)
{
NTSTATUS status;
switch (I.IoctlCode())
{
case POWERIDLE_IOCTL_800:
t << "POWERIDLE_IOCTL_800_Handler\n";
I.Information() = 0;
status = STATUS_SUCCESS;
break;
default:
// Unrecognized IOCTL request
status = STATUS_INVALID_PARAMETER;
break;
}
return I.PnpComplete(this, status);
}
NTSTATUS PowerIdleDevice::OnDevicePowerUp(KIrp I)
{
NTSTATUS status = STATUS_SUCCESS;
t << "OnDevicePowerUp\n";
// TODO: Service the device.
// Restore any context to the hardware device that
// was saved during the handling of a power down request.
// See the OnDeviceSleep function.
// Do NOT complete this IRP.
//
switch ( I.PowerStateType() )
{
case SystemPowerState:
t << "SystemPowerState " << SystemPowerStateName(I.PowerStateSetting().SystemState) << "\n" ;
break;
case DevicePowerState:
t << "DevicePowerState " << DevicePowerStateName(I.PowerStateSetting().DeviceState) << "\n" ;
break;
}
EnableIdleDetection(30,30,PowerDeviceD1);
//允许空闲检测,能源保护模式和最佳性能模式的空闲检测超时值均为30秒
return status;
}
NTSTATUS PowerIdleDevice::OnDeviceSleep(KIrp I)
{
NTSTATUS status = STATUS_SUCCESS;
t << "OnDeviceSleep\n";
// TODO: Service the device.
// Save any context to the hardware device that will be required
// during a power up request. See the OnDevicePowerUp function.
// Do NOT complete this IRP. The base class handles forwarding
// this IRP to the PDO.
//
switch ( I.PowerStateType() )
{
case SystemPowerState:
t << "SystemPowerState " << SystemPowerStateName(I.PowerStateSetting().SystemState) << "\n" ;
break;
case DevicePowerState:
t << "DevicePowerState " << DevicePowerStateName(I.PowerStateSetting().DeviceState) << "\n" ;
break;
}
DisableIdleDetection(); //禁止空闲检测
//若允许空闲检测,当空闲检测超时后,如不禁止空闲检测,系统将周期性地调用
//OnDeviceSleep例程
return status;
}
PCHAR DevicePowerStateName(DEVICE_POWER_STATE ps)
{
static PCHAR PowerStates[] = {
"PowerDeviceUnspecified",
"PowerDeviceD0",
"PowerDeviceD1",
"PowerDeviceD2",
"PowerDeviceD3"
};
if (ps > PowerDeviceD3)
return "<undefined power state>";
else
return PowerStates[ps];
}
PCHAR SystemPowerStateName(SYSTEM_POWER_STATE ps)
{
static PCHAR PowerStates[] = {
"PowerSystemUnspecified",
"PowerSystemWorking",
"PowerSystemSleeping1",
"PowerSystemSleeping2",
"PowerSystemSleeping3",
"PowerSystemHibernate",
"PowerSystemShutdown"
};
if (ps > PowerSystemShutdown)
return "<undefined power state>";
else
return PowerStates[ps];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -