1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QMODBUSTCPSERVER_H |
5 | #define QMODBUSTCPSERVER_H |
6 | |
7 | #include <QtSerialBus/qmodbuspdu.h> |
8 | #include <QtSerialBus/qmodbusserver.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class QModbusTcpServerPrivate; |
13 | class QTcpSocket; |
14 | |
15 | class Q_SERIALBUS_EXPORT QModbusTcpConnectionObserver |
16 | { |
17 | public: |
18 | virtual ~QModbusTcpConnectionObserver(); |
19 | |
20 | virtual bool acceptNewConnection(QTcpSocket *newClient) = 0; |
21 | }; |
22 | |
23 | class Q_SERIALBUS_EXPORT QModbusTcpServer : public QModbusServer |
24 | { |
25 | Q_OBJECT |
26 | Q_DECLARE_PRIVATE(QModbusTcpServer) |
27 | |
28 | public: |
29 | explicit QModbusTcpServer(QObject *parent = nullptr); |
30 | ~QModbusTcpServer(); |
31 | |
32 | void installConnectionObserver(QModbusTcpConnectionObserver *observer); |
33 | |
34 | Q_SIGNALS: |
35 | void modbusClientDisconnected(QTcpSocket *modbusClient); |
36 | |
37 | protected: |
38 | QModbusTcpServer(QModbusTcpServerPrivate &dd, QObject *parent = nullptr); |
39 | |
40 | bool open() override; |
41 | void close() override; |
42 | |
43 | QModbusResponse processRequest(const QModbusPdu &request) override; |
44 | }; |
45 | |
46 | QT_END_NAMESPACE |
47 | |
48 | #endif // QMODBUSTCPSERVER_H |
49 | |