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
10QT_BEGIN_NAMESPACE
11
12class QModbusTcpServerPrivate;
13class QTcpSocket;
14
15class Q_SERIALBUS_EXPORT QModbusTcpConnectionObserver
16{
17public:
18 virtual ~QModbusTcpConnectionObserver();
19
20 virtual bool acceptNewConnection(QTcpSocket *newClient) = 0;
21};
22
23class Q_SERIALBUS_EXPORT QModbusTcpServer : public QModbusServer
24{
25 Q_OBJECT
26 Q_DECLARE_PRIVATE(QModbusTcpServer)
27
28public:
29 explicit QModbusTcpServer(QObject *parent = nullptr);
30 ~QModbusTcpServer();
31
32 void installConnectionObserver(QModbusTcpConnectionObserver *observer);
33
34Q_SIGNALS:
35 void modbusClientDisconnected(QTcpSocket *modbusClient);
36
37protected:
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
46QT_END_NAMESPACE
47
48#endif // QMODBUSTCPSERVER_H
49

source code of qtserialbus/src/serialbus/qmodbustcpserver.h