我在根进程(守护程序)中使用Carbon Event Manager来监视用户进程(我的应用程序)的状态。但是我只获得kEventAppLaunched
用户进程(我的应用程序),我在那里吃午根进程(守护进程)。如何在所有登录用户中获取kEventAppLaunched
用户进程。
static OSStatus CarbonEventHandler(
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent,
void * inUserData
)
{
ProcessSerialNumber psn;
CFStringRef processName = NULL ;
id lUserData;
if (inUserData) {
lUserData= (id)inUserData;
}
OSStatus status;
(void) GetEventParameter(
inEvent,
kEventParamProcessID,
typeProcessSerialNumber,
NULL,
sizeof(psn),
NULL,
&psn
);
switch ( GetEventKind(inEvent) ) {
case kEventAppLaunched:
status = CopyProcessName(&psn , &processName);
if (processName != NULL) {
if([(NSString *)processName isEqualToString:@"myApp"])
{
//initialize application
}
CFRelease(processName);
}
break;
default:
break;
}
return noErr;
}
- (void)InstallCarbonEventsForMonitor
{
static EventHandlerRef sCarbonEventsRef = NULL;
static const EventTypeSpec kEvents[] = {
{ kEventClassApplication, kEventAppLaunched },
{ kEventClassApplication, kEventAppTerminated }
};
if (sCarbonEventsRef == NULL) {
(void) InstallEventHandler( GetApplicationEventTarget(), (EventHandlerUPP) CarbonEventHandler,
GetEventTypeCount(kEvents),
kEvents,
self,
&sCarbonEventsRef
);
}
}