1// Copyright (C) 2017 Witekio.
2// Copyright (C) 2018 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#ifndef QCOAPCLIENT_H
6#define QCOAPCLIENT_H
7
8#include <QtCore/qglobal.h>
9#include <QtCoap/qcoapglobal.h>
10#include <QtCoap/qcoapnamespace.h>
11#include <QtCore/qobject.h>
12#include <QtNetwork/qabstractsocket.h>
13
14QT_BEGIN_NAMESPACE
15
16class QCoapReply;
17class QCoapResourceDiscoveryReply;
18class QCoapRequest;
19class QCoapProtocol;
20class QCoapConnection;
21class QCoapSecurityConfiguration;
22class QCoapMessage;
23class QIODevice;
24
25class QCoapClientPrivate;
26class Q_COAP_EXPORT QCoapClient : public QObject
27{
28 Q_OBJECT
29public:
30 explicit QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSecurity,
31 QObject *parent = nullptr);
32 ~QCoapClient();
33
34 QCoapReply *get(const QCoapRequest &request);
35 QCoapReply *get(const QUrl &url);
36 QCoapReply *put(const QCoapRequest &request, const QByteArray &data = QByteArray());
37 QCoapReply *put(const QCoapRequest &request, QIODevice *device);
38 QCoapReply *put(const QUrl &url, const QByteArray &data = QByteArray());
39 QCoapReply *post(const QCoapRequest &request, const QByteArray &data = QByteArray());
40 QCoapReply *post(const QCoapRequest &request, QIODevice *device);
41 QCoapReply *post(const QUrl &url, const QByteArray &data = QByteArray());
42 QCoapReply *deleteResource(const QCoapRequest &request);
43 QCoapReply *deleteResource(const QUrl &url);
44 QCoapReply *observe(const QCoapRequest &request);
45 QCoapReply *observe(const QUrl &request);
46 void cancelObserve(QCoapReply *notifiedReply);
47 void cancelObserve(const QUrl &url);
48 void disconnect();
49
50 QCoapResourceDiscoveryReply *discover(
51 QtCoap::MulticastGroup group = QtCoap::MulticastGroup::AllCoapNodesIPv4,
52 int port = QtCoap::DefaultPort,
53 const QString &discoveryPath = QLatin1String("/.well-known/core"));
54 QCoapResourceDiscoveryReply *discover(
55 const QUrl &baseUrl,
56 const QString &discoveryPath = QLatin1String("/.well-known/core"));
57
58 void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration);
59 void setBlockSize(quint16 blockSize);
60 void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
61 void setMaximumServerResponseDelay(uint responseDelay);
62 void setAckTimeout(uint ackTimeout);
63 void setAckRandomFactor(double ackRandomFactor);
64 void setMaximumRetransmitCount(uint maximumRetransmitCount);
65 void setMinimumTokenSize(int tokenSize);
66
67Q_SIGNALS:
68 void finished(QCoapReply *reply);
69 void responseToMulticastReceived(QCoapReply *reply, const QCoapMessage &message,
70 const QHostAddress &sender);
71 void error(QCoapReply *reply, QtCoap::Error error);
72
73protected:
74 Q_DECLARE_PRIVATE(QCoapClient)
75};
76
77QT_END_NAMESPACE
78
79#endif // QCOAPCLIENT_H
80

source code of qtcoap/src/coap/qcoapclient.h