1 #ifndef MESSAGE_CLIENT_HPP__
2 #define MESSAGE_CLIENT_HPP__
3 
4 #include <QObject>
5 #include <QTime>
6 #include <QDateTime>
7 #include <QString>
8 #include <QHostAddress>
9 
10 #include "Radio.hpp"
11 #include "pimpl_h.hpp"
12 
13 class QByteArray;
14 class QHostAddress;
15 class QColor;
16 
17 //
18 // MessageClient - Manage messages sent and replies received from a
19 //                 matching server (MessageServer) at the other end of
20 //                 the wire
21 //
22 //
23 // Each outgoing message type is a Qt slot
24 //
25 class MessageClient
26   : public QObject
27 {
28   Q_OBJECT;
29 
30 public:
31   using Frequency = Radio::Frequency;
32   using port_type = quint16;
33 
34   // instantiate and initiate a host lookup on the server
35   //
36   // messages will be silently dropped until a server host lookup is complete
37   MessageClient (QString const& id, QString const& version, QString const& revision,
38                  QString const& server_name, port_type server_port,
39                  QStringList const& network_interface_names,
40                  int TTL, QObject * parent = nullptr);
41 
42   // query server details
43   QHostAddress server_address () const;
44   port_type server_port () const;
45 
46   // initiate a new server host lookup or if the server name is empty
47   // the sending of messages is disabled, if an interface is specified
48   // then that interface is used for outgoing datagrams
49   Q_SLOT void set_server (QString const& server_name, QStringList const& network_interface_names);
50 
51   // change the server port messages are sent to
52   Q_SLOT void set_server_port (port_type server_port = 0u);
53 
54   // change the server port messages are sent to
55   Q_SLOT void set_TTL (int TTL);
56 
57   // enable incoming messages
58   Q_SLOT void enable (bool);
59 
60   // outgoing messages
61   Q_SLOT void status_update (Frequency, QString const& mode, QString const& dx_call, QString const& report
62                              , QString const& tx_mode, bool tx_enabled, bool transmitting, bool decoding
63                              , quint32 rx_df, quint32 tx_df, QString const& de_call, QString const& de_grid
64                              , QString const& dx_grid, bool watchdog_timeout, QString const& sub_mode
65                              , bool fast_mode, quint8 special_op_mode, quint32 frequency_tolerance
66                              , quint32 tr_period, QString const& configuration_name
67                              , QString const& tx_message);
68   Q_SLOT void decode (bool is_new, QTime time, qint32 snr, float delta_time, quint32 delta_frequency
69                       , QString const& mode, QString const& message, bool low_confidence
70                       , bool off_air);
71   Q_SLOT void WSPR_decode (bool is_new, QTime time, qint32 snr, float delta_time, Frequency
72                            , qint32 drift, QString const& callsign, QString const& grid, qint32 power
73                            , bool off_air);
74   Q_SLOT void decodes_cleared ();
75   Q_SLOT void qso_logged (QDateTime time_off, QString const& dx_call, QString const& dx_grid
76                           , Frequency dial_frequency, QString const& mode, QString const& report_sent
77                           , QString const& report_received, QString const& tx_power, QString const& comments
78                           , QString const& name, QDateTime time_on, QString const& operator_call
79                           , QString const& my_call, QString const& my_grid
80                           , QString const& exchange_sent, QString const& exchange_rcvd
81                           , QString const& propmode);
82 
83   // ADIF_record argument should be valid ADIF excluding any <EOR> end
84   // of record marker
85   Q_SLOT void logged_ADIF (QByteArray const& ADIF_record);
86 
87   // this signal is emitted if the server has requested a decode
88   // window clear action
89   Q_SIGNAL void clear_decodes (quint8 window);
90 
91   // this signal is emitted if the server sends us a reply, the only
92   // reply supported is reply to a prior CQ or QRZ message
93   Q_SIGNAL void reply (QTime, qint32 snr, float delta_time, quint32 delta_frequency, QString const& mode
94                        , QString const& message_text, bool low_confidence, quint8 modifiers);
95 
96   // this signal is emitted if the server has requested this client to
97   // close down gracefully
98   Q_SIGNAL void close ();
99 
100   // this signal is emitted if the server has requested a replay of
101   // all decodes
102   Q_SIGNAL void replay ();
103 
104   // this signal is emitted if the server has requested immediate (or
105   // auto Tx if auto_only is true) transmission to halt
106   Q_SIGNAL void halt_tx (bool auto_only);
107 
108   // this signal is emitted if the server has requested a new free
109   // message text
110   Q_SIGNAL void free_text (QString const&, bool send);
111 
112   // this signal is emitted if the server has sent a highlight
113   // callsign request for the specified call
114   Q_SIGNAL void highlight_callsign (QString const& callsign, QColor const& bg, QColor const& fg, bool last_only);
115 
116   // this signal is emitted if the server has requested a
117   // configuration switch
118   Q_SIGNAL void switch_configuration (QString const& configuration_name);
119 
120   // this signal is emitted if the server has requested a
121   // configuration change
122   Q_SIGNAL void configure (QString const& mode, quint32 frequency_tolerance, QString const& submode
123                            , bool fast_mode, quint32 tr_period, quint32 rx_df, QString const& dx_call
124                            , QString const& dx_grid, bool generate_messages);
125 
126   // this signal is emitted when network errors occur or if a host
127   // lookup fails
128   Q_SIGNAL void error (QString const&) const;
129 
130   // this signal is emitted if the message obtains a location from a
131   // server.  (It doesn't have to be new, could be a periodic location
132   // update)
133   Q_SIGNAL void location (QString const&);
134 
135 private:
136   class impl;
137   pimpl<impl> m_;
138 };
139 
140 #endif
141