summaryrefslogtreecommitdiff
path: root/Transceiver/TxInhibitTransceiver.hpp
blob: fb3f0103538a3249f7878cb853a9daea3fea5ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef TX_INHIBIT_TRANSCEIVER_HPP__
#define TX_INHIBIT_TRANSCEIVER_HPP__

#include <memory>

#include <QElapsedTimer>
#include <QHash>
#include <QString>

#include "Transceiver.hpp"

class QTimer;

class TxInhibitTransceiver final
  : public Transceiver
{
  Q_OBJECT

public:
  static constexpr int maximum_tracked_holds {64};

  explicit TxInhibitTransceiver (logger_type *, std::unique_ptr<Transceiver>);

  void set (TransceiverState const&, unsigned sequence_number) noexcept override;
  void start (unsigned sequence_number) noexcept override;
  void stop () noexcept override;
  void enqueue_jtty_pcm (QByteArray const&, TxAudioQueueEpoch, qint64) noexcept override;
  void clear_jtty_pcm (TxAudioQueueEpoch) noexcept override;

  Q_SLOT void tx_inhibit_command (QString controller, quint32 ttl_ms, QString station);
  Q_SLOT void tx_inhibit_invalid (quint64 count);

  Q_SIGNAL void statusChanged (bool supported, bool inhibited,
                               QString const& holder,
                               quint32 hold_rx, quint32 release_rx,
                               quint32 expiries, quint32 invalid);

private:
  struct Hold
  {
    qint64 expires_at;
    QString holder;
  };

  void apply_requested_state () noexcept;
  void emit_status ();
  void expire_holds ();
  QString holder_summary () const;
  void schedule_expiry ();

  std::unique_ptr<Transceiver> wrapped_;
  QTimer * expiry_timer_;
  QElapsedTimer monotonic_clock_;
  QHash<QString, Hold> holds_;
  TransceiverState requested_;
  TransceiverState last_effective_;
  unsigned sequence_number_ {0};
  quint32 hold_rx_ {0};
  quint32 release_rx_ {0};
  quint32 expiries_ {0};
  quint32 invalid_ {0};
  bool have_requested_state_ {false};
  bool have_effective_state_ {false};
  bool started_ {false};
};

#endif