libASPL
Loading...
Searching...
No Matches
ControlRequestHandler.hpp
Go to the documentation of this file.
1// Copyright (c) libASPL authors
2// Licensed under MIT
3
4//! @file aspl/ControlRequestHandler.hpp
5//! @brief Handler for control requests to device.
6
7#pragma once
8
9#include <aspl/Client.hpp>
10
11#include <CoreAudio/AudioHardwareBase.h>
12
13#include <memory>
14
15namespace aspl {
16
17//! Handler for control requests to device.
18//!
19//! You may subclass this class if you want to implement custom handling or
20//! inject custom Client implementation.
22{
23public:
24 ControlRequestHandler() = default;
25
27 ControlRequestHandler& operator=(const ControlRequestHandler&) = delete;
28
29 virtual ~ControlRequestHandler() = default;
30
31 //! @name Start / stop
32 //! @{
33
34 //! Invoked by Device when the very first client wants to start I/O.
35 //! If desired, may block to perform all necessary initialization.
36 //! If error is returned, device reports error to clients.
37 //! After this call, StopIO() will invoked eventually.
38 //! After that, StartIO() may be called again.
39 virtual OSStatus OnStartIO()
40 {
41 return kAudioHardwareNoError;
42 }
43
44 //! Invoked by Device when the last client has stopped I/O.
45 //! After this call, StartIO() may be called again.
46 virtual void OnStopIO()
47 {
48 }
49
50 //! @}
51
52 //! @name Clients
53 //! @{
54
55 //! Invoked by Device when a new client attaches to it.
56 //! Override to handle client creation.
57 //! Should construct a Client bases on provided ClientInfo.
58 virtual std::shared_ptr<Client> OnAddClient(const ClientInfo& clientInfo)
59 {
60 return std::make_shared<Client>(clientInfo);
61 }
62
63 //! Invoked by Device when a client detaches from it.
64 //! Override to handle client removal.
65 //! The provided shared pointer is the last reference to the client.
66 virtual void OnRemoveClient(std::shared_ptr<Client> client)
67 {
68 }
69
70 //! @}
71};
72
73} // namespace aspl
Client.
Handler for control requests to device.
virtual OSStatus OnStartIO()
Invoked by Device when the very first client wants to start I/O. If desired, may block to perform all...
virtual void OnRemoveClient(std::shared_ptr< Client > client)
Invoked by Device when a client detaches from it. Override to handle client removal....
virtual std::shared_ptr< Client > OnAddClient(const ClientInfo &clientInfo)
Invoked by Device when a new client attaches to it. Override to handle client creation....
virtual void OnStopIO()
Invoked by Device when the last client has stopped I/O. After this call, StartIO() may be called agai...
Information about client.
Definition Client.hpp:19