libASPL
|
Base class for audio objects. More...
#include <aspl/Object.hpp>
Public Member Functions | |
Object (std::shared_ptr< const Context > context, const char *className="Object", AudioObjectID objectID=kAudioObjectUnknown) | |
Construct object. Class name is used for logging. It should be the name of the derived class. If objectID is kAudioObjectUnknown (zero), allocates new object ID. Otherwise uses given object ID. | |
Object (const Object &)=delete | |
Object & | operator= (const Object &)=delete |
std::shared_ptr< const Context > | GetContext () const |
Get object context. | |
Class and ID | |
virtual AudioClassID | GetClass () const |
Get class ID. Each subclass overrides this method. | |
virtual AudioClassID | GetBaseClass () const |
Get base class ID. Each subclass overrides this method. | |
virtual bool | IsInstance (AudioClassID classID) const |
Check if this object is instance of given base class. Returns true if any of the base classes matches given class ID. Each subclass overrides this method. | |
AudioObjectID | GetID () const |
Get object ID. Returns objectID selected at construction time. | |
Ownership | |
AudioObjectID | GetOwnerID () const |
Get object owner. If the object has an owner, returns its ID. Otherwise, returns kAudioObjectUnknown (zero). | |
bool | HasOwner () const |
Check if the object is part of the hierarchy. Returns true if GetOwnerID() is not equal to kAudioObjectUnknown. | |
std::vector< AudioObjectID > | GetOwnedObjectIDs (AudioObjectPropertyScope scope=kAudioObjectPropertyScopeGlobal, AudioClassID classID=0) const |
Get owned objects. Returns the list of objects to which this object is the owner. | |
void | AddOwnedObject (std::shared_ptr< Object > object, AudioObjectPropertyScope scope=kAudioObjectPropertyScopeGlobal) |
Add object to the list of owned objects. Also invokes SetOwner() on the added object. | |
void | RemoveOwnedObject (AudioObjectID objectID) |
Remove object to the list of owned objects. Also invokes SetOwner() on the removed object. | |
Notification | |
void | NotifyPropertyChanged (AudioObjectPropertySelector selector, AudioObjectPropertyScope scope=kAudioObjectPropertyScopeGlobal, AudioObjectPropertyElement element=kAudioObjectPropertyElementMain) const |
Notify HAL that a property was changed. This is automatically called by all setters. | |
void | NotifyPropertiesChanged (std::vector< AudioObjectPropertySelector > selectors, AudioObjectPropertyScope scope=kAudioObjectPropertyScopeGlobal, AudioObjectPropertyElement element=kAudioObjectPropertyElementMain) const |
Notify HAL that some properties were changed. This is automatically called by all setters. | |
Property dispatch | |
virtual Boolean | HasProperty (AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address) const |
Check whether given property is present. | |
virtual OSStatus | IsPropertySettable (AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, Boolean *outIsSettable) const |
Check whether given property can be changed. | |
virtual OSStatus | GetPropertyDataSize (AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 *outDataSize) const |
Get size of property value in bytes. | |
virtual OSStatus | GetPropertyData (AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, UInt32 *outDataSize, void *outData) const |
Get property value. | |
virtual OSStatus | SetPropertyData (AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, const void *inData) |
Change property value. | |
Custom properties | |
template<typename ObjectType , typename ValueType > | |
using | GetterMethod = ValueType (ObjectType::*)() const |
Pointer to custom property getter method. Used in RegisterCustomProperty(). | |
template<typename ObjectType , typename ValueType > | |
using | SetterMethod = void (ObjectType::*)(ValueType) |
Pointer to custom property setter method. Used in RegisterCustomProperty(). | |
virtual std::vector< AudioServerPlugInCustomPropertyInfo > | GetCustomProperties () const |
Get info about registered custom properties. Returns list of properties added using RegisterCustomProperty(). | |
template<typename ObjectType , typename ValueType > | |
void | RegisterCustomProperty (AudioObjectPropertySelector selector, ObjectType &object, GetterMethod< ObjectType, ValueType > getter, SetterMethod< ObjectType, ValueType > setter=nullptr) |
Register custom property with getter and optional setter. | |
template<typename GetterFunc > | |
void | RegisterCustomProperty (AudioObjectPropertySelector selector, GetterFunc getter) |
Register custom property with getter and optional setter. | |
void | RegisterCustomProperty (AudioObjectPropertySelector selector, std::function< CFStringRef()> getter, std::function< void(CFStringRef)> setter) |
Register custom property with getter and optional setter. | |
void | RegisterCustomProperty (AudioObjectPropertySelector selector, std::function< CFPropertyListRef()> getter, std::function< void(CFPropertyListRef)> setter) |
Register custom property with getter and optional setter. | |
Base class for audio objects.
CoreAudio uses property-based object model to communicate with plugins. This class is the base class for various audio objects which implement property dispatch protocol required by HAL.
This class provides the following services:
Definition at line 54 of file Object.hpp.
using aspl::Object::GetterMethod = ValueType (ObjectType::*)() const |
Pointer to custom property getter method. Used in RegisterCustomProperty().
Definition at line 173 of file Object.hpp.
using aspl::Object::SetterMethod = void (ObjectType::*)(ValueType) |
Pointer to custom property setter method. Used in RegisterCustomProperty().
Definition at line 178 of file Object.hpp.
|
explicit |
Construct object. Class name is used for logging. It should be the name of the derived class. If objectID is kAudioObjectUnknown
(zero), allocates new object ID. Otherwise uses given object ID.
void aspl::Object::AddOwnedObject | ( | std::shared_ptr< Object > | object, |
AudioObjectPropertyScope | scope = kAudioObjectPropertyScopeGlobal ) |
Add object to the list of owned objects. Also invokes SetOwner() on the added object.
|
virtual |
Get base class ID. Each subclass overrides this method.
kAudioObjectPropertyBaseClass
property. Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
|
virtual |
Get class ID. Each subclass overrides this method.
kAudioObjectPropertyClass
property. Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
std::shared_ptr< const Context > aspl::Object::GetContext | ( | ) | const |
Get object context.
|
virtual |
Get info about registered custom properties. Returns list of properties added using RegisterCustomProperty().
kAudioObjectPropertyCustomPropertyInfoList
property. AudioObjectID aspl::Object::GetID | ( | ) | const |
Get object ID. Returns objectID selected at construction time.
std::vector< AudioObjectID > aspl::Object::GetOwnedObjectIDs | ( | AudioObjectPropertyScope | scope = kAudioObjectPropertyScopeGlobal, |
AudioClassID | classID = 0 ) const |
Get owned objects. Returns the list of objects to which this object is the owner.
kAudioObjectPropertyOwnedObjects
property. AudioObjectID aspl::Object::GetOwnerID | ( | ) | const |
Get object owner. If the object has an owner, returns its ID. Otherwise, returns kAudioObjectUnknown
(zero).
kAudioObjectPropertyOwner
property.
|
virtual |
Get property value.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
|
virtual |
Get size of property value in bytes.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
bool aspl::Object::HasOwner | ( | ) | const |
Check if the object is part of the hierarchy. Returns true if GetOwnerID() is not equal to kAudioObjectUnknown.
|
virtual |
Check whether given property is present.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
|
virtual |
Check if this object is instance of given base class. Returns true if any of the base classes matches given class ID. Each subclass overrides this method.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
|
virtual |
Check whether given property can be changed.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.
void aspl::Object::NotifyPropertiesChanged | ( | std::vector< AudioObjectPropertySelector > | selectors, |
AudioObjectPropertyScope | scope = kAudioObjectPropertyScopeGlobal, | ||
AudioObjectPropertyElement | element = kAudioObjectPropertyElementMain ) const |
Notify HAL that some properties were changed. This is automatically called by all setters.
|
inline |
Notify HAL that a property was changed. This is automatically called by all setters.
Definition at line 146 of file Object.hpp.
|
inline |
Register custom property with getter and optional setter.
This overload is for read-only properties (without setter).
GetterFunc should be convertible to std::function<ValueType()>, where value type should be either CFStringRef or CFPropertyListRef (because they are the only types allowed by CoreAudio).
Getter transfers ownership to the caller; the caller will call CFRelease().
Definition at line 232 of file Object.hpp.
|
inline |
Register custom property with getter and optional setter.
This overload allows to use methods as getter and setter:
Value type should be either CFStringRef or CFPropertyListRef because they are the only types allowed by CoreAudio.
Getter transfers ownership to the caller; the caller will call CFRelease(). Setter does not transfer ownership; the setter should call CFRetain() if it wants to store the value.
Definition at line 207 of file Object.hpp.
void aspl::Object::RegisterCustomProperty | ( | AudioObjectPropertySelector | selector, |
std::function< CFPropertyListRef()> | getter, | ||
std::function< void(CFPropertyListRef)> | setter ) |
Register custom property with getter and optional setter.
This overload is for properties of type CFPropertyListRef.
Setter may be null function if the property is read-only.
Getter transfers ownership to the caller; the caller will call CFRelease(). Setter does not transfer ownership; the setter should call CFRetain() if it wants to store the value.
void aspl::Object::RegisterCustomProperty | ( | AudioObjectPropertySelector | selector, |
std::function< CFStringRef()> | getter, | ||
std::function< void(CFStringRef)> | setter ) |
Register custom property with getter and optional setter.
This overload is for properties of type CFStringRef.
Setter may be null function if the property is read-only.
Getter transfers ownership to the caller; the caller will call CFRelease(). Setter does not transfer ownership; the setter should call CFRetain() if it wants to store the value.
void aspl::Object::RemoveOwnedObject | ( | AudioObjectID | objectID | ) |
Remove object to the list of owned objects. Also invokes SetOwner() on the removed object.
|
virtual |
Change property value.
Reimplemented in aspl::Device, aspl::MuteControl, aspl::Plugin, aspl::Stream, and aspl::VolumeControl.