gramods
|
Synchronization of simple data, such as boolean, float or integer values, over network. More...
#include <DataSync.hh>
Classes | |
struct | Impl |
Public Member Functions | |
void | addData (std::shared_ptr< SyncData > d) |
Adds a data container to be synchronized by the instance. More... | |
void | addData (SyncData *d) |
Adds a data container to be synchronized by the instance. More... | |
void | update () |
Exchanges old data with newly received data in all associated data containers. More... | |
void | processMessage (Message m) override |
Receives data values and sets the associated container. More... | |
void | send (SyncData *d) |
Synchronizes the specified data object. More... | |
char | getProtocolFlag () override |
Returns the header byte associated with the protocol, sent in the header of messages to indicate which protocol instance to call for interpretation and processing. More... | |
![]() | |
virtual void | lostPeer (size_t idx) |
Called by the sync node when connection to one of the peers has been broken. More... | |
void | setSyncNode (SyncNode *sync_node) |
Additional Inherited Members | |
![]() | |
static const size_t | HEADER_LENGTH = Message().getHeader().size() |
![]() | |
void | sendMessage (std::vector< char > data) |
Convenience method for creating a message and sending this to all peers. More... | |
size_t | getLocalPeerIdx () |
Convenience method for quering the SyncNode for the local peer idx. More... | |
std::set< size_t > | getConnectedPeers () |
Convenience method for quering the SyncNode for the currently connected peers. More... | |
![]() | |
SyncNode * | sync_node |
The SyncNode instance this protocol communicates through or nullptr if it has gone out of scope. More... | |
std::mutex | sync_node_lock |
Lock for synchronizing the sync_node pointer. More... | |
Synchronization of simple data, such as boolean, float or integer values, over network.
OBSERVE: The data sharing currently assumes, but does not test, that the peers have the same endianness.
The data synchronization applies these principles:
Global variables:
Initialize:
Use:
void gramods::gmNetwork::DataSync::addData | ( | std::shared_ptr< SyncData > | d | ) |
Adds a data container to be synchronized by the instance.
Subsequently setting the value of the specified container will send that value to the connected peers, and a received value will be set. Call update to make received values current.
Observe that all connected peers must have the exact same associated data containers.
void gramods::gmNetwork::DataSync::addData | ( | SyncData * | d | ) |
Adds a data container to be synchronized by the instance.
Subsequently setting the value of the specified container will send that value to the connected peers, and a received value will be set. Call update to make received values current.
Observe that all connected peers must have the exact same associated data containers.
WARNING: the caller MUST make sure that the pointer is valid during the lifetime of this object.
|
inlineoverridevirtual |
Returns the header byte associated with the protocol, sent in the header of messages to indicate which protocol instance to call for interpretation and processing.
Reimplemented from gramods::gmNetwork::Protocol.
|
overridevirtual |
Receives data values and sets the associated container.
Reimplemented from gramods::gmNetwork::Protocol.
void gramods::gmNetwork::DataSync::send | ( | SyncData * | d | ) |
Synchronizes the specified data object.
This method is automatically called when the value of a SyncData is set and should not be used by client code.
void gramods::gmNetwork::DataSync::update | ( | ) |
Exchanges old data with newly received data in all associated data containers.