Dynamically allocates and registers Handler instances for ephemeral transfer resources.
The resource_id is dynamically assigned and registered with the TransferService on creation and wrapped in a TransferResource. It is unregistered and deallocated when the TransferResource is destroyed or closed.
A range of resource IDs can be specified to allocate from. The range must be between 1 and std::numeric_limits<uint32_t>::max() - 1 inclusive.
Takes a pw::Allocator to allocate memory for the Handler instances and the list tracking active handlers.
Public Member Functions | |
| TransferHandlerAllocator (TransferService &transfer_service, Allocator &allocator, uint32_t min_resource_id=1, uint32_t max_resource_id=std::numeric_limits< uint32_t >::max() - 1) | |
| Result< TransferResource > | AllocateReader (stream::Reader &reader) |
| Result< TransferResource > | AllocateWriter (stream::Writer &writer) |
| Result< TransferResource > | AllocateReadWriter (stream::ReaderWriter &reader_writer) |
Static Public Member Functions | |
| static constexpr size_t | GetAllocatorSize (size_t max_handlers, size_t allocator_block_overhead) |
Friends | |
| class | TransferResource |
|
inline |
Constructs a TransferHandlerAllocator bound to transfer_service.
| [in] | transfer_service | Service with which allocated handlers are registered. |
| [in] | allocator | Memory allocator used for handlers and tracking entries. |
| [in] | min_resource_id | Minimum resource ID to assign (inclusive). |
| [in] | max_resource_id | Maximum resource ID to assign (inclusive). |
min_resource_id != 0, max_resource_id >= min_resource_id, and max_resource_id < std::numeric_limits<uint32_t>::max(). | Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateReader | ( | stream::Reader & | reader | ) |
Allocates and registers a ReadOnlyHandler for the given reader.
| [in] | reader | Stream from which transfer data will be read. |
TransferResource handle for the registered handler on success or one of the following error codes on failure:TransferService. | Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateReadWriter | ( | stream::ReaderWriter & | reader_writer | ) |
Allocates and registers a ReadWriteHandler for the given reader_writer.
| [in] | reader_writer | Stream used for both reading and writing. |
TransferResource handle for the registered handler on success or one of the following error codes on failure:TransferService. | Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateWriter | ( | stream::Writer & | writer | ) |
Allocates and registers a WriteOnlyHandler for the given writer.
| [in] | writer | Stream to which transfer data will be written. |
TransferResource handle for the registered handler on success or one of the following error codes on failure:TransferService.
|
inlinestaticconstexpr |
Calculates the allocator buffer size needed to support max_handlers concurrent handlers.
| [in] | max_handlers | Maximum number of concurrent active handlers. |
| [in] | allocator_block_overhead | Per-allocation overhead in bytes for the backing pw::Allocator (e.g. SmallBlock::kBlockOverhead). |