Program Listing for File RatatoskDoubleVal.hpp

Return to documentation for file (sinspekto/ratatosk/RatatoskDoubleVal.hpp)

#pragma once

#include "sinspekto/QtToDds.hpp"
#include "QDateTime"

class RatatoskDoubleValSubscriber : public QObject
{
  Q_OBJECT
  Q_PROPERTY(double val READ val NOTIFY valChanged)
  Q_PROPERTY(QDateTime timestamp READ timestamp NOTIFY timestampChanged)

public:
  explicit RatatoskDoubleValSubscriber(QObject *parent = nullptr);
  virtual ~RatatoskDoubleValSubscriber();

  double val() const;
  QDateTime timestamp() const;

  Q_INVOKABLE void init(QtToDds* dds, const QString& topic, bool with_listener=true);

signals:

  void valChanged(double val);
  void timestampChanged(QDateTime timestamp);
  void eventHeard();

public slots:
  void updateValue();

private:
  std::unique_ptr<sinspekto::Reader<ratatosk::types::DoubleVal>> m_reader;

};

class RatatoskDoubleValPublisher : public QObject
{
  Q_OBJECT
  Q_PROPERTY(double val READ val WRITE setVal NOTIFY valChanged)

public:
  explicit RatatoskDoubleValPublisher(QObject *parent = nullptr);
  virtual ~RatatoskDoubleValPublisher();

  double val() const;
  Q_INVOKABLE void init(QtToDds* dds, const QString& topic, double start_value, bool send_first);

signals:
  void valChanged(double value);

public slots:
  void setVal(double val);

  void publish();

private:
  std::unique_ptr<sinspekto::Writer<ratatosk::types::DoubleVal>> m_writer;
};