1 #ifndef MESSAGE_SERVER_HPP__
2 #define MESSAGE_SERVER_HPP__
3 
4 #include <QObject>
5 #include <QPair>
6 #include <QString>
7 #include <QSet>
8 #include <QTime>
9 #include <QDateTime>
10 #include <QHostAddress>
11 #include <QColor>
12 
13 #include "udp_export.h"
14 #include "Radio.hpp"
15 
16 #include "pimpl_h.hpp"
17 
18 class QString;
19 
20 //
21 // MessageServer - a reference implementation of a message server
22 //                  matching the MessageClient class at the other end
23 //                  of the wire
24 //
25 // This class is fully functioning and suitable for use in C++
26 // applications that use the Qt framework. Other applications should
27 // use this classes' implementation as a reference implementation.
28 //
29 class UDP_EXPORT MessageServer
30   : public QObject
31 {
32   Q_OBJECT;
33 
34 public:
35   using port_type = quint16;
36   using Frequency = Radio::Frequency;
37   using ClientKey = QPair<QHostAddress, QString>;
38 
39   MessageServer (QObject * parent = nullptr,
40                  QString const& version = QString {}, QString const& revision = QString {});
41 
42   // start or restart the server, if the multicast_group_address
43   // argument is given it is assumed to be a multicast group address
44   // which the server will join
45   Q_SLOT void start (port_type port
46                      , QHostAddress const& multicast_group_address = QHostAddress {}
47                      , QSet<QString> const& network_interface_names = QSet<QString> {});
48 
49   // ask the client to clear one or both of the decode windows
50   Q_SLOT void clear_decodes (ClientKey const&, quint8 window = 0);
51 
52   // ask the client with identification 'id' to make the same action
53   // as a double click on the decode would
54   //
55   // note that the client is not obliged to take any action and only
56   // takes any action if the decode is present and is a CQ or QRZ message
57   Q_SLOT void reply (ClientKey const&, QTime time, qint32 snr, float delta_time, quint32 delta_frequency
58                      , QString const& mode, QString const& message, bool low_confidence, quint8 modifiers);
59 
60   // ask the client to close down gracefully
61   Q_SLOT void close (ClientKey const&);
62 
63   // ask the client to replay all decodes
64   Q_SLOT void replay (ClientKey const&);
65 
66   // ask the client to halt transmitting auto_only just disables auto
67   // Tx, otherwise halt is immediate
68   Q_SLOT void halt_tx (ClientKey const&, bool auto_only);
69 
70   // ask the client to set the free text message and optionally send
71   // it ASAP
72   Q_SLOT void free_text (ClientKey const&, QString const& text, bool send);
73 
74   // ask the client to set the location provided
75   Q_SLOT void location (ClientKey const&, QString const& location);
76 
77   // ask the client to highlight the callsign specified with the given
78   // colors
79   Q_SLOT void highlight_callsign (ClientKey const&, QString const& callsign
80                                   , QColor const& bg = QColor {}, QColor const& fg = QColor {}
81                                   , bool last_only = false);
82 
83   // ask the client to switch to configuration 'configuration_name'
84   Q_SLOT void switch_configuration (ClientKey const&, QString const& configuration_name);
85 
86   // ask the client to change configuration
87   Q_SLOT void configure (ClientKey const&, QString const& mode, quint32 frequency_tolerance
88                          , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df
89                          , QString const& dx_call, QString const& dx_grid, bool generate_messages);
90 
91   // the following signals are emitted when a client broadcasts the
92   // matching message
93   Q_SIGNAL void client_opened (ClientKey const&, QString const& version, QString const& revision);
94   Q_SIGNAL void status_update (ClientKey const&, Frequency, QString const& mode, QString const& dx_call
95                                , QString const& report, QString const& tx_mode, bool tx_enabled
96                                , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df
97                                , QString const& de_call, QString const& de_grid, QString const& dx_grid
98                                , bool watchdog_timeout, QString const& sub_mode, bool fast_mode
99                                , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period
100                                , QString const& configuration_name, QString const& tx_message);
101   Q_SIGNAL void client_closed (ClientKey const&);
102   Q_SIGNAL void decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time
103                         , quint32 delta_frequency, QString const& mode, QString const& message
104                         , bool low_confidence, bool off_air);
105   Q_SIGNAL void WSPR_decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time, Frequency
106                              , qint32 drift, QString const& callsign, QString const& grid, qint32 power
107                              , bool off_air);
108   Q_SIGNAL void qso_logged (ClientKey const&, QDateTime time_off, QString const& dx_call, QString const& dx_grid
109                             , Frequency dial_frequency, QString const& mode, QString const& report_sent
110                             , QString const& report_received, QString const& tx_power, QString const& comments
111                             , QString const& name, QDateTime time_on, QString const& operator_call
112                             , QString const& my_call, QString const& my_grid
113                             , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode);
114   Q_SIGNAL void decodes_cleared (ClientKey const&);
115   Q_SIGNAL void logged_ADIF (ClientKey const&, QByteArray const& ADIF);
116 
117   // this signal is emitted when a network error occurs
118   Q_SIGNAL void error (QString const&) const;
119 
120 private:
121   class UDP_NO_EXPORT impl;
122   pimpl<impl> m_;
123 };
124 
125 Q_DECLARE_METATYPE (MessageServer::ClientKey);
126 
127 #endif
128