Add wxPowerResourceBlocker for power management.

Add functions to acquire/release power resources, preventing/allowing back the
system to go to sleep or turn off the screen and a class wrapping them in a
safe way.

This patch implements the functions for MSW and OSX, adds documentation and
updates the sample to demonstrate the new functionality.

Closes #16413.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77511 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-08-29 23:22:15 +00:00
parent a704ab9cc0
commit 51d715e46d
12 changed files with 534 additions and 15 deletions

View File

@@ -95,6 +95,49 @@ typedef void (wxEvtHandler::*wxPowerEventFunction)(wxPowerEvent&);
#undef wxHAS_POWER_EVENTS
#endif // support for power events/no support
// ----------------------------------------------------------------------------
// wxPowerResourceBlocker
// ----------------------------------------------------------------------------
enum wxPowerResourceKind
{
wxPOWER_RESOURCE_SCREEN,
wxPOWER_RESOURCE_SYSTEM
};
class WXDLLIMPEXP_BASE wxPowerResource
{
public:
static bool Acquire(wxPowerResourceKind kind,
const wxString& reason = wxString());
static void Release(wxPowerResourceKind kind);
};
class wxPowerResourceBlocker
{
public:
explicit wxPowerResourceBlocker(wxPowerResourceKind kind,
const wxString& reason = wxString())
: m_kind(kind),
m_acquired(wxPowerResource::Acquire(kind, reason))
{
}
bool IsInEffect() const { return m_acquired; }
~wxPowerResourceBlocker()
{
if ( m_acquired )
wxPowerResource::Release(m_kind);
}
private:
const wxPowerResourceKind m_kind;
const bool m_acquired;
wxDECLARE_NO_COPY_CLASS(wxPowerResourceBlocker);
};
// ----------------------------------------------------------------------------
// power management functions
// ----------------------------------------------------------------------------