Skip to content

Commit ef992e8

Browse files
committed
Rework argument types
Argument types of setters and ctors now mostly follow these rules: - moveable types are passed by value - non-moveable types are passed by const ref Code that receives moveable types by value now passes it to nested methods using std::move(). These changes together allowed to make most setters zero-copy for moveable types, in case if user uses rvalue or std::move(). If the user uses copy ctor, it is usually the only copy made. This is a breaking change: signature of some protected methods that can be overridden by user were changed.
1 parent dc6dddd commit ef992e8

25 files changed

Lines changed: 125 additions & 133 deletions

include/aspl/Compat.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace aspl {
1212

13-
// Backward compatibility macOS before 12.0
13+
// Backward compatibility with macOS before 12.0
1414
#if !defined(MAC_OS_VERSION_12_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0
1515
enum
1616
{

include/aspl/Context.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ struct Context
3737
//! Create context.
3838
//! If dispatcher or tracer is not specified, default one is created.
3939
//! Default tracer sends output to syslog.
40-
explicit Context(const std::shared_ptr<aspl::Tracer>& tracer = {},
41-
const std::shared_ptr<aspl::Dispatcher>& dispatcher = {})
42-
: Dispatcher(dispatcher ? dispatcher : std::make_shared<aspl::Dispatcher>())
43-
, Tracer(tracer ? tracer : std::make_shared<aspl::Tracer>())
40+
explicit Context(std::shared_ptr<aspl::Tracer> tracer = {},
41+
std::shared_ptr<aspl::Dispatcher> dispatcher = {})
42+
: Dispatcher(
43+
dispatcher ? std::move(dispatcher) : std::make_shared<aspl::Dispatcher>())
44+
, Tracer(tracer ? std::move(tracer) : std::make_shared<aspl::Tracer>())
4445
{
4546
}
4647
};

include/aspl/Device.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Device : public Object
167167
{
168168
public:
169169
//! Construct device.
170-
explicit Device(const std::shared_ptr<const Context>& context,
170+
explicit Device(std::shared_ptr<const Context> context,
171171
const DeviceParameters& params = {});
172172

173173
//! @name Getters and setters
@@ -619,7 +619,7 @@ class Device : public Object
619619

620620
//! Add stream to device.
621621
//! Same as AddStreamAsync(Direction), but allows to construct stream manually.
622-
void AddStreamAsync(const std::shared_ptr<Stream>& stream);
622+
void AddStreamAsync(std::shared_ptr<Stream> stream);
623623

624624
//! Remove stream from device.
625625
//! @remarks
@@ -630,7 +630,7 @@ class Device : public Object
630630
//! owned objects asynchronously (when HAL allows it). Hence, GetStreamCount()
631631
//! and GetStreamByIndex() are updated immediately, but GetOwnedObjectIDs(),
632632
//! GetStreamIDs(), etc. are updated some time later.
633-
void RemoveStreamAsync(const std::shared_ptr<Stream>& stream);
633+
void RemoveStreamAsync(std::shared_ptr<Stream> stream);
634634

635635
//! @}
636636

@@ -672,7 +672,7 @@ class Device : public Object
672672
//! Add volume control to device.
673673
//! Same as AddVolumeControlAsync(Direction), but allows to construct control
674674
//! manually.
675-
void AddVolumeControlAsync(const std::shared_ptr<VolumeControl>& control);
675+
void AddVolumeControlAsync(std::shared_ptr<VolumeControl> control);
676676

677677
//! Remove volume control from device.
678678
//! @remarks
@@ -683,7 +683,7 @@ class Device : public Object
683683
//! owned objects asynchronously (when HAL allows it). Hence, GetVolumeControlCount()
684684
//! and GetVolumeControlByIndex() are updated immediately, but GetOwnedObjectIDs(),
685685
//! GetControlIDs(), etc. are updated some time later.
686-
void RemoveVolumeControlAsync(const std::shared_ptr<VolumeControl>& control);
686+
void RemoveVolumeControlAsync(std::shared_ptr<VolumeControl> control);
687687

688688
//! @}
689689

@@ -723,7 +723,7 @@ class Device : public Object
723723

724724
//! Add mute control to device.
725725
//! Same as AddMuteControlAsync(Direction), but allows to construct control manually.
726-
void AddMuteControlAsync(const std::shared_ptr<MuteControl>& control);
726+
void AddMuteControlAsync(std::shared_ptr<MuteControl> control);
727727

728728
//! Remove mute control from device.
729729
//! @remarks
@@ -734,7 +734,7 @@ class Device : public Object
734734
//! owned objects asynchronously (when HAL allows it). Hence, GetMuteControlCount()
735735
//! and GetMuteControlByIndex() are updated immediately, but GetOwnedObjectIDs(),
736736
//! GetControlIDs(), etc. are updated some time later.
737-
void RemoveMuteControlAsync(const std::shared_ptr<MuteControl>& control);
737+
void RemoveMuteControlAsync(std::shared_ptr<MuteControl> control);
738738

739739
//! @}
740740

@@ -744,7 +744,7 @@ class Device : public Object
744744
//! Set handler for control requests.
745745
//! This is optional. You may provide a custom handler if you want to do
746746
//! custom processing or want to inject custom client implementation.
747-
void SetControlHandler(const std::shared_ptr<ControlRequestHandler>& handler);
747+
void SetControlHandler(std::shared_ptr<ControlRequestHandler> handler);
748748

749749
//! Called before new client start I/O with the device.
750750
//! Updates client map and invokes OnAddClient().
@@ -790,7 +790,7 @@ class Device : public Object
790790
//! You need to provide your own implementation if you want your device
791791
//! to actually do something useful. Default implementation is suitable for
792792
//! a null / black hole device.
793-
void SetIOHandler(const std::shared_ptr<IORequestHandler>& handler);
793+
void SetIOHandler(std::shared_ptr<IORequestHandler> handler);
794794

795795
//! Get the current zero time stamp for the device.
796796
//! In default implementation, the zero time stamp and host time are increased
@@ -874,7 +874,7 @@ class Device : public Object
874874
//! If invoked from PerformConfigurationChange(), assumes that we're already
875875
//! at the point where it's safe to change configuration and executes the
876876
//! function immediately.
877-
void RequestConfigurationChange(const std::function<void()>& func = {});
877+
void RequestConfigurationChange(std::function<void()> func = {});
878878

879879
//! Called by the Host to allow the device to perform a configuration change
880880
//! that had been previously requested via a call to the Host method,
@@ -982,8 +982,7 @@ class Device : public Object
982982
//! Invoked by SetAvailableSampleRatesAsync() to actually change the list.
983983
//! Default implementation just updates the list returned by
984984
//! GetAvailableSampleRates().
985-
virtual OSStatus SetAvailableSampleRatesImpl(
986-
const std::vector<AudioValueRange>& rates);
985+
virtual OSStatus SetAvailableSampleRatesImpl(std::vector<AudioValueRange> rates);
987986

988987
//! Set channels for stereo.
989988
//! Invoked by SetPreferredChannelsForStereoAsync() to actually change the value.
@@ -1003,14 +1002,13 @@ class Device : public Object
10031002
//! By default, it also affects values returned by GetPreferredChannelCount() and
10041003
//! GetPreferredChannelLayout().
10051004
virtual OSStatus SetPreferredChannelsImpl(
1006-
const std::vector<AudioChannelDescription>& channels);
1005+
std::vector<AudioChannelDescription> channels);
10071006

10081007
//! Invoked by SetPreferredChannelLayoutAsync() to actually change the value.
10091008
//! Default implementation changes the value returned by GetPreferredChannelLayout().
10101009
//! By default, it also affects values returned by GetPreferredChannelCount() and
10111010
//! GetPreferredChannels().
1012-
virtual OSStatus SetPreferredChannelLayoutImpl(
1013-
const std::vector<UInt8>& channelLayout);
1011+
virtual OSStatus SetPreferredChannelLayoutImpl(std::vector<UInt8> channelLayout);
10141012

10151013
//! Start or stop device identification.
10161014
//! This can be requested by UI, but probably makes little sense to virtual devices.

include/aspl/Dispatcher.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class Dispatcher
4141
public:
4242
//! Construct dispatcher.
4343
//! Use tracer if you want to debug dispatcher itself, it is quite verbose.
44-
Dispatcher(const std::shared_ptr<Tracer> tracer = {},
45-
AudioObjectID hintMaximumID = 1000);
44+
Dispatcher(std::shared_ptr<Tracer> tracer = {}, AudioObjectID hintMaximumID = 1000);
4645

4746
Dispatcher(const Dispatcher&) = delete;
4847
Dispatcher& operator=(const Dispatcher&) = delete;

include/aspl/Driver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class Driver
5555
public:
5656
//! Construct driver.
5757
//! If context or plugin are not set, they are created automatically.
58-
explicit Driver(const std::shared_ptr<Context>& context = {},
59-
const std::shared_ptr<Plugin>& plugin = {});
58+
explicit Driver(std::shared_ptr<Context> context = {},
59+
std::shared_ptr<Plugin> plugin = {});
6060

6161
Driver(const Driver&) = delete;
6262
Driver& operator=(const Driver&) = delete;

include/aspl/MuteControl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MuteControl : public Object
3939
{
4040
public:
4141
//! Construct stream.
42-
explicit MuteControl(const std::shared_ptr<const Context>& context,
42+
explicit MuteControl(std::shared_ptr<const Context> context,
4343
const MuteControlParameters& params = {});
4444

4545
//! @name Getters and setters

include/aspl/Object.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Object : public std::enable_shared_from_this<Object>
5858
//! Class name is used for logging. It should be the name of the derived class.
5959
//! If objectID is @c kAudioObjectUnknown (zero), allocates new object ID.
6060
//! Otherwise uses given object ID.
61-
explicit Object(const std::shared_ptr<const Context>& context,
61+
explicit Object(std::shared_ptr<const Context> context,
6262
const char* className = "Object",
6363
AudioObjectID objectID = kAudioObjectUnknown);
6464

@@ -121,7 +121,7 @@ class Object : public std::enable_shared_from_this<Object>
121121

122122
//! Add object to the list of owned objects.
123123
//! Also invokes SetOwner() on the added object.
124-
void AddOwnedObject(const std::shared_ptr<Object>& object,
124+
void AddOwnedObject(std::shared_ptr<Object> object,
125125
AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal);
126126

127127
//! Remove object to the list of owned objects.
@@ -144,8 +144,7 @@ class Object : public std::enable_shared_from_this<Object>
144144

145145
//! Notify HAL that some properties were changed.
146146
//! This is automatically called by all setters.
147-
void NotifyPropertiesChanged(
148-
const std::vector<AudioObjectPropertySelector>& selectors,
147+
void NotifyPropertiesChanged(std::vector<AudioObjectPropertySelector> selectors,
149148
AudioObjectPropertyScope scope = kAudioObjectPropertyScopeGlobal,
150149
AudioObjectPropertyElement element = kAudioObjectPropertyElementMain) const;
151150

include/aspl/Plugin.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Plugin : public Object
4949
{
5050
public:
5151
//! Construct plugin.
52-
explicit Plugin(const std::shared_ptr<const Context>& context,
52+
explicit Plugin(std::shared_ptr<const Context> context,
5353
const PluginParameters& params = {});
5454

5555
//! @name Getters and setters
@@ -103,11 +103,11 @@ class Plugin : public Object
103103

104104
//! Add device to the plugin.
105105
//! Adds device to the owned object list.
106-
void AddDevice(const std::shared_ptr<Device>& device);
106+
void AddDevice(std::shared_ptr<Device> device);
107107

108108
//! Remove device from the plugin.
109109
//! Removes device from the owned object list.
110-
void RemoveDevice(const std::shared_ptr<Device>& device);
110+
void RemoveDevice(std::shared_ptr<Device> device);
111111

112112
//! @}
113113

include/aspl/Stream.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class Stream : public Object
7777
{
7878
public:
7979
//! Construct stream.
80-
explicit Stream(const std::shared_ptr<const Context>& context,
81-
const std::shared_ptr<Device>& device,
80+
explicit Stream(std::shared_ptr<const Context> context,
81+
std::shared_ptr<Device> device,
8282
const StreamParameters& params = {});
8383

8484
//! @name Getters and setters
@@ -242,11 +242,11 @@ class Stream : public Object
242242

243243
//! Attach volume control to the stream.
244244
//! ApplyProcessing() will use control to apply volume settings to the stream.
245-
void AttachVolumeControl(const std::shared_ptr<VolumeControl>& control);
245+
void AttachVolumeControl(std::shared_ptr<VolumeControl> control);
246246

247247
//! Attach mute control to the stream.
248248
//! ApplyProcessing() will use control to apply mute settings to the stream.
249-
void AttachMuteControl(const std::shared_ptr<MuteControl>& control);
249+
void AttachMuteControl(std::shared_ptr<MuteControl> control);
250250

251251
//! Apply processing to the stream's data.
252252
//! The provided buffer contains exactly @p frameCount * @p channelCount samples.
@@ -266,7 +266,7 @@ class Stream : public Object
266266

267267
//! Request HAL to perform configuration update.
268268
//! Similar to Device::RequestConfigurationChange().
269-
void RequestConfigurationChange(const std::function<void()>& func = {});
269+
void RequestConfigurationChange(std::function<void()> func = {});
270270

271271
//! @}
272272

@@ -353,7 +353,7 @@ class Stream : public Object
353353
//! Default implementation just changes the list returned by
354354
//! GetAvailablePhysicalFormats().
355355
virtual OSStatus SetAvailablePhysicalFormatsImpl(
356-
const std::vector<AudioStreamRangedDescription>& formats);
356+
std::vector<AudioStreamRangedDescription> formats);
357357

358358
//! Set current virtual format of the stream.
359359
//! Invoked by SetVirtualFormatAsync() to actually change the format.
@@ -369,7 +369,7 @@ class Stream : public Object
369369
//! Default implementation just changes the list returned by
370370
//! GetAvailableVirtualFormats().
371371
virtual OSStatus SetAvailableVirtualFormatsImpl(
372-
const std::vector<AudioStreamRangedDescription>& formats);
372+
std::vector<AudioStreamRangedDescription> formats);
373373

374374
//! @}
375375

include/aspl/VolumeControl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class VolumeControl : public Object
6565
{
6666
public:
6767
//! Construct stream.
68-
explicit VolumeControl(const std::shared_ptr<const Context>& context,
68+
explicit VolumeControl(std::shared_ptr<const Context> context,
6969
const VolumeControlParameters& params = {});
7070

7171
//! @name Getters and setters

0 commit comments

Comments
 (0)