18#ifndef NET_STACK_MEMORY_MANAGER_H
19#define NET_STACK_MEMORY_MANAGER_H
53typedef void net_stack_mem_buf_t;
78 virtual net_stack_mem_buf_t *
alloc_heap(uint32_t size, uint32_t align) = 0;
91 virtual net_stack_mem_buf_t *
alloc_pool(uint32_t size, uint32_t align) = 0;
106 net_stack_mem_buf_t *
realloc_heap(net_stack_mem_buf_t *orig_buf, uint32_t new_align, std::optional<uint32_t> new_len = std::nullopt, std::optional<uint16_t> new_header_skip_size = std::nullopt);
128 return MBED_CONF_NSAPI_EMAC_RX_POOL_NUM_BUFS;
139 virtual void free(net_stack_mem_buf_t *buf) = 0;
162 virtual void copy_to_buf(net_stack_mem_buf_t *to_buf,
const void *ptr, uint32_t len);
175 virtual uint32_t
copy_from_buf(
void *ptr, uint32_t len,
const net_stack_mem_buf_t *from_buf)
const;
189 virtual void cat(net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf) = 0;
199 virtual net_stack_mem_buf_t *
get_next(
const net_stack_mem_buf_t *buf)
const = 0;
210 while (buf !=
nullptr) {
225 virtual void *
get_ptr(
const net_stack_mem_buf_t *buf)
const = 0;
235 virtual uint32_t
get_len(
const net_stack_mem_buf_t *buf)
const = 0;
256 virtual void set_len(net_stack_mem_buf_t *buf, uint32_t len) = 0;
virtual uint32_t get_pool_alloc_unit(uint32_t align) const =0
Get memory buffer pool allocation unit.
virtual int32_t get_header_skip_size(net_stack_mem_buf_t *buf)=0
Get the total number of header bytes that are currently being skipped.
virtual void copy_to_buf(net_stack_mem_buf_t *to_buf, const void *ptr, uint32_t len)
Copy from a raw buffer in memory to a memory buffer chain.
virtual net_stack_mem_buf_t * alloc_pool(uint32_t size, uint32_t align)=0
Allocates memory buffer chain from a pool.
virtual void cat(net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf)=0
Concatenate two memory buffer chains.
uint32_t get_pool_size()
Get memory buffer pool size.
virtual uint32_t copy_from_buf(void *ptr, uint32_t len, const net_stack_mem_buf_t *from_buf) const
Copy from a memory buffer chain to a raw buffer in memory.
virtual net_stack_mem_buf_t * alloc_heap(uint32_t size, uint32_t align)=0
Allocates memory buffer from the heap.
net_stack_mem_buf_t * realloc_heap(net_stack_mem_buf_t *orig_buf, uint32_t new_align, std::optional< uint32_t > new_len=std::nullopt, std::optional< uint16_t > new_header_skip_size=std::nullopt)
Reallocates a buffer or buffer chain as a contiguous (non-chained) heap buffer, freeing the original.
virtual void * get_ptr(const net_stack_mem_buf_t *buf) const =0
Return pointer to the payload of the buffer.
virtual uint32_t get_len(const net_stack_mem_buf_t *buf) const =0
Return payload size of this individual buffer (NOT including any chained buffers)
virtual void free(net_stack_mem_buf_t *buf)=0
Free memory buffer chain.
@ HEAP_ALLOCATED
Allocated from the memory manager's heap.
@ VOLATILE
Buffer points to data from the application that will not live past the current network stack call.
@ CONSTANT
Buffer points to constant data (e.g. in ROM) that will live forever.
@ POOL_ALLOCATED
Allocated from the memory manager's pool.
virtual void skip_header_space(net_stack_mem_buf_t *buf, int32_t amount)=0
Skips (or un-skips) header space from the buffer.
void restore_header_space(net_stack_mem_buf_t *buf, const int32_t amount)
Restores previously skipped header space to the buffer.
virtual net_stack_mem_buf_t * get_next(const net_stack_mem_buf_t *buf) const =0
Returns the next buffer.
virtual Lifetime get_lifetime(net_stack_mem_buf_t const *buf) const =0
Gets the lifetime of the buffer.
mbed::Callback< void()> onPoolSpaceAvailCallback
Callback which shall be called (if set) by the implementation after one or more buffer spaces become ...
size_t count_buffers(const net_stack_mem_buf_t *buf)
Count the number of buffers in a buffer chain.
void set_on_pool_space_avail_cb(mbed::Callback< void()> cb)
Set callback which will be called when pool space becomes available.
virtual void set_len(net_stack_mem_buf_t *buf, uint32_t len)=0
Sets the payload size of the buffer.
virtual uint32_t get_total_len(const net_stack_mem_buf_t *buf) const =0
Return total length of a memory buffer chain.
Callback class based on template specialization.