13#include <CoreAudio/AudioServerPlugIn.h>
54class Object :
public std::enable_shared_from_this<Object>
61 explicit Object(std::shared_ptr<const Context> context,
62 const char* className =
"Object",
63 AudioObjectID objectID = kAudioObjectUnknown);
127 AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal,
128 AudioClassID classID = 0)
const;
133 AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal);
147 AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal,
148 AudioObjectPropertyElement element = kAudioObjectPropertyElementMain)
const
156 AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal,
157 AudioObjectPropertyElement element = kAudioObjectPropertyElementMain)
const;
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)
219 : std::function<
void(ValueType)>{});
231 template <
typename GetterFunc>
234 using ValueType =
decltype(getter());
236 static_assert(std::is_same<ValueType, CFStringRef>::value ||
237 std::is_same<ValueType, CFPropertyListRef>::value,
238 "GetterFunc() should return CFStringRef or CFPropertyListRef");
241 std::function<ValueType()>(getter),
242 std::function<
void(ValueType)>{});
255 std::function<CFStringRef()> getter,
256 std::function<
void(CFStringRef)> setter);
268 std::function<CFPropertyListRef()> getter,
269 std::function<
void(CFPropertyListRef)> setter);
281 const AudioObjectPropertyAddress* address)
const;
288 const AudioObjectPropertyAddress* address,
289 Boolean* outIsSettable)
const;
296 const AudioObjectPropertyAddress* address,
297 UInt32 qualifierDataSize,
298 const void* qualifierData,
299 UInt32* outDataSize)
const;
306 const AudioObjectPropertyAddress* address,
307 UInt32 qualifierDataSize,
308 const void* qualifierData,
311 void* outData)
const;
318 const AudioObjectPropertyAddress* address,
319 UInt32 qualifierDataSize,
320 const void* qualifierData,
327 struct CustomProperty;
329 void AttachOwner(
Object& owner);
332 Boolean HasPropertyFallback(AudioObjectID objectID,
334 const AudioObjectPropertyAddress* address)
const;
336 OSStatus IsPropertySettableFallback(AudioObjectID objectID,
338 const AudioObjectPropertyAddress* address,
339 Boolean* outIsSettable)
const;
341 OSStatus GetPropertyDataSizeFallback(AudioObjectID objectID,
343 const AudioObjectPropertyAddress* address,
344 UInt32 qualifierDataSize,
345 const void* qualifierData,
346 UInt32* outDataSize)
const;
348 OSStatus GetPropertyDataFallback(AudioObjectID objectID,
350 const AudioObjectPropertyAddress* address,
351 UInt32 qualifierDataSize,
352 const void* qualifierData,
355 void* outData)
const;
357 OSStatus SetPropertyDataFallback(AudioObjectID objectID,
359 const AudioObjectPropertyAddress* address,
360 UInt32 qualifierDataSize,
361 const void* qualifierData,
365 mutable std::mutex writeMutex_;
367 const std::shared_ptr<const Context> context_;
369 const char*
const className_;
371 const AudioObjectID objectID_;
373 Object* ownerObject_ =
nullptr;
374 std::atomic<AudioObjectID> ownerObjectID_ = kAudioObjectUnknown;
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.