CODE
void pwr_callback(void *x, io_service_t srv, natural_t msg_type, void *arg);
static io_connect_t root_port;
void BBRegisterForPowerNotifications()
{
/* Taken from Apple's documentation. */
IONotificationPortRef notify;
io_object_t iterator;
root_port = IORegisterForSystemPower(NULL, /* Date returned on state notification */
¬ify, /* Port that will receive notifications */
pwr_callback, /* Callback function */
&iterator); /* Pointer to notifier */
if (!root_port) return;
CFRunLoopAddSource(CFRunLoopGetCurrent(), /* Run loop to modify */
IONotificationPortGetRunLoopSource(notify), /* Run loop source to add */
kCFRunLoopDefaultMode); /* Mode */
}
void pwr_callback(void *x, io_service_t srv, natural_t msg_type, void *arg)
{
if (msg_type == kIOMessageSystemHasPoweredOn) {
CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), /* The notification center to post to */
BBComputerDidWakeNotification, /* The name of the notification */
NULL, /* Object posting notification */
NULL, /* Additional info */
false); /* Deliver immediately? */
} else if (msg_type == kIOMessageCanSystemSleep || msg_type == kIOMessageSystemWillSleep) {
/* If this is not implemented, there is a 30-second delay before sleep. */
IOAllowPowerChange(root_port, (long)arg);
}
}
static io_connect_t root_port;
void BBRegisterForPowerNotifications()
{
/* Taken from Apple's documentation. */
IONotificationPortRef notify;
io_object_t iterator;
root_port = IORegisterForSystemPower(NULL, /* Date returned on state notification */
¬ify, /* Port that will receive notifications */
pwr_callback, /* Callback function */
&iterator); /* Pointer to notifier */
if (!root_port) return;
CFRunLoopAddSource(CFRunLoopGetCurrent(), /* Run loop to modify */
IONotificationPortGetRunLoopSource(notify), /* Run loop source to add */
kCFRunLoopDefaultMode); /* Mode */
}
void pwr_callback(void *x, io_service_t srv, natural_t msg_type, void *arg)
{
if (msg_type == kIOMessageSystemHasPoweredOn) {
CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), /* The notification center to post to */
BBComputerDidWakeNotification, /* The name of the notification */
NULL, /* Object posting notification */
NULL, /* Additional info */
false); /* Deliver immediately? */
} else if (msg_type == kIOMessageCanSystemSleep || msg_type == kIOMessageSystemWillSleep) {
/* If this is not implemented, there is a 30-second delay before sleep. */
IOAllowPowerChange(root_port, (long)arg);
}
}
or this:
CODE
- (id)init
{
if (self = [super init]) {
dataFileParser = [[MDDataFileParser alloc] init];
dockMenu = nil;
timer = nil;
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[dataFileParser release]; dataFileParser = nil;
[dockMenu release]; dockMenu = nil;
[timer invalidate]; timer = nil; // Do not release -- not retained by object
[super dealloc];
}
{
if (self = [super init]) {
dataFileParser = [[MDDataFileParser alloc] init];
dockMenu = nil;
timer = nil;
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[dataFileParser release]; dataFileParser = nil;
[dockMenu release]; dockMenu = nil;
[timer invalidate]; timer = nil; // Do not release -- not retained by object
[super dealloc];
}