NDEVR
API Documentation
BluetoothConnection.h
1#pragma once
2#include <NDEVR/Connection.h>
3#include <QPointer>
4class QBluetoothSocket;
5namespace NDEVR
6{
13 {
14 public:
30 virtual uint04 peek(char* s, uint04 size = Constant<uint04>::Max) const override;
37 virtual uint04 rx(char* s, uint04 size = Constant<uint04>::Max) override;
42 virtual void tx(const StringView& command) override;
48 virtual bool open(const ConnectionInfo& request) override;
54 virtual bool openInMainThread(const ConnectionInfo& request);
58 virtual void close() override;
63 virtual bool isOpen() const override;
68 virtual uint04 bytesAvailable() const override;
73 virtual TranslatedString lastError() const override;
80 virtual bool setBluetoothPort(QBluetoothSocket* bluetooth_port, const ConnectionInfo& info);
86 virtual bool waitForReadyRead(const TimeSpan& span) override;
91 void handleBluetoothError(int error);
92 protected:
93 QPointer<QBluetoothSocket> m_socket;
95 };
96
102 {
103 public:
109 virtual bool handlesType(const StringView& request) const override;
115 virtual ConnectionBackend* createConnection(const ConnectionInfo& request) override;
127 };
128}
A ConnectionFactory that enables the creation of a BluetoothConnection for interfacing with a QBlueto...
virtual Buffer< ConnectionCategory > availableConnectionCategories() override
Returns the categories of connections this factory can provide.
virtual bool handlesType(const StringView &request) const override
Checks whether this factory handles the given connection type string.
virtual Buffer< ConnectionInfo > availableConnections(const ConnectionSearchParameters &params) override
Discovers available Bluetooth connections matching the search parameters.
virtual ConnectionBackend * createConnection(const ConnectionInfo &request) override
Creates a new BluetoothConnection backend for the given connection info.
virtual bool isOpen() const override
Checks whether the Bluetooth socket is currently open and connected.
QPointer< QBluetoothSocket > m_socket
The underlying Qt Bluetooth socket used for communication.
BluetoothConnection(LogPtr log)
Constructs a BluetoothConnection with the given log.
virtual uint04 peek(char *s, uint04 size=Constant< uint04 >::Max) const override
Peeks at incoming data without consuming it from the receive buffer.
virtual bool waitForReadyRead(const TimeSpan &span) override
Blocks until data is ready to read or the timeout expires.
virtual uint04 rx(char *s, uint04 size=Constant< uint04 >::Max) override
Receives data from the Bluetooth socket into the provided buffer.
virtual bool openInMainThread(const ConnectionInfo &request)
Opens a Bluetooth connection on the main thread, required for some Qt Bluetooth operations.
virtual bool open(const ConnectionInfo &request) override
Opens a Bluetooth connection using the provided connection info.
virtual uint04 bytesAvailable() const override
Returns the number of bytes available for reading from the socket.
virtual TranslatedString lastError() const override
Returns the last error message from this connection.
~BluetoothConnection()
Destroys the BluetoothConnection and releases the underlying socket.
virtual void tx(const StringView &command) override
Transmits the given command string over the Bluetooth socket.
virtual void close() override
Closes the Bluetooth connection and releases the socket.
TranslatedString m_last_error
The most recent error message from this connection.
void handleBluetoothError(int error)
Handles a Bluetooth error by updating the internal error state.
virtual bool setBluetoothPort(QBluetoothSocket *bluetooth_port, const ConnectionInfo &info)
Assigns an existing QBluetoothSocket to this connection.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides the unseen backend logic for setting up, tearing down, and sending data over a specific type...
Definition Connection.h:169
ConnectionBackend(LogPtr log)
Constructs a ConnectionBackend with the given log.
Stores factories that can be registered for creating Connections of various types by instantiating a ...
Definition Connection.h:250
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
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
A structure designed to store information about a specific Connection.
Definition Connection.h:90
Describes settings for performing a Connection search.
Definition Connection.h:149