NDEVR
API Documentation
SocketIOChannel.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, 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: Hardware
28File: SocketIOChannel
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "Base/Headers/String.h"
34#include "Base/Headers/UUID.h"
35
36namespace NDEVR
37{
42 {
43 friend class SocketIO;
44 protected:
49 explicit SocketIOChannel(const StringView& name, UUID target = Constant<UUID>::Invalid)
52 , m_name(name)
53 {
54 lib_assert(name.size() > 0 && !name.contains('|'), "Bad Socket channel name");
55 }
56
61 SocketIOChannel(const StringView& name, std::function<void(const char* data, uint04 size)> data_callback, UUID target = Constant<UUID>::Invalid)
62 : m_recieve_data_callback(data_callback)
64 , m_name(name)
65 {
66 lib_assert(name.size() > 0 && !name.contains('|'), "Bad Socket channel name");
67 }
68 public:
72 void setRecieveDataCallback(std::function<void(const char* data, uint04 size)> data_callback) { m_recieve_data_callback = data_callback; };
77 void sendData(const char* data, uint04 size)
78 {
79 lib_assert(m_send_data_callback, "Tried to send without socket IO connection");
81 m_send_data_callback(data, size);
82 };
83
86 const String& name() const { return m_name; }
90 const UUID& target() const { return m_target; }
91 protected:
95 void setSendDataCallback(std::function<void(const char* data, uint04 size)> data_callback) { m_send_data_callback = data_callback; };
100 void recieveData(const char* data, uint04 size)
101 {
103 m_recieve_data_callback(data, size);
104 };
105 protected:
106 std::function<void(const char* data, uint04 size)> m_recieve_data_callback;
107 std::function<void(const char* data, uint04 size)> m_send_data_callback;
110 };
111}
112
UUID m_target
The target client UUID, or invalid for broadcast.
SocketIOChannel(const StringView &name, std::function< void(const char *data, uint04 size)> data_callback, UUID target=Constant< UUID >::Invalid)
Constructs a channel with a data receive callback.
std::function< void(const char *data, uint04 size)> m_send_data_callback
Callback for outgoing data.
String m_name
The channel name.
void sendData(const char *data, uint04 size)
Sends data over this channel.
std::function< void(const char *data, uint04 size)> m_recieve_data_callback
Callback for incoming data.
SocketIOChannel(const StringView &name, UUID target=Constant< UUID >::Invalid)
Constructs a channel with the given name and optional target.
void setRecieveDataCallback(std::function< void(const char *data, uint04 size)> data_callback)
Sets the callback to invoke when data is received on this channel.
const UUID & target() const
Gets the target UUID for this channel.
void recieveData(const char *data, uint04 size)
Dispatches received data to the receive callback.
void setSendDataCallback(std::function< void(const char *data, uint04 size)> data_callback)
Sets the callback used to send data through the SocketIO connection.
const String & name() const
Gets the name of this channel.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
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...