Re: how to get events from a carbon event handler, in a cocoa app.
Re: how to get events from a carbon event handler, in a cocoa app.
- Subject: Re: how to get events from a carbon event handler, in a cocoa app.
- From: Clayton John <email@hidden>
- Date: Thu, 14 Sep 2006 17:07:06 +0200
:-)
Cool to know - thanks - I stole the code from an example...
OK, I basically want to listen for process activation and
termination... watching the live process list essentially, here's how
the handler gets installed:
EventTypeSpec eventsToListenFor [2];
eventsToListenFor[0].eventClass = kEventClassApplication;
eventsToListenFor[0].eventKind = kEventAppLaunched;
eventsToListenFor[1].eventClass = kEventClassApplication;
eventsToListenFor[1].eventKind = kEventAppTerminated;
OSStatus functionResult = InstallApplicationEventHandler
(launchTerminateCallbackUPP,
2,
eventsToListenFor,
self,
&_eventHandle);
// Done with UPP so dispose of it.
DisposeEventHandlerUPP(launchTerminateCallbackUPP);
if (functionResult != noErr)
_errorCode = CR_LPL_CANNOT_INSTALL_APPEVENT_HANDLER;
I do worry about the dispose-event-handler-upp, wonder why that's
being done? ref counted I *assume* ??
And I was planning on being a 'good little programmer' and cleaning
up after myself, that's why I wanted to keep the event handler handle
around... :-) of course, the OS is nice enough to clean up after me
in this case... again... :-)
John
On 14 Sep 2006, at 17:02, Rosyna wrote:
It should just work, but what events are you installing a handler
for? What is eventsToListenFor? Also, you don't *need* to use
NewEventHandlerUPP, you can just pass
LaunchTerminationNotifierProxyCallbackFunction. And you can pass
NULL for the last param if you are not going to remove this event
handler at any time.
Ack, at 9/14/06, Clayton John said:
here's my problem:
- I don't receive events from an installed carbon handler in my
cocoa app.
- the app is actually a preferences bundle
the code i used to install the handler (ignoring decl'd vars and
so on) is this:
EventHandlerUPP launchTerminateCallbackUPP =
NewEventHandlerUPP(LaunchTerminationNotifierProxyCallbackFunction);
...
OSStatus functionResult = InstallApplicationEventHandler
(launchTerminateCallbackUPP,
2,
eventsToListenFor,
self,
&_eventHandle);
and that in turn is macro defined to this:
#define InstallApplicationEventHandler( handler, numTypes, list,
userData, outHandlerRef ) \
InstallEventHandler( GetApplicationEventTarget(), (handler),
(numTypes), (list), (userData), (outHandlerRef) )
meaning, I've installed a carbon event callback on the Application
Event Target.
So - my app never appears to have the callbacks get called - i.e.
the function launchTerminateCallbackUPP is never called (I've got
print statements in there), and when I start/stop applications I
never see anything.
the test app I stole this from, ObserveProcessLifeCarbon, works OK
- the main difference I see is that in the example application,
they explicitly kick off the carbon run loop via a call to
RunApplicationEventLoop - which isn't an option for me, since the
event loop is being handled by NSApplication / NSResponder type
API's.
Can anyone tell me how I am able to get this application event
listener working in a Cocoa app?
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden