• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
      • From: email@hidden
    • Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
      • From: Eric Schlegel <email@hidden>
  • Prev by Date: CoreData: "nil is not a valid persistent store" and can't save
  • Next by Date: Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • Previous by thread: CoreData: "nil is not a valid persistent store" and can't save
  • Next by thread: Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • Index(es):
    • Date
    • Thread