Template Class Pipeline

Class Documentation

template<typename T>
class Pipeline

The Pipepline manages the production and optionally consumption of packages. Cyclically the producer is called and returned packages are saved in a queue. This queue is then either also cyclically utilized by the registered consumer or can be externally used.

Template Parameters:

T – Type of the managed packages

Public Types

typedef std::chrono::high_resolution_clock Clock
typedef Clock::time_point Time

Public Functions

inline Pipeline(IProducer<T> &producer, IConsumer<T> *consumer, std::string name, INotifier &notifier, const bool producer_fifo_scheduling = false)

Creates a new Pipeline object, registering producer, consumer and notifier. Additionally, an empty queue is initialized.

Parameters:
  • producer – The producer to run in the pipeline

  • consumer – The consumer to run in the pipeline

  • name – The pipeline’s name

  • notifier – The notifier to use

  • producer_fifo_scheduling – Should the producer thread use FIFO scheduling?

inline Pipeline(IProducer<T> &producer, std::string name, INotifier &notifier, const bool producer_fifo_scheduling = false)

Creates a new Pipeline object, registering producer and notifier while no consumer is used. Additionally, an empty queue is initialized.

Parameters:
  • producer – The producer to run in the pipeline

  • name – The pipeline’s name

  • notifier – The notifier to use

  • producer_fifo_scheduling – Should the producer thread use FIFO scheduling?

inline virtual ~Pipeline()

The Pipeline object’s destructor, stopping the pipeline and joining all running threads.

inline void init(const size_t max_num_tries = 0, const std::chrono::milliseconds reconnection_time = std::chrono::seconds(10))

Initialize the pipeline. Internally calls setup of producer and consumer.

Parameters:
  • max_num_tries – Maximum number of connection attempts before counting the connection as failed. Unlimited number of attempts when set to 0.

  • reconnection_time – time in between connection attempts to the server

inline void run()

Starts the producer and, if existing, the consumer in new threads.

inline void stop()

Stops the pipeline and all running threads.

inline bool getLatestProduct(std::unique_ptr<T> &product, std::chrono::milliseconds timeout)

Returns the most recent package in the queue. Can be used instead of registering a consumer. If the queue already contains one or more items, the queue will be flushed and the newest item will be returned. If there is no item inside the queue, the function will wait for timeout for a new package.

Parameters:
  • product – Unique pointer to be set to the package

  • timeout – Time to wait if no package is in the queue before returning

Returns: