gramods
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
gramods::gmNetwork::Protocol Class Reference

TODO: write this. More...

#include <Protocol.hh>

Inheritance diagram for gramods::gmNetwork::Protocol:
Inheritance graph
[legend]
Collaboration diagram for gramods::gmNetwork::Protocol:
Collaboration graph
[legend]

Classes

struct  Message
 Data entity communicated by the connection to the designated protocol. More...
 

Public Member Functions

virtual char getProtocolFlag ()
 Returns the byte sent in the message to indicate which protocol instance to call for interpretation and processing. More...
 
virtual void processMessage (Message m)
 Called by the sync node when data with this protocols flag has been received. 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)
 

Static Public Attributes

static const size_t HEADER_LENGTH = Message().getHeader().size()
 

Protected Member Functions

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...
 

Protected Attributes

SyncNodesync_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...
 

Detailed Description

TODO: write this.

Member Function Documentation

◆ getConnectedPeers()

std::set< size_t > gramods::gmNetwork::Protocol::getConnectedPeers ( )
protected

Convenience method for quering the SyncNode for the currently connected peers.

◆ getLocalPeerIdx()

size_t gramods::gmNetwork::Protocol::getLocalPeerIdx ( )
protected

Convenience method for quering the SyncNode for the local peer idx.

This will throw gmCore::PreConditionViolation exception if there is no SyncNode instance to get local peer idx from.

◆ getProtocolFlag()

virtual char gramods::gmNetwork::Protocol::getProtocolFlag ( )
inlinevirtual

Returns the byte sent in the message to indicate which protocol instance to call for interpretation and processing.

Values 0-127 are reserved for internal protocols while values 128-255 may be used by application specific protocols.

Reimplemented in gramods::gmNetwork::RunSync, and gramods::gmNetwork::DataSync.

◆ lostPeer()

void gramods::gmNetwork::Protocol::lostPeer ( size_t  idx)
virtual

Called by the sync node when connection to one of the peers has been broken.

Reimplemented in gramods::gmNetwork::RunSync.

◆ processMessage()

void gramods::gmNetwork::Protocol::processMessage ( Message  m)
virtual

Called by the sync node when data with this protocols flag has been received.

The message is complete, as sent by the peer.

It should be assumed that the call is made from a non-main thread. Also, the method should return promptly and leave heavy processing to either another worker thread or to the main thread.

Reimplemented in gramods::gmNetwork::RunSync, and gramods::gmNetwork::DataSync.

◆ sendMessage()

void gramods::gmNetwork::Protocol::sendMessage ( std::vector< char >  data)
protected

Convenience method for creating a message and sending this to all peers.

Member Data Documentation

◆ sync_node

SyncNode* gramods::gmNetwork::Protocol::sync_node
protected

The SyncNode instance this protocol communicates through or nullptr if it has gone out of scope.

Use sync_node_lock to avoid race condition on this pointer.

◆ sync_node_lock

std::mutex gramods::gmNetwork::Protocol::sync_node_lock
protected

Lock for synchronizing the sync_node pointer.


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