mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value > Class Template Reference

A wrapper class for synchronizing and processing data. More...

Inheritance diagram for mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >:
[legend]
Collaboration diagram for mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >:
[legend]

Public Member Functions

 SynchronizationWrapper (boost::asio::io_context &context, std::function< void(std::vector< Value > &)> fn)
 Constructor for the SynchronizationWrapper class.
 
void push (Value &&value)
 Pushes a value into the queue for asynchronous processing.
 
void push (Value &&value)
 
bool has_data ()
 Checks if there is data available for processing.
 
std::future< boolcreate_pop_task ()
 Creates a task to asynchronously process the enqueued data.
 

Private Attributes

boost::asio::io_context::strand strand_
 
std::atomic_flag synchronization_flag_
 
std::function< void(std::vector< Value > &)> dequeue_function_
 
std::vector< Value > input_data_
 

Detailed Description

template<typename Value>
class mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >

A wrapper class for synchronizing and processing data.

This class provides a thread-safe mechanism for pushing data into a queue, and asynchronously processing them using a provided processing function.

Template Parameters
ValueThe type of the data.

Definition at line 56 of file packet-dispatcher.hpp.

Constructor & Destructor Documentation

◆ SynchronizationWrapper()

template<typename Value >
mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::SynchronizationWrapper ( boost::asio::io_context & context,
std::function< void(std::vector< Value > &)> fn )
inline

Constructor for the SynchronizationWrapper class.

Parameters
contextThe Boost Asio io_context to be used for strand synchronization.
fnA function that processes a vector of key-value pairs.

Definition at line 65 of file packet-dispatcher.hpp.

Member Function Documentation

◆ create_pop_task()

template<typename Value >
std::future< bool > mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::create_pop_task ( )
inline

Creates a task to asynchronously process the enqueued data.

This function creates a task that processes the enqueued data using the processing function. The promise is set to true if data was processed, and false otherwise.

Returns
A std::future<bool> indicating the result of data processing.

Definition at line 116 of file packet-dispatcher.hpp.

◆ has_data()

template<typename Value >
bool mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::has_data ( )
inline

Checks if there is data available for processing.

Returns
true if data is available, false otherwise.

Definition at line 105 of file packet-dispatcher.hpp.

◆ push() [1/2]

template<typename Value >
void mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::push ( Value && value)
inline

Pushes a value into the queue for asynchronous processing.

The value is enqueued for processing by the processing function. The synchronization flag is set to indicate the availability of data.

Parameters
keyThe key to be pushed.

Definition at line 77 of file packet-dispatcher.hpp.

Here is the caller graph for this function:

◆ push() [2/2]

template<typename Value >
void mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::push ( Value && value)
inline

Definition at line 87 of file packet-dispatcher.hpp.

Member Data Documentation

◆ dequeue_function_

template<typename Value >
std::function<void(std::vector<Value> &)> mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::dequeue_function_
private

Function that processes the input data

Definition at line 140 of file packet-dispatcher.hpp.

◆ input_data_

template<typename Value >
std::vector<Value> mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::input_data_
private

Queue for storing the data

Definition at line 141 of file packet-dispatcher.hpp.

◆ strand_

template<typename Value >
boost::asio::io_context::strand mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::strand_
private

Synchronization strand.

Definition at line 138 of file packet-dispatcher.hpp.

◆ synchronization_flag_

template<typename Value >
std::atomic_flag mal_packet_weaver::PacketDispatcher::SynchronizationWrapper< Value >::synchronization_flag_
private

Atomic flag indicating updates to the data_

Definition at line 139 of file packet-dispatcher.hpp.


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