Version: 3.1.2
wxPowerResourceBlocker Class Reference

#include <wx/power.h>

Detailed Description

Helper RAII class ensuring that power resources are released.

A wxPowerResourceBlocker object acquires a power resource in the constructor and releases it in the destructor making it impossible to to forget to release the power resource (which would prevent suspending or screen power off until the application ends).

Example:

void MyWindow::DoSomething()
{
blocker(wxPOWER_RESOURCE_SYSTEM, "Downloading something important");
if ( !blocker.IsInEffect() )
{
// If the resource could not be acquired, tell the user that he has
// to keep the system alive
wxLogMessage("Warning: system may suspend while downloading.");
}
// Run an important download and the system will not suspend while downloading
for ( int i = 0; i < download.size(); ++i )
download.readByte();
// wxPOWER_RESOURCE_SYSTEM automatically released here.
}
Since
3.1.0

Library:  wxBase
Category:  Miscellaneous
See also
wxPowerResource

Public Member Functions

 wxPowerResourceBlocker (wxPowerResourceKind kind, const wxString &reason=wxString())
 Acquires the power resource. More...
 
bool IsInEffect () const
 Returns whether the power resource could be acquired. More...
 
 ~wxPowerResourceBlocker ()
 Releases the power resource. More...
 

Constructor & Destructor Documentation

wxPowerResourceBlocker::wxPowerResourceBlocker ( wxPowerResourceKind  kind,
const wxString reason = wxString() 
)
explicit

Acquires the power resource.

Uses the same parameters as wxPowerResource::Acquire().

wxPowerResourceBlocker::~wxPowerResourceBlocker ( )

Releases the power resource.

See also
wxPowerResource::Release()

Member Function Documentation

bool wxPowerResourceBlocker::IsInEffect ( ) const

Returns whether the power resource could be acquired.

This can be used to inform the user that the application will not prevent automatic suspending.

See also
wxPowerResource::Acquire()