NDEVR
API Documentation
NDEVRCommunicationLogic.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2020, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVRFileServer
28File: NDEVRCommunicationLogic
29Included in API: True
30Author(s): tyler.parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Dictionary.h>
35#include <NDEVR/String.h>
36#include <NDEVR/PasswordString.h>
37#include "NDEVRDataPacket.h"
38#include <NDEVR/LogPtr.h>
39namespace NDEVR
40{
44 struct NDEVRConnectionData
45 {
46 NDEVRConnectionData()
47 {
48 rx_message.setupPacketHeader(false);
49 }
51 void* socket = nullptr;
52 NDEVRDataPacket tx_message;
53 NDEVRDataPacket rx_message;
55 };
56
60 {
62 uint02 port = Constant<uint02>::Invalid;
65 bool secure = true;
66 };
67
71 {
72 public:
75 virtual void onReceive(NDEVRConnectionData& state) = 0;
79 virtual void onConnectionChanged(void* socket, bool is_connected) = 0;
80 };
81
84 class NDEVRSERVERCLIENT_API NDEVRCommunicationLogic
85 {
86 public:
88 NDEVRCommunicationLogic();
90 virtual ~NDEVRCommunicationLogic() {};
94 void addConnection(void* socket, const StringView& id);
97 void removeConnection(void* socket);
100 virtual void updateWindowSize(NDEVRConnectionData& state);
104 bool sendAndReceiveData(NDEVRConnectionData& state);
107 void addListener(PacketListener* listener);
111 void changeConnectionState(void* socket, bool is_connected);
114 void removeListener(PacketListener* listener) { m_listeners.removeElement(listener); }
118 virtual void* connectTo(const NDEVRServerInfo& info) = 0;
121 virtual void disconnectFrom(void* socket) = 0;
125 bool readRxData(NDEVRConnectionData& state);
129 virtual void sendMessage(void* target, NDEVRDataPacket&& data);
133 const NDEVRConnectionData* connectionData(void* target);
137 virtual void wait(const TimeSpan& span, LogPtr log = nullptr) = 0;
140 const NDEVRServerInfo& connectionInfo() const { return m_connection_info; }
144 virtual bool isOpen(void* socket = nullptr) const = 0;
145 protected:
150 virtual uint08 rx(void* socket, NDEVRDataPacket& packet) = 0;
156 virtual uint08 tx(void* socket, NDEVRDataPacket& packet, uint08 max_size) = 0;
160 virtual uint08 bytesAvailable(void* socket) = 0;
161 protected:
162 Buffer<PacketListener*> m_listeners;
163 Dictionary<void*, NDEVRConnectionData*> m_connections;
164 NDEVRServerInfo m_connection_info;
165 };
166}
Interface for objects that wish to receive NDEVR packet events and connection state changes.
virtual void onConnectionChanged(void *socket, bool is_connected)=0
Called when a connection's state changes.
virtual void onReceive(NDEVRConnectionData &state)=0
Called when a complete packet has been received.
When passwords are used inside the NDEVR engine, we don't want them logged or visible.
The core String class for the NDEVR API.
Definition String.h:95
The primary namespace for the NDEVR SDK.
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
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.
String connection_id
Unique identifier for this connection.
NDEVRDataPacket tx_message
Outgoing data packet being assembled or sent.
void * socket
Opaque socket handle for the connection.
uint04 window_size
Transmission window size in bytes.
NDEVRDataPacket rx_message
Incoming data packet being received.
Contains the address, credentials, and security flag needed to connect to an NDEVR server.
String address
Server hostname or IP address.
PasswordString password
Password for authentication.
uint02 port
Server port number.
String username
Username for authentication.
bool secure
Whether to use a secure (TLS/SSL) connection.