Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
- Subject: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
- From: James Bucanek <email@hidden>
- Date: Mon, 8 Oct 2007 22:45:12 -0700
Greetings,
I'm trying to get the Carbon volume mount and unmount events in
a Core Foundation process (daemon). Here's the code I use to
install the handler:
- (void)startNotifications
{
if (volumeEventUPP==NULL)
{
volumeEventUPP = NewEventHandlerUPP(sVolumeEventCallback);
EventTypeSpec eventTypes[2];
eventTypes[0].eventClass = kEventClassVolume;
eventTypes[0].eventKind = kEventVolumeMounted;
eventTypes[1].eventClass = kEventClassVolume;
eventTypes[1].eventKind = kEventVolumeUnmounted;
OSStatus osStatus = InstallApplicationEventHandler(volumeEventUPP,2,eventTypes,self,&volumeEventHandlerRef);
if (osStatus==noErr)
[Logger log success... <-- I get this message
else
[Logger log failure...
}
}
...
static OSStatus sVolumeEventCallback( EventHandlerCallRef
handlerCallRef, EventRef event, void *userData )
{
#pragma unused(handlerCallRef)
#pragma unused(userData)
NSLog(@"%s",__func__);
FSVolumeRefNum refNum = 0;
OSStatus osStatus = GetEventParameter (event,kEventParamDirectObject,typeFSVolumeRefNum,NULL,sizeof(refNum),NULL,&refNum);
if (osStatus==noErr)
{
NSString* diskID = nil;
osStatus = FSCopyDiskIDForVolume(refNum,(CFStringRef*)&diskID);
NSLog(@"FSCopyDiskIDForVolume() returned %d; %@",osStatus,diskID);
[diskID autorelease];
...
}
else
{
[Logger log failure ...
}
return (noErr);
}
What I get is nothing. The success log message in
startNotifications is recorded, then nothing beyond that. As far
as I can tell, sVolumeEventCallback is never called.
I've gone over the Carbon-Cocoa Integration guide and it doesn't
mention that you have to do anything special to get Carbon
events in a Cocoa application. It indicates that this should
"just work," but clearly something is missing.
If it makes any difference, the main NSRunLoop for this process
is run using [NSRunLoop runMode:beforeDate:].
P.S. I originally coded this using the disk arbitration
framework. But it turns out that DA event don't include volume
mount and unmount events, which is what I'm really interested in.
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden