• 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: More Than One AudioHardwareAddPropertyListener
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Than One AudioHardwareAddPropertyListener


  • Subject: Re: More Than One AudioHardwareAddPropertyListener
  • From: Jeff Moore <email@hidden>
  • Date: Tue, 26 Jun 2001 17:39:41 -0700

on 6/26/01 12:19 PM, Vincent Predoehl <email@hidden> wrote:

> Hello, is it possible to call AudioHardwareAddPropertyListener for the
> same property using the same listener function more than once? I have a
> C++ wrapper class for listeners, and I am wondering if this will cause
> any problems. The user data is the only thing that is guaranteed to be
> different.

You can register the one listener function with as many properties as you'd
like.

You cannot register one listener function with the same property multiple
times. This leaves you on your own for dispatching back into your own code.

With my C++ code I like to "virtualize" the listener proc. Here's an example
where the listener is listening for the device list changing:

class DevicePropertyListener
{
void SignIn();
virtual void HandleHardwarePropertyNotfication(
AudioHardwarePropertyID inPropertyID);
static OSStatus HardwarePropertyNotification(
AudioHardwarePropertyID inPropertyID,
void* inClientData);
};

void DevicePropertyListener::SignIn()
{
OSStatus theStatus = kAudioHardwareNoError;
theStatus = AudioHardwareAddPropertyListener(
kAudioHardwarePropertyDevices,
DevicePropertyListener::HardwarePropertyNotification,
this);
ThrowIfError(theStatus);
}

void DevicePropertyListener::HandleHardwarePropertyNotfication(
AudioHardwarePropertyID inPropertyID)
{
switch(inPropertyID)
{
case kAudioHardwarePropertyDevices:
// the device list changed, so
// do something interesting
break;
default:
break;
};
}

OSStatus HardwarePropertyNotification(
AudioHardwarePropertyID inPropertyID,
void* inClientData)
{
OSStatus theStatus = kAudioHardwareNoError;
try
{
DevicePropertyListener* theListener =
dynamic_cast<DevicePropertyListener*>(inClientData);
theListener->HandleHardwarePropertyNotfication(inPropertyID);
}
catch(...)
{
}
return theStatus
}

Note the try/catch in the static routine. It is vital to prevent C++
exceptions from propagating outside of a callback like a listener proc.

--

Jeff Moore
Core Audio
Apple


References: 
 >More Than One AudioHardwareAddPropertyListener (From: Vincent Predoehl <email@hidden>)

  • Prev by Date: Is there anybody out there?
  • Next by Date: NEWBIE: Anyone using the AudioToolbox framework?
  • Previous by thread: More Than One AudioHardwareAddPropertyListener
  • Next by thread: Timers for MIDI
  • Index(es):
    • Date
    • Thread