Module: System::Power
- Defined in:
- lib/system_control/power.rb,
ext/system_control/power.c
Class Method Summary (collapse)
-
+ (Object) no_sleep_close
Cleans up the non-sleep.
-
+ (Object) no_sleep_open
Prepares the non-sleep.
-
+ (Object) sleep
Sleeps the machine.
-
+ (Object) sleep_display
Sleeps the only display.
Instance Method Summary (collapse)
-
- (Object) no_sleep(&block)
While this method processes given block, the system does not sleep.
Class Method Details
+ (Object) no_sleep_close
Cleans up the non-sleep. This method is used by no_sleep.
|
|
# File 'ext/system_control/power.c'
/*
* Cleans up the non-sleep. This method is used by no_sleep.
*
* @see
* System::Power.no_sleep
*/
static VALUE
rb_sys_no_sleep_close(VALUE obj, VALUE arg)
{
IOPMAssertionRelease(FIX2INT(arg));
}
|
+ (Object) no_sleep_open
Prepares the non-sleep. This method is used by no_sleep.
|
|
# File 'ext/system_control/power.c'
/*
* Prepares the non-sleep. This method is used by no_sleep.
*
* @see
* System::Power.no_sleep
*/
static VALUE
rb_sys_no_sleep_open(VALUE obj)
{
IOPMAssertionID id;
IOReturn ret = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, &id);
if (ret != kIOReturnSuccess) {
rb_raise(rb_eRuntimeError, "no sleep failed");
}
return INT2FIX((int)id);
}
|
+ (Object) sleep
Sleeps the machine.
|
|
# File 'ext/system_control/power.c'
/*
* Sleeps the machine.
*
* @example
* System::Power.sleep
*/
static VALUE
rb_sys_sleep(VALUE obj)
{
mach_port_t port;
io_connect_t manage;
if (IOMasterPort(bootstrap_port, &port) != kIOReturnSuccess) {
rb_raise(rb_eRuntimeError, "Failed to get master port");
}
manage = IOPMFindPowerManagement(port);
if (!manage) {
rb_raise(rb_eRuntimeError, "Failed to find power management");
}
if (IOPMSleepSystem(manage) != kIOReturnSuccess) {
rb_raise(rb_eRuntimeError, "Failed to sleep");
}
IOServiceClose(manage);
return Qnil;
}
|
+ (Object) sleep_display
Sleeps the only display.
|
|
# File 'ext/system_control/power.c'
/*
* Sleeps the only display.
*
* @example
* System::Power.sleep_display
*/
static VALUE
rb_sys_sleep_display(VALUE obj)
{
io_registry_entry_t regist =
IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if(!regist) {
return Qnil;
}
IORegistryEntrySetCFProperty(regist, CFSTR("IORequestIdle"), kCFBooleanTrue);
IOObjectRelease(regist);
return Qnil;
}
|
Instance Method Details
- (Object) no_sleep(&block)
While this method processes given block, the system does not sleep.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/system_control/power.rb', line 17 def no_sleep(&block) if !block_given? raise ArgumentError, "need block" end begin id = no_sleep_open() block.call ensure no_sleep_close(id) end end |