Ugh!, This is gonna get ugly. |
![]() ![]() |
Ugh!, This is gonna get ugly. |
| *mipadi* |
Jan 7 2007, 02:38 PM
Post
#1
|
|
Guest |
As much as I like C, sometimes it's not fun to jump from Java/Objective-C to pure C. Seriously, which is more fun to read, this:
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); } } 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]; } |
|
|
|
| *kryogenix* |
Jan 7 2007, 02:39 PM
Post
#2
|
|
Guest |
PSEUDO CODE FTW
|
|
|
|
![]() ![]() |