Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Comms
  5. pw_transfer
  6. pw::transfer::TransferHandlerAllocator Class Reference
Loading...
Searching...
No Matches
pw::transfer::TransferHandlerAllocator Class Reference

Overview

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
 

Constructor & Destructor Documentation

◆ TransferHandlerAllocator()

pw::transfer::TransferHandlerAllocator::TransferHandlerAllocator ( TransferService &  transfer_service,
Allocator &  allocator,
uint32_t  min_resource_id = 1,
uint32_t  max_resource_id = std::numeric_limits<uint32_t>::max() - 1 
)
inline

Constructs a TransferHandlerAllocator bound to transfer_service.

Parameters
[in]transfer_serviceService with which allocated handlers are registered.
[in]allocatorMemory allocator used for handlers and tracking entries.
[in]min_resource_idMinimum resource ID to assign (inclusive).
[in]max_resource_idMaximum resource ID to assign (inclusive).
Precondition
min_resource_id != 0, max_resource_id >= min_resource_id, and max_resource_id < std::numeric_limits<uint32_t>::max().

Member Function Documentation

◆ AllocateReader()

Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateReader ( stream::Reader &  reader)

Allocates and registers a ReadOnlyHandler for the given reader.

Parameters
[in]readerStream from which transfer data will be read.
Returns
A Result containing a TransferResource handle for the registered handler on success or one of the following error codes on failure:

◆ AllocateReadWriter()

Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateReadWriter ( stream::ReaderWriter &  reader_writer)

Allocates and registers a ReadWriteHandler for the given reader_writer.

Parameters
[in]reader_writerStream used for both reading and writing.
Returns
A Result containing a TransferResource handle for the registered handler on success or one of the following error codes on failure:

◆ AllocateWriter()

Result< TransferResource > pw::transfer::TransferHandlerAllocator::AllocateWriter ( stream::Writer &  writer)

Allocates and registers a WriteOnlyHandler for the given writer.

Parameters
[in]writerStream to which transfer data will be written.
Returns
A Result containing a TransferResource handle for the registered handler on success or one of the following error codes on failure:

◆ GetAllocatorSize()

static constexpr size_t pw::transfer::TransferHandlerAllocator::GetAllocatorSize ( size_t  max_handlers,
size_t  allocator_block_overhead 
)
inlinestaticconstexpr

Calculates the allocator buffer size needed to support max_handlers concurrent handlers.

Parameters
[in]max_handlersMaximum number of concurrent active handlers.
[in]allocator_block_overheadPer-allocation overhead in bytes for the backing pw::Allocator (e.g. SmallBlock::kBlockOverhead).
Returns
Required allocator capacity in bytes.

The documentation for this class was generated from the following file: