Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sunil

macrumors newbie
Original poster
Oct 6, 2005
7
0
Hi Guys,

I have written a network application in cocoa.
In my application I want to capture the Logout,Restart,Shutdown events.
Based on these events I want to send some message to my server.


After reading the documentation on internet regarding system events I came to know that whenever user choose "Shutdown" or "Restart" from the Apple Menu the running application gets "KAEQuitApplication" event but not any specific event whether the application is quiting by "Shutdown" or "Restart" or "Log Out". The "KAEQuitApplication" event also get by the user when he/she quit their application by clicking at the top left cross button of the application window.

I m looking to get the specific event related with each action taken by the user i.e. "Shutdown" or "Restart" or "Log Out".
Is it possible to get the different event for each of the action taken by the user i.e. "Shutdown" or "Restart" or "Log Out"?.

waiting for the reply.

Thanks,
sunil
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
I've no idea. But you could try seeing if a notification is sent, by registering for all distributed notifications; restarting your Mac, and seeing what notifications were received.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I think these may be what you're looking for: kIOMessageSystemWillPowerOff, kIOMessageSystemWillSleep, kIOMessageSystemWillRestart
 

semaja2

macrumors 6502a
Dec 12, 2005
576
18
Adelaide
Heres some code from my Utility Lock, i believe you could just change the constants in the case;

PowerManagment.m
Code:
#import "PowerManagment.h"

void powerCallback(void *refCon, io_service_t service, natural_t messageType, void *messageArgument)
{
    [(PowerManagment *)refCon powerMessageReceived: messageType withArgument: messageArgument];
}

@implementation PowerManagment
- (void)powerMessageReceived:(natural_t)messageType withArgument:(void *) messageArgument
{
    switch (messageType)
    {
        case kIOMessageSystemWillSleep:{
            IOAllowPowerChange(root_port, (long)messageArgument);
            NSLog(@"System is going to sleep");
            break;
		}
        case kIOMessageCanSystemSleep:
            // I don’t know if this will ever be asked…
            IOAllowPowerChange(root_port, (long)messageArgument);
            break; 
			
        case kIOMessageSystemHasPoweredOn:{
            NSLog(@"System has awaken from sleep");
            break;
		}
    }
}

- (void)awakeFromNib {
    IONotificationPortRef notificationPort;
    root_port = IORegisterForSystemPower(self, &notificationPort, powerCallback, &notifier);
    NSAssert(root_port != nil, @"IORegisterForSystemPower failed");
    CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopDefaultMode);
}

PowerManagment.h
Code:
#import <Cocoa/Cocoa.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
#import <IOKit/IOMessage.h>

@interface PowerManagment : NSObject {
	io_connect_t root_port;
	io_object_t notifier;
}
- (void)powerMessageReceived:(natural_t)messageType withArgument:(void *) messageArgument;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.