#include <ddtDataTransferLib.hpp>
Public Types | |
| enum class | ConnectionState { Disconnected = 0 , Connected , Reconnecting , PublisherDisconnected } |
| using | ConnectionStateSignalT = boost::signals2::signal<void(ConnectionState)> |
Public Member Functions | |
| DdtDataTransferLib (DdtLogger *ddt_logger) | |
| DdtDataTransferLib (log4cplus::Logger const &log4cplus_logger) | |
| virtual | ~DdtDataTransferLib () |
| void | SetQoS (const int ddt_latency, const int ddt_deadline) |
| const std::string | VerifyPathInBrokerUri (std::string broker_uri) |
| int | InitMAL (const std::string broker_uri) |
| std::unique_ptr< datatransfer::DataBrokerRegistrationSync, std::default_delete< datatransfer::DataBrokerRegistrationSync > > | GetBrokerClient () |
| virtual int | RegisterPublisher (const std::string uri, const std::string dsi, const bool compute_crc) |
| virtual int | UnregisterPublisher () |
| virtual void | PublishData () |
| virtual int | RegisterSubscriber (const std::string uri, const std::string dsi, const std::string remote_uri, const int32_t interval=10) |
| virtual int | UnregisterSubscriber () |
| virtual DataSample * | ReadData () |
| boost::signals2::connection | ConnectToConnectionState (const std::function< void(ConnectionState)> &callback) |
Protected Member Functions | |
| void | StartHeartbeat (const int32_t interval, const std::string id) |
| void | StopHeartbeat () |
| virtual void | StopThreads () |
| void | Reconnect () |
| virtual void | Reregister () |
| void | CheckHeartbeatTimeout (int32_t &new_reply_time) |
| void | NotifyConnectionState (ConnectionState state) |
| const std::string | GetConfigFilePath () |
| void | SpawnReconnectionThread () |
Protected Attributes | |
| int | latency = 0 |
| int | deadline = 0 |
| int32_t | reply_time = 0 |
| int32_t | heartbeat_interval = 0 |
| std::thread | hb_thread |
| std::thread | reconnect_thread |
| std::atomic< bool > | reconnect_pending {false} |
| std::mutex | hb_cv_mutex |
| std::condition_variable | hb_cv |
| std::atomic< bool > | heartbeat_active {false} |
| std::atomic< bool > | shutdown_in_progress {false} |
| std::unique_ptr< datatransfer::DataBrokerRegistrationSync, std::default_delete< datatransfer::DataBrokerRegistrationSync > > | client |
| std::atomic< bool > | connected_to_broker {false} |
| ConnectionStateSignalT | connection_state_signal |
| std::atomic< ConnectionState > | last_notified_state {ConnectionState::Disconnected} |
| std::string | broker_uri |
| elt::mal::rr::ListenerRegistration | connection_listener |
| DdtLogger * | logger = nullptr |
| DdtLogger * | my_logger = nullptr |
| const int32_t | REPLY_TIME_DEFAULT = 6 |
| const int32_t | REPLY_TIME_MIN = 2 |
| int32_t | wait_for_connection = 0 |
| const int32_t | WAIT_FOR_CONNECTION_DEFAULT = 10 |
| const int32_t | WAIT_FOR_CONNECTION_MIN = 2 |
| int32_t | max_consecutive_failures = 0 |
| const int32_t | MAX_CONSECUTIVE_FAILURES_DEFAULT = 3 |
| const int32_t | MAX_CONSECUTIVE_FAILURES_MIN = 1 |
Base class for DdtDataPublishers and DdtDataSubscribers.
| using ddt::DdtDataTransferLib::ConnectionStateSignalT = boost::signals2::signal<void(ConnectionState)> |
Signal type to to notify gui about connection state.
|
strong |
|
explicit |
Constructor
| ddt_logger | A DDT logger object (no transfer of ownership). |
|
explicit |
Constructor
| log4cplus_logger | A log4cplus logger object (no transfer of ownership). |
|
virtual |
Destructor
|
protected |
Verifies that the heartbeat timeout retrieved from the broker is greater than reply time.
| new_reply_time | MAL reply time for the case that the client needs to get recreated. |
Make sure the heartbeat timeout is greater than the reply time! If not, recreate MAL client with new reply time.
reset reply_time (the connection manager makes sure that the heartbeat timeout has a valid value (at least 3s)
| boost::signals2::connection DdtDataTransferLib::ConnectToConnectionState | ( | const std::function< void(ConnectionState)> & | callback | ) |
Registers an external callback that is notified whenever the connection state to the broker changes.
| callback | Slot invoked on every transition between connection states. The argument describes the new state. |
| std::unique_ptr< datatransfer::DataBrokerRegistrationSync, std::default_delete< datatransfer::DataBrokerRegistrationSync > > DdtDataTransferLib::GetBrokerClient | ( | ) |
Retrieve the smart pointer for the client created by the MAL Factory
|
protected |
This function reads the environment variable DDT_TRANSFERCONFIG_PATH and returns path and name of the configuration file.
check if DDT_TRANSFERCONFIG_PATH is set return empty string if not set
| int DdtDataTransferLib::InitMAL | ( | const std::string | broker_uri | ) |
Initializes the MAL.
| broker_uri | The URI of the broker. |
determine MAL mapping from uri and load it obtain reference to CiiFactory
Synchronous client example w/ ReplyTime QoS set. DataBrokerRegistrationSync interface is requested.
|
protected |
Notify subscribers of the connection-state signal that the connection state has changed.
| state | New connection state. |
|
inlinevirtual |
Function for triggering the local broker to publish data over the network.
Reimplemented in ddt::DdtDataPublisher.
|
inlinevirtual |
|
protected |
Reconnects to the broker after heartbeat failures.
|
inlinevirtual |
Function for registering a publisher at the local broker using a MAL client.
| uri | The MAL Uniform Resource Identifier. |
| dsi | The data stream identifier. |
| compute_crc | Used to switch on / off the CRC computation. |
Reimplemented in ddt::DdtDataPublisher.
|
inlinevirtual |
Function for registering a subscriber at the local broker using a MAL client.
| uri | The MAL Uniform Resource Identifier. |
| dsi | The data stream identifier. |
| remote_uri | The URI of the remote broker. |
| interval | The reading interval. |
Reimplemented in ddt::DdtDataSubscriber.
|
inlineprotectedvirtual |
Reregisters at the broker after a reconnection.
| void DdtDataTransferLib::SetQoS | ( | const int | ddt_latency, |
| const int | ddt_deadline ) |
Sets quality of service parameters.
| ddt_latency | A MAL QoS parameter. Shall be the maximum time a sample may remain in-transit between the publisher and subscriber in [ms]. |
| ddt_deadline | A MAL QoS parameter. Shall be the maximum age of a sample in [s]. |
|
protected |
Spawn Reconnect() on a fresh thread if no reconnect is already in progress.
|
protected |
Starts the heartbeat thread.
| interval | The heartbeat interval in [s]. |
| id | The data stream identifier (in case of a publisher) or the UUID (in case of a subscriber). |
|
protected |
Stops the heartbeat thread.
|
protectedvirtual |
Stops all threads and joins them.
Reimplemented in ddt::DdtDataSubscriber.
|
inlinevirtual |
Function for unregistering a publisher from the local broker.
Reimplemented in ddt::DdtDataPublisher.
|
inlinevirtual |
Function for unregistering a subscriber from the local broker.
Reimplemented in ddt::DdtDataSubscriber.
| const std::string DdtDataTransferLib::VerifyPathInBrokerUri | ( | std::string | broker_uri | ) |
This function verifies if the broker uri contains the path element. If not specified by the user the path element is added.
| broker_uri | The URI of the broker. |
|
protected |
URI of the broker.
|
protected |
MAL client used to connect to data brokers.
|
protected |
Stores connection state to broker.
|
protected |
Observes the connection to the broker.
|
protected |
Signal fired when the connection state changes.
|
protected |
Maximum age of a sample [s].
|
protected |
|
protected |
Mutex and condition variable used to allow immediate wakeup of the heartbeat sleep when stopping.
|
protected |
Heartbeat thread.
|
protected |
When the HearbeatThread is stopped it waits until heartbeat_active is set to false.
|
protected |
Interval for the heartbeat in [s] retrieved from the data broker.
|
protected |
Last connection state that was broadcast via the signal.
|
protected |
Duration between send and receive cannot be greater than 'latency' [ms].
|
protected |
A DDT logger object.
|
protected |
Maximum consecutive heartbeat failures before stopping.
|
protected |
Default value for max_consecutive_failures.
|
protected |
Minimum value for max_consecutive_failures.
|
protected |
A DDT logger object.
|
protected |
Guard flag preventing concurrent reconnect attempts.
|
protected |
Reconnect thread. Spawned by HeartbeatThread when consecutive heartbeat failures exceed the threshold, or by the MAL connection listener when the broker connection is reported down.
|
protected |
Configurable reply time for MAL clients in [s].
|
protected |
Default value for the reply time.
|
protected |
Minimum value for the reply time.
|
protected |
Information for threads to abort operation if shutdown is pending.
|
protected |
Time to wait for broker connection in [s].
|
protected |
Default value for the wait_for_connection timeout.
|
protected |
Minimum value for the wait_for_connection timeout.