-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimerNetworkService.h
99 lines (85 loc) · 2.93 KB
/
TimerNetworkService.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef __TimerNetworkService_H
#define __TimerNetworkService_H
/*
* Copyright (c) 2019 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* The TimerNetworkService accepts connections on a TCP port, with the
* connection being a link to a remote controller. Only one controller
* at a time may be connected.
*
* A connected controller sends commands as ASCII text lines. Each
* line starts with a command, and the remaining words are options for
* the commands. The controller responds with "OK <words>" with the
* words being optional responses, and depend on the command being
* responded to. If there in an error, the response is
* "ERROR:<N>:<text>" where <N> is an error number, and <text> is a
* human readable error string.
*
* The supported commands are:
*
* close-detach
* close the link and detach the controller.
*
* next-end <number> practice|no-practice
* Set up for the next end. The <number> is used at the upcoming
* end number, and the practice|no-practice selects whether this
* is a practice end. The return code is the end to happen AFTER
* this (i.e. <number>+1) or an error code.
*
* start-timer
*
* fast-forward
*
* pause-timer
*
*/
# include <QString>
# include <QTcpServer>
# include <QTimer>
# include "qzeroconf.h"
class TimerControlBox;
class QTcpSocket;
class TimerNetworkService : private QTcpServer {
Q_OBJECT
public:
explicit TimerNetworkService(TimerControlBox*parent);
~TimerNetworkService();
private slots:
void new_connection_signal(void);
void ready_read(void);
void port_disconnected(void);
void service_added(QZeroConfService srv);
void service_removed(QZeroConfService srv);
void service_updated(QZeroConfService srv);
void clock_timeout();
private:
void process_command_(const QString&cmd);
void scan_for_networks_();
private:
// State machine for publishing my address.
QZeroConf zero_conf_;
private:
TimerControlBox*controls_;
QTcpSocket* connection_;
QString line_buffer_;
QStringList if_list_;
// Timer for polling and similar.
QTimer clock_;
};
#endif