MIRA
|
Base class of connections between frameworks. More...
#include <fw/RemoteConnection.h>
Classes | |
class | RPCRemoteFinishHandler |
RPCHandler for getting notified when an rpc call on server side is finished and the response is ready. More... | |
class | RPCRemoteRequestHandler |
RPCHandler for sending a rpc call to the server side. More... | |
struct | SendData |
Public Types | |
typedef std::map< std::string, Typename > | ChannelTypeMap |
typedef std::set< std::string > | StringSet |
typedef std::map< std::string, SendData > | ChannelSendMap |
typedef std::set< std::string > | MetaSet |
typedef std::list< AuthorityDescription > | AuthorityDescriptions |
Public Member Functions | |
virtual | ~RemoteConnection () |
Destructor. More... | |
template<typename Reflector > | |
void | reflect (Reflector &r) |
boost::asio::ip::tcp::socket & | getSocket () |
Returns the network socket of this connection. More... | |
virtual void | start () |
Starts the connection. Can be implemented in derived classes. More... | |
void | stop () |
Close the socket. More... | |
void | onConnect (bool enablePTPTimeSync, bool enablePingTimeout) |
Called by RemoteModule::onIncomingConnected/onOutgoingConnected. More... | |
bool | isPTPSyncEnabled () |
Is synchronization of clocks via PTP enabled? More... | |
bool | isPingTimeoutEnabled () |
Is ping timeout enabled? More... | |
void | startTimeSync () |
Create a timer to frequently call syncTime. More... | |
bool | isSynchronized () const |
synchronizeFrameworks() was executed. More... | |
virtual void | publishChannels (const ChannelTypeMap &channels)=0 |
Notifies the connected framework that we have at least one publisher for each of the channels in the channels map. More... | |
void | unpublishChannel (const std::string &channel) |
Notifies the connected framework that we no longer have a publisher for the given channel. More... | |
virtual void | subscribeChannel (const std::string &channelID, const ServiceLevel &serviceLevel)=0 |
Notify the connected remote frameworks that we have a subscriber for the given channel (assuming it has a publisher for it). More... | |
virtual void | publishAuthorities (const AuthorityDescriptions &authorities)=0 |
Notifies the connected framework that the authorities in the authorities map exist in our framework. More... | |
virtual void | unpublishAuthorities (const AuthorityDescriptions &authorities)=0 |
Notifies the connected framework that the authorities in the authorities map do not longer exist in our framework. More... | |
void | migrateUnit (const std::string &id) |
Send a request to the connected framework to transfer ownership of a unit to this framework. More... | |
bool | hasAuthority (const std::string &id) const |
Check if a authority with given full id exists in the connected framework. More... | |
virtual void | publishServices (const StringSet &services)=0 |
Notifies the connected framework that the services in the services set exist in our framework. More... | |
virtual void | unpublishServices (const StringSet &services)=0 |
Notifies the connected framework that the services in the services set do not longer exist in our framework. More... | |
template<typename BufferSequence > | |
void | write (const BufferSequence &buffers) |
Send data in the buffers to the connected framework. More... | |
UUID | getRemoteID () const |
std::string | getGlobalID () const |
void | setAuthority (std::unique_ptr< Authority > auth) |
const std::string & | getFrameworkID () const |
const KnownFramework & | getAddress () const |
void | setAddress (const KnownFramework &addr) |
void | setAutoReconnect (bool autoReconnect) |
Class const & | getClass () const |
call the virtual internalGetClass(). More... | |
Static Public Member Functions | |
static PseudoClass const & | CLASS () |
Protected Types | |
enum | AuthState { AUTHSTATE_NONE, AUTHSTATE_CONNECTING, AUTHSTATE_AUTHENTICATING, AUTHSTATE_ACCEPTED, AUTHSTATE_DENIED } |
typedef std::pair< FrameworkMessageType, Buffer< uint8 > > | RPCMessage |
Protected Member Functions | |
RemoteConnection () | |
Constructs a remote connection that uses its own io service. More... | |
RemoteConnection (boost::asio::io_service &service) | |
Constructs a remote connection that uses a given io service. More... | |
virtual void | onDisconnect () |
Called in stop() when connection is about to be stopped. More... | |
virtual void | onWriteError (boost::system::system_error &e) |
Called when writing to the socket failed. Can be implemented in derived classes. More... | |
void | syncTime () |
Time synchronization between frameworks. More... | |
void | sendPTP () |
Sends a PTP command used for time synchronization between frameworks. More... | |
void | ping () |
Sends a ping command. More... | |
bool | hasPingTimeout () const |
Check if the connection incoming ping's are still alive. More... | |
void | writeMessage (FrameworkMessageType msg) |
Writes a message to the other framework. More... | |
template<typename Arg , typename... Args> | |
void | writeMessage (FrameworkMessageType msg, Arg &&arg, Args &&... args) |
Writes a message to the other framework. More... | |
template<typename BufferType > | |
void | writeMessageFromBuffer (FrameworkMessageType msg, const BufferType &buffer) |
Writes a message to the other framework. More... | |
template<typename DataType > | |
void | writeMessageFromData (FrameworkMessageType msg, const DataType &data) |
Writes a message to the other framework. More... | |
void | queueRPCMessage (FrameworkMessageType msg, Buffer< uint8 > &&answer) |
Queue an outgoing RPC request or RPC response to be transmitted in a separate thread. More... | |
void | valueChanged (ChannelRead< void > value, ServiceLevel &serviceLevel) |
Channel callback method that gets registered on each channel the connected framework subscribes. More... | |
void | parseMessage () |
Parses an incoming message (stored in mMessage) and calls the respective receivedXXX method. More... | |
void | receivedPTPFollowUp (uint64 timestamp) |
void | receivedPTPDelayResponse (uint64 timestamp) |
void | receivedPTPDelayRequest (uint64 timestamp) |
void | receivedPTPFinish () |
void | receivedSubscribeChannelRequest () |
void | receivedUnsubscribeChannelRequest (const std::string &channelID) |
void | receivedPublishChannelMsg () |
void | receivedUnpublishChannelMsg () |
void | receivedPublishAuthorityMsg () |
void | receivedUnpublishAuthorityMsg () |
virtual void | receivedPublishServiceMsg ()=0 |
void | receivedUnpublishServiceMsg () |
void | receivedWriteChannelMsg () |
virtual void | receivedRPCRequestMsg ()=0 |
virtual void | receivedRPCResponseMsg ()=0 |
void | receivedRequestMigrationMsg () |
void | receivedMigrationMsg () |
void | receivedMigrationSinkSuccessMsg () |
void | receivedMigrationSinkFailureMsg () |
void | receivedMigrationFinishedMsg () |
void | receivedTypeMetaMsg () |
void | receivedChannelMetaMsg () |
void | receivedPingMsg () |
virtual void | sendData (ChannelRead< void > value, ServiceLevel &serviceLevel) |
virtual int | addBinaryFormatVersion (Buffer< uint8 > &data)=0 |
void | synchronizeFrameworks () |
void | updateOutgoingStats (std::size_t size) |
bool | checkMessageHeader () const |
Returns true, if the message (header) is valid, i.e. More... | |
void | sendConnectDenied (const std::string &msg) |
void | sendRPCMessagesThread () |
void | processPingThread () |
void | checkPingTimeoutThread () |
void | sendChannelUpdatesThread () |
virtual Class const & | internalGetClass () const =0 |
Protected Attributes | |
KnownFramework | address |
The address of the connected framework. More... | |
UUID | remoteID |
The UUID of the connected framework. More... | |
std::string | frameworkID |
The ID/Name of the connected framework. More... | |
uint32 | remoteVersion |
The protocol version of the connected framework. More... | |
std::unique_ptr< Authority > | authority |
Our authority used for subscribing to data. More... | |
ChannelSendMap | subscriptions |
List of channels the connected framework is subscribed to + what was sent to them. More... | |
MetaSet | sentMetaInformation |
Set of type meta information already sent. More... | |
StringSet | publishedServices |
List of services of the connected framework. More... | |
Time | synchronizedTime |
Time when the connection was fully established (e.g. PTP synchronized) More... | |
bool | mEnablePTPSync |
PTP Sync enabled for this connection? More... | |
bool | mEnablePingTimeout |
Ping timeout enabled for this connection? More... | |
TimeOffsetCompensation | clockOffset |
The clock offset between us and the connected framework. More... | |
IOService | mService |
boost::asio::ip::tcp::socket | mSocket |
boost::condition_variable | mRPCMessagesCondition |
boost::mutex | mWriteMutex |
boost::mutex | mStopMutex |
TimerPtr | mSyncTimeTimer |
boost::thread | mSendRPCMessagesThread |
boost::thread | mProcessPingThread |
boost::thread | mCheckPingTimeoutThread |
boost::thread | mSendChannelUpdatesThread |
Time | mHeaderReceived |
FrameworkMessageHeader | mHeader |
Buffer< uint8 > | mMessage |
AuthState | mAuthState |
std::string | mAuthSignMsg |
bool | mPTPOutgoing |
Time | mPTPSyncLocal |
Time | mPTPSyncRemote |
Time | mPTPDelayLocal |
Time | mPTPDelayRemote |
Time | mLastPTP |
Time | mPingLastSend |
Time | mPingLastReceived |
boost::shared_ptr< MicroUnit > | mMigrationUnit |
std::string | mMigrationNS |
std::string | mMigrationID |
bool | mStopped |
boost::shared_ptr< RPCRemoteFinishHandler > | mRPCFinishHandler |
boost::shared_ptr< RPCRemoteRequestHandler > | mRPCRequestHandler |
std::map< std::string, boost::shared_ptr< RemoteAuthority > > | mRemoteAuthorities |
std::list< RPCMessage > | mOutgoingRPCMessages |
boost::mutex | mRPCMessagesMutex |
std::unordered_map< std::string, ServiceLevel > | mPendingChannelUpdates |
boost::mutex | mChannelUpdatesMutex |
Base class of connections between frameworks.
If PTP synchronization is enabled for a connection, the protocol for establishing a time sync (determining a time offset) between two connected frameworks is as follows:
If PTP synchronization is not enabled, the PUBLISH_CHANNEL/SERVICE/AUTHORITY_MSG messages are sent immediately.
typedef std::map<std::string, Typename> ChannelTypeMap |
typedef std::set<std::string> StringSet |
typedef std::map<std::string, SendData> ChannelSendMap |
typedef std::set<std::string> MetaSet |
typedef std::list<AuthorityDescription> AuthorityDescriptions |
|
protected |
|
protected |
|
protected |
Constructs a remote connection that uses its own io service.
run()/runThreads() must be called on the service by the subclass!
|
protected |
Constructs a remote connection that uses a given io service.
run()/runThreads() must be called on the service by the owner!
|
virtual |
Destructor.
|
inline |
|
inline |
Returns the network socket of this connection.
|
virtual |
Starts the connection. Can be implemented in derived classes.
Reimplemented in RemoteOutgoingConnectionBase, and RemoteIncomingConnection.
void stop | ( | ) |
Close the socket.
void onConnect | ( | bool | enablePTPTimeSync, |
bool | enablePingTimeout | ||
) |
Called by RemoteModule::onIncomingConnected/onOutgoingConnected.
Provides the RemoteModule settings for enabling PTP sync and ping timeout, which should be kept by the RemoteConnection through its lifetime.
|
inline |
Is synchronization of clocks via PTP enabled?
|
inline |
Is ping timeout enabled?
void startTimeSync | ( | ) |
Create a timer to frequently call syncTime.
Time sync must be completed at least once before data is transmitted (if ping timeout is enabled in the RemoteModule, time sync is automatically done in the ping thread and the timer should not be created).
|
inline |
synchronizeFrameworks() was executed.
The connection is fully established, time was synchronized at least once (if enabled and required) and authorities/channels/services have been published to the remote framework (unless monitor-only).
|
pure virtual |
Notifies the connected framework that we have at least one publisher for each of the channels in the channels map.
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
void unpublishChannel | ( | const std::string & | channel | ) |
Notifies the connected framework that we no longer have a publisher for the given channel.
|
pure virtual |
Notify the connected remote frameworks that we have a subscriber for the given channel (assuming it has a publisher for it).
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
pure virtual |
Notifies the connected framework that the authorities in the authorities map exist in our framework.
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
pure virtual |
Notifies the connected framework that the authorities in the authorities map do not longer exist in our framework.
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
void migrateUnit | ( | const std::string & | id | ) |
Send a request to the connected framework to transfer ownership of a unit to this framework.
bool hasAuthority | ( | const std::string & | id | ) | const |
Check if a authority with given full id exists in the connected framework.
|
pure virtual |
Notifies the connected framework that the services in the services set exist in our framework.
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
pure virtual |
Notifies the connected framework that the services in the services set do not longer exist in our framework.
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
inline |
Send data in the buffers to the connected framework.
[in] | buffers | The data to send |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotectedvirtual |
Called in stop() when connection is about to be stopped.
Can be implemented in derived classes.
Reimplemented in RemoteOutgoingConnectionBase, and RemoteIncomingConnection.
|
inlineprotectedvirtual |
Called when writing to the socket failed. Can be implemented in derived classes.
Reimplemented in RemoteOutgoingConnectionBase.
|
protected |
Time synchronization between frameworks.
For local connected frameworks the method synchronizeFrameworks will be called. For frameworks on remote hosts sendPTP will be called.
|
protected |
Sends a PTP command used for time synchronization between frameworks.
|
protected |
Sends a ping command.
This method ensures, that the ping is not send more than the configured interval in the RemoteModule.
|
protected |
Check if the connection incoming ping's are still alive.
|
inlineprotected |
Writes a message to the other framework.
This method takes just the message type.
|
inlineprotected |
Writes a message to the other framework.
This method takes the message type and a variable number of parameters that are sent within the message.
|
inlineprotected |
Writes a message to the other framework.
Instead of writing parameters into a buffer for generating the message, this method expects a buffer as parameter directly, e.g. created by serializing data.
|
inlineprotected |
Writes a message to the other framework.
Instead of writing the parameter into a buffer for generating the message, (as writeMessage does), this method uses the parameter memory location directly.
|
protected |
Queue an outgoing RPC request or RPC response to be transmitted in a separate thread.
msg must be either RPC_RESPONSE_MSG or RPC_REQUEST_MSG
|
protected |
Channel callback method that gets registered on each channel the connected framework subscribes.
When data in the channel changes it is sent to the connected framework.
|
protected |
Parses an incoming message (stored in mMessage) and calls the respective receivedXXX method.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedpure virtual |
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
protected |
|
protected |
|
protectedpure virtual |
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
protectedpure virtual |
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
inlineprotectedvirtual |
Reimplemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
protectedpure virtual |
Implemented in ConcreteRemoteConnection< BinaryFormatVersion >, and ConcreteRemoteConnection< 2 >.
|
protected |
|
protected |
|
protected |
Returns true, if the message (header) is valid, i.e.
if the specified message length does not exceed a max size and the message type is known. This is used to prevent Denial of Service attacks.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
inlineinherited |
call the virtual internalGetClass().
|
inlinestaticinherited |
|
protectedpure virtualinherited |
|
protected |
The address of the connected framework.
|
protected |
The UUID of the connected framework.
|
protected |
The ID/Name of the connected framework.
|
protected |
The protocol version of the connected framework.
|
protected |
Our authority used for subscribing to data.
|
protected |
List of channels the connected framework is subscribed to + what was sent to them.
|
protected |
Set of type meta information already sent.
|
protected |
List of services of the connected framework.
|
protected |
Time when the connection was fully established (e.g. PTP synchronized)
|
protected |
PTP Sync enabled for this connection?
|
protected |
Ping timeout enabled for this connection?
|
protected |
The clock offset between us and the connected framework.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |