API Documentation
Loading...
Searching...
No Matches
SocketIOChannel.h
Go to the documentation of this file.
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{
38 /**--------------------------------------------------------------------------------------------------
39 \brief A specific channel of communication within the SocketIO framework.
40 **/
42 {
43 friend class SocketIO;
44 protected:
48 , m_name(name)
49 {
50 lib_assert(name.size() > 0 && !name.contains('|'), "Bad Socket channel name");
51 }
52 SocketIOChannel(const String& name, std::function<void(const char* data, uint04 size)> data_callback, UUID target = Constant<UUID>::Invalid)
53 : m_recieve_data_callback(data_callback)
55 , m_name(name)
56 {
57 lib_assert(name.size() > 0 && !name.contains('|'), "Bad Socket channel name");
58 }
59 public:
60 void setRecieveDataCallback(std::function<void(const char* data, uint04 size)> data_callback) { m_recieve_data_callback = data_callback; };
61 void sendData(const char* data, uint04 size)
62 {
63 lib_assert(m_send_data_callback, "Tried to send without socket IO connection");
65 m_send_data_callback(data, size);
66 };
67 const String& name() const { return m_name; }
68 const UUID& target() const { return m_target; }
69 protected:
70 void setSendDataCallback(std::function<void(const char* data, uint04 size)> data_callback) { m_send_data_callback = data_callback; };
71 void recieveData(const char* data, uint04 size)
72 {
74 m_recieve_data_callback(data, size);
75 };
76 protected:
77 std::function<void(const char* data, uint04 size)> m_recieve_data_callback;
78 std::function<void(const char* data, uint04 size)> m_send_data_callback;
81 };
82}
83
#define lib_assert(expression, message)
Definition LibAssert.h:61
bool contains(const t_type &element) const
Definition Buffer.hpp:465
constexpr t_index_type size() const
Definition Buffer.hpp:823
A specific channel of communication within the SocketIO framework.
Definition SocketIOChannel.h:42
void recieveData(const char *data, uint04 size)
Definition SocketIOChannel.h:71
void setRecieveDataCallback(std::function< void(const char *data, uint04 size)> data_callback)
Definition SocketIOChannel.h:60
SocketIOChannel(const String &name, UUID target=Constant< UUID >::Invalid)
Definition SocketIOChannel.h:45
std::function< void(const char *data, uint04 size)> m_recieve_data_callback
Definition SocketIOChannel.h:77
UUID m_target
Definition SocketIOChannel.h:79
SocketIOChannel(const String &name, std::function< void(const char *data, uint04 size)> data_callback, UUID target=Constant< UUID >::Invalid)
Definition SocketIOChannel.h:52
const UUID & target() const
Definition SocketIOChannel.h:68
const String & name() const
Definition SocketIOChannel.h:67
String m_name
Definition SocketIOChannel.h:80
std::function< void(const char *data, uint04 size)> m_send_data_callback
Definition SocketIOChannel.h:78
void setSendDataCallback(std::function< void(const char *data, uint04 size)> data_callback)
Definition SocketIOChannel.h:70
void sendData(const char *data, uint04 size)
Definition SocketIOChannel.h:61
Provides the ability to communicate over a network using SocketIO (https://socket....
Definition SocketIO.h:51
The core String class for the NDEVR API.
Definition String.h:69
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233