NDEVR
API Documentation
AdaptiveWebClient.h
1#pragma once
2#include <NDEVR/NDEVRCommunicationLogic.h>
3#include <NDEVR/String.h>
4#include <NDEVR/QueueBuffer.h>
5#include <QWebSocket>
6#include <QTimer>
7namespace NDEVR
8{
14 class AdaptiveWebClient : public QObject, public NDEVRCommunicationLogic
15 {
16 Q_OBJECT
17 public:
21 explicit AdaptiveWebClient(QObject* parent = nullptr);
27 void connectToServer(const StringView& host, uint04 port, bool secure);
33 virtual uint08 rx(void* socket, NDEVRDataPacket& packet) override;
40 virtual uint08 tx(void* socket, NDEVRDataPacket& packet, uint08 size) override;
45 virtual uint08 bytesAvailable(void* socket) override;
50 virtual bool isOpen(void* socket = nullptr) const override;
55 void* connectTo(const NDEVRServerInfo& info) override;
60 virtual void wait(const TimeSpan& span, LogPtr log = nullptr) override;
68 virtual void disconnectFrom(void* socket) override;
69 private slots:
71 void onConnected();
73 void onSendTick();
77 void onBinaryMessageReceived(const QByteArray& message);
82 void onBinaryFrameReceived(const QByteArray& message, bool is_last);
86 void onBinaryMessageSent(qint64 message);
88 void onReconnectTimeout();
89 protected:
91 QTimer m_send_timer;
92 QWebSocket* m_server_socket;
93 bool m_should_be_open = false;
94 bool m_is_open_received = false;
95 };
96}
virtual uint08 bytesAvailable(void *socket) override
Returns the number of bytes available for reading.
QTimer m_reconnect_timer
Timer for automatic reconnection attempts.
virtual bool isOpen(void *socket=nullptr) const override
Checks whether the socket is currently connected.
QTimer m_send_timer
Timer for periodic send buffer flushing.
virtual uint08 rx(void *socket, NDEVRDataPacket &packet) override
Receives data from the socket into a packet.
void connectToServer(const StringView &host, uint04 port, bool secure)
Initiates a WebSocket connection to the specified host and port.
virtual void wait(const TimeSpan &span, LogPtr log=nullptr) override
Waits for the specified time span, processing events.
virtual uint08 tx(void *socket, NDEVRDataPacket &packet, uint08 size) override
Transmits packet data through the socket.
bool m_is_open_received
Whether the connected signal has been received.
virtual void disconnectFrom(void *socket) override
Disconnects from the specified socket.
AdaptiveWebClient(QObject *parent=nullptr)
Constructs the WebSocket client.
QWebSocket * m_server_socket
The underlying WebSocket.
bool m_should_be_open
Whether the connection should be open.
void updateWindowSize(NDEVRConnectionData &state) override
Updates the protocol window size for flow control.
void * connectTo(const NDEVRServerInfo &info) override
Establishes a connection to the specified server.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
The core String View class for the NDEVR API.
Definition StringView.h:58
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Holds the state of a single NDEVR network connection, including transmit and receive packets.
Contains the address, credentials, and security flag needed to connect to an NDEVR server.