Re: How to noify the framework when application closes
Re: How to noify the framework when application closes
- Subject: Re: How to noify the framework when application closes
- From: Dirk Stegemann <email@hidden>
- Date: Mon, 16 Jan 2006 22:37:03 +0200
Hi,
Am 16.01.2006 um 11:00 schrieb rohit dhamija:
I have build an framework for accessing the usb bulk storage device
using iokit framework. Multiple applications can access the device
using this framework.
[...]
So is there any way that I can notify the framework that the
application has been closed ?
I'm not sure about the applications which will load your framework,
but we have a Carbon application which manages (vendor specific) USB
bulk devices to provide access to these devices to client
applications. Usually, client application register at our Carbon app
to indicate that they want to use the USB devices, and unregister to
indicate they don't want to any longer.
So, this is entirely "user space" access of the devices, I think your
situation is similar.
Now, to learn about client apps which die without unregistering, as
soon as such a client registers we store its Process Serial Number.
Then, from within an installed application event handler which is
called every time a process dies, we check whether the PSN of the
died app is in our list.
In case your SIGNAL hanlder approach doesn't suffice, you could try
to spawn such a little app which just listens for dying apps and
cleans up some framework resources...
See below some sample code snippets (shortened in Mail).
Regards,
Dirk Stegemann
-----snip-----
// Application's kEventAppTerminated Handler
pascal OSStatus AEAppTerminatedHandler( EventHandlerCallRef nextHandler,
EventRef theEvent,
void* userData)
{
// get PSN out of 'theEvent'
ProcessSerialNumber processSerialNumber;
OSErr theErr = extractPSNFromEventRef(theEventRef,
&processSerialNumber);
EventParamType outActualType;
UInt32 outActualSize = 0;
OSErr theErr = GetEventParameter ( theEvent,
kEventParamProcessID,
typeProcessSerialNumber,
&outActualType,
sizeof(ProcessSerialNumber),
&outActualSize,
&processSerialNumber);
if ((myErr) || (outActualType != typeProcessSerialNumber) ||
(outActualSize != sizeof(ProcessSerialNumber)))
// handle error
// check for client PSNs...
return noErr;
}
-----snip-----
OSErr myErr = noErr;
EventTypeSpec eventsToListenFor [1];
EventHandlerUPP gAEAppTerminatedHandler = NewEventHandlerUPP
(AEAppTerminatedHandler);
-----snip-----
{
// this is somewhere in 'main()':
eventsToListenFor[0].eventClass = kEventClassApplication;
eventsToListenFor[0].eventKind = kEventAppTerminated;
// Work around a bug (r. 2998556) in Mac OS X 10.2 by forcing
// the Process Manager to initialize itself.
{
ProcessSerialNumber junkPSN;
(void) GetCurrentProcess ( &junkPSN );
}
// Now call InstallApplicationEventHandler.
myErr = InstallApplicationEventHandler( gAEAppTerminatedHandler, //
the callback handler
1, // number of different event-kinds the callback
should handle
eventsToListenFor, // the list of event kinds the
callback should handle
nil, // user data
gEventHandlerAppTerminatedRemovalHandle);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden