Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions dev/PowerNotifications/PowerNotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ namespace winrt::Microsoft::Windows::System::Power::implementation
}

// PowerSourceKind Functions
EventType& PowerSourceKind_Event()
{
return Factory()->m_powerSourceKindChangedEvent;
}

void PowerSourceKind_Register()
{
Expand Down Expand Up @@ -204,44 +200,9 @@ namespace winrt::Microsoft::Windows::System::Power::implementation
Factory()->m_systemIdleStatusHandle));
}

ULONG GetEffectivePowerModeVersion()
{
// We check for the version supported by checking if the feature is supported
// Using NULL as an indicator for uninitialized cache value
auto& version{ Factory()->m_powerModeVersion };
if (!version)
{
void* handle{};
auto hr{ PowerRegisterForEffectivePowerModeNotifications(
EFFECTIVE_POWER_MODE_V2, [](EFFECTIVE_POWER_MODE, void*) {}, nullptr, &handle) };
version = SUCCEEDED(hr) ? EFFECTIVE_POWER_MODE_V2 : EFFECTIVE_POWER_MODE_V1;
THROW_IF_FAILED(PowerUnregisterFromEffectivePowerModeNotifications(handle));
}
return version;
}

EventType& EffectivePowerMode_Event()
{
return Factory()->m_powerModeChangedEvent;
}

void EffectivePowerMode_Register()
{
ULONG version{ GetEffectivePowerModeVersion() };
auto& powerModeHandle{ Factory()->m_powerModeHandle };
THROW_IF_FAILED(PowerRegisterForEffectivePowerModeNotifications(
version, [](EFFECTIVE_POWER_MODE mode, void*)
{
PowerManager::EffectivePowerModeChanged_Callback(mode);
}, nullptr, &powerModeHandle));
}

void EffectivePowerMode_Unregister()
{
auto& powerModeHandle{ Factory()->m_powerModeHandle };
THROW_IF_FAILED(PowerUnregisterFromEffectivePowerModeNotifications(powerModeHandle));
powerModeHandle = nullptr;
}

void EffectivePowerMode_Update()
{
Expand Down
18 changes: 0 additions & 18 deletions dev/PowerNotifications/PowerNotifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ namespace winrt::Microsoft::Windows::System::Power
void SystemIdleStatus_Register();
void SystemIdleStatus_Unregister();

EventType& EffectivePowerMode_Event();
void EffectivePowerMode_Register();
void EffectivePowerMode_Unregister();
void EffectivePowerMode_Update();

EventType& UserPresenceStatus_Event();
void UserPresenceStatus_Register();
Expand Down Expand Up @@ -202,12 +198,6 @@ namespace winrt::Microsoft::Windows::System::Power
&Power::implementation::NoOperation,
L"SystemIdleStatus" };

PowerFunctionDetails effectivePowerModeFunc{
&Power::implementation::EffectivePowerMode_Event,
&Power::implementation::EffectivePowerMode_Register,
&Power::implementation::EffectivePowerMode_Unregister,
&Power::implementation::EffectivePowerMode_Update,
L"EffectivePowerMode" };

PowerFunctionDetails userPresenceStatusFunc{
&Power::implementation::UserPresenceStatus_Event,
Expand Down Expand Up @@ -539,14 +529,6 @@ namespace winrt::Microsoft::Windows::System::Power
}


// EffectivePowerMode Functions
winrt::Windows::Foundation::IAsyncOperation<Power::EffectivePowerMode> EffectivePowerMode()
{
co_await resume_background();
UpdateValuesIfNecessary(effectivePowerModeFunc);
auto res{ static_cast<Power::EffectivePowerMode>(m_cachedPowerMode) };
co_return res;
}

Power::EffectivePowerMode EffectivePowerMode2()
{
Expand Down
1 change: 0 additions & 1 deletion dev/PowerNotifications/PowerNotifications.idl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ namespace Microsoft.Windows.System.Power

static event Windows.Foundation.EventHandler<Object> SystemIdleStatusChanged;

static Windows.Foundation.IAsyncOperation<EffectivePowerMode> EffectivePowerMode{ get; };
static event Windows.Foundation.EventHandler<Object> EffectivePowerModeChanged;

[contract(PowerNotificationsContract, 2)]
Expand Down
6 changes: 6 additions & 0 deletions test/PowerNotifications/APITests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,11 @@ namespace Test::PowerNotifications
VERIFY_IS_NOT_NULL(token);
PowerManager::SystemSuspendStatusChanged(token);
}

TEST_METHOD(GetEffectivePowerMode)
{
auto value = PowerManager::EffectivePowerMode2();
VERIFY_ARE_EQUAL(value, EffectivePowerMode::Balanced);
}
};
}