13#include <CoreAudio/AudioServerPlugIn.h>
54class Object :
public std::enable_shared_from_this<Object>
172 template <
typename ObjectType,
typename ValueType>
177 template <
typename ObjectType,
typename ValueType>
206 template <
typename ObjectType,
typename ValueType>
212 static_assert(std::is_same<ValueType, CFStringRef>::value ||
213 std::is_same<ValueType, CFPropertyListRef>::value,
214 "ValueType should be CFStringRef or CFPropertyListRef");
217 std::bind(
getter, &
object),
218 setter ? std::bind(
setter, &
object, std::placeholders::_1)
231 template <
typename GetterFunc>
236 static_assert(std::is_same<ValueType, CFStringRef>::value ||
237 std::is_same<ValueType, CFPropertyListRef>::value,
238 "GetterFunc() should return CFStringRef or CFPropertyListRef");
365 mutable std::mutex writeMutex_;
367 const std::shared_ptr<const Context> context_;
369 const char*
const className_;
373 Object* ownerObject_ =
nullptr;
377 std::map<AudioObjectID, std::shared_ptr<Object>>>>
Compatibility definitions.
Doubly-buffered value with non-blocking read and blocking write.
Base class for audio objects.
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.
AudioObjectID GetOwnerID() const
Get object owner. If the object has an owner, returns its ID. Otherwise, returns kAudioObjectUnknown ...
ValueType(ObjectType::*)() const GetterMethod
Pointer to custom property getter method. Used in RegisterCustomProperty().
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.
virtual Boolean HasProperty(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address) const
Check whether given property is present.
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 RegisterCustomProperty(AudioObjectPropertySelector selector, ObjectType &object, GetterMethod< ObjectType, ValueType > getter, SetterMethod< ObjectType, ValueType > setter=nullptr)
Register custom property with getter and optional setter.
bool HasOwner() const
Check if the object is part of the hierarchy. Returns true if GetOwnerID() is not equal to kAudioObje...
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...
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.
AudioObjectID GetID() const
Get object ID. Returns objectID selected at construction time.
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.
virtual std::vector< AudioServerPlugInCustomPropertyInfo > GetCustomProperties() const
Get info about registered custom properties. Returns list of properties added using RegisterCustomPro...
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.
std::shared_ptr< const Context > GetContext() const
Get object context.
void(ObjectType::*)(ValueType) SetterMethod
Pointer to custom property setter method. Used in RegisterCustomProperty().
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.
virtual OSStatus IsPropertySettable(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, Boolean *outIsSettable) const
Check whether given property can be changed.
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....
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.
void RegisterCustomProperty(AudioObjectPropertySelector selector, std::function< CFPropertyListRef()> getter, std::function< void(CFPropertyListRef)> setter)
Register custom property with getter and optional setter.
virtual OSStatus SetPropertyData(AudioObjectID objectID, pid_t clientPID, const AudioObjectPropertyAddress *address, UInt32 qualifierDataSize, const void *qualifierData, UInt32 inDataSize, const void *inData)
Change property value.
void RemoveOwnedObject(AudioObjectID objectID)
Remove object to the list of owned objects. Also invokes SetOwner() on the removed object.