• 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
Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process


  • Subject: Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • From: Eric Schlegel <email@hidden>
  • Date: Mon, 8 Oct 2007 23:06:37 -0700


On Oct 8, 2007, at 10:45 PM, James Bucanek wrote:

- (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);

For future reference, I'd code this something like:

EventTypeSpec eventTypes[] =
{
{ kEventClassVolume, kEventVolumeMounted },
{ kEventClassVolume, kEventVolumeUnmounted }
};
InstallApplicationEventHandler (sVolumeEventCallback ,GetEventTypeCount(eventTypes),eventTypes,self,&volumeEventHandlerRef);


It's easier and less error-prone to use initialization syntax to set up the EventTypeSpec array, and by using GetEventTypeCount to get the count of elements in the array, you avoid the risk of modifying the array and forgetting to modify the count. Also, you can skip the NewFooUPP calls in mach-o; they just return the pointer you passed in.

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.

The only thing that really should be required is that you spin the runloop, and it sounds like you're doing that.


If it makes any difference, the main NSRunLoop for this process is run using [NSRunLoop runMode:beforeDate:].

What mode are you passing? Anything custom?

-eric
_______________________________________________

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: James Bucanek <email@hidden>
References: 
 >Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process (From: James Bucanek <email@hidden>)

  • Prev by Date: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • Next by Date: Adding binding causes all bindings to fail
  • Previous by thread: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • Next by thread: Re: Getting Carbon Volume Mount Events in a Cocoa (Core Foundation) process
  • Index(es):
    • Date
    • Thread