Low-Level C++ SDK  v1.2.0
Loading...
Searching...
No Matches
WeArtClient.h
Go to the documentation of this file.
1
6#pragma once
7#include "WeArtCommon.h"
9#include "WeArtMessages.h"
14#include <winsock2.h>
15#include <future>
16#include <forward_list>
17
20public:
21 using MessageCallback = std::function<void(WeArtMessage*)>;
22
23 WeArtClient(PCSTR ip_address, PCSTR port);
24
27 void Start(TrackingType trackType = TrackingType::WEART_HAND);
28
30 void Stop();
31
33 void Run();
34
37 bool IsConnected();
38
40 void Close();
41
43 void StartCalibration();
44
46 void StopCalibration();
47
49 void StartRawData();
50
52 void StopRawData();
53
56 void SendMessage(WeArtMessage* message);
57
61
64 void AddThimbleRawSensors(WeArtTrackingRawData* rawSensorData);
65
68 void AddThimbleAnalogRawSensor(WeArtAnalogSensorData *analogRawSensorData);
69
71 int SizeThimbles();
72
76
80
84
88
91 void AddConnectionStatusCallback(std::function<void(bool)> callback);
92
93 enum ErrorType {
97 };
98
101 void AddErrorCallback(std::function<void(WeArtClient::ErrorType)> callback);
102
103protected:
104 WeArtMessageSerializer messageSerializer;
105
106 void OnReceive();
107
108private:
109 bool Connected = false;
110
111 SOCKET ConnectSocket;
112
113 std::vector<WeArtThimbleTrackingObject*> thimbleTrackingObjects;
114 std::vector<WeArtMessageListener*> messageListeners;
115 std::vector<MessageCallback> messageCallbacks;
116
117 void ForwardingMessages(std::vector<WeArtMessage*> messages);
118
119 // Connection status and errors callbacks management
120 std::vector<std::function<void(bool)>> connectionStatusCallbacks;
121 std::vector<std::function<void(ErrorType)>> errorCallbacks;
122 std::forward_list<std::future<void>> pendingCallbacks;
123
124 void NotifyConnectionStatus(bool connected);
125 void NotifyError(ErrorType errorType);
126 void ClearProcessedCallbacks();
127
128 PCSTR IP_ADDESS;
129 PCSTR PORT;
130};
131
TrackingType
Definition: WeArtCommon.h:12
Definition: WeArtAnalogSensorData.h:14
Weart client, used to connect to the Weart middleware, perform operations and receive messages.
Definition: WeArtClient.h:19
void StartRawData()
Ask the middleware to send raw sensors data to the sdk.
Definition: WeArtClient.cpp:259
std::function< void(WeArtMessage *)> MessageCallback
Definition: WeArtClient.h:21
void AddMessageCallback(MessageCallback callback)
Adds a message callback called when a message is received.
Definition: WeArtClient.cpp:341
void SendMessage(WeArtMessage *message)
Sends a message to the Weart middleware.
Definition: WeArtClient.cpp:269
int SizeThimbles()
Definition: WeArtClient.cpp:333
void RemoveMessageListener(WeArtMessageListener *listener)
Removes the given listener from the client. From now on the listener will not receive messages.
Definition: WeArtClient.cpp:346
void OnReceive()
Definition: WeArtClient.cpp:135
void AddThimbleAnalogRawSensor(WeArtAnalogSensorData *analogRawSensorData)
Adds a analog raw data sensors observer to the client, allowing it to receive messages.
Definition: WeArtClient.cpp:382
ErrorType
Definition: WeArtClient.h:93
@ ConnectionError
Definition: WeArtClient.h:94
@ SendMessageError
Definition: WeArtClient.h:95
@ ReceiveMessageError
Definition: WeArtClient.h:96
void Start(TrackingType trackType=TrackingType::WEART_HAND)
Send a start command to the middleware.
Definition: WeArtClient.cpp:221
void AddConnectionStatusCallback(std::function< void(bool)> callback)
Adds a callback for the connection status (true = connected, false = disconnected)
Definition: WeArtClient.cpp:365
void AddThimbleTracking(WeArtThimbleTrackingObject *trackingObjects)
Adds a thimble tracking object to the client, allowing it to receive messages.
Definition: WeArtClient.cpp:373
WeArtMessageSerializer messageSerializer
Definition: WeArtClient.h:104
void StopRawData()
Ask the middleware to stop sending raw sensors data to the sdk.
Definition: WeArtClient.cpp:264
void Run()
Starts and runs the network connection thread.
Definition: WeArtClient.cpp:42
bool IsConnected()
Tells whether the client is connected to the Weart middleware.
Definition: WeArtClient.cpp:130
void RemoveMessageCallback(MessageCallback callback)
Remove a given callback from the client.
Definition: WeArtClient.cpp:352
void AddThimbleRawSensors(WeArtTrackingRawData *rawSensorData)
Adds a raw data sensors observer to the client, allowing it to receive messages.
Definition: WeArtClient.cpp:378
void AddErrorCallback(std::function< void(WeArtClient::ErrorType)> callback)
Adds a callback for errors (connection, send or receive errors)
Definition: WeArtClient.cpp:369
void Close()
Close the network connection.
Definition: WeArtClient.cpp:231
void Stop()
Send a stop command to the middleware.
Definition: WeArtClient.cpp:226
void AddMessageListener(WeArtMessageListener *listener)
Adds a message listener object to the client, allowing it to receive messages.
Definition: WeArtClient.cpp:337
void StopCalibration()
Stops the device calibration procedure.
Definition: WeArtClient.cpp:254
void StartCalibration()
Starts the device calibration procedure.
Definition: WeArtClient.cpp:249
Message Listener basic interface.
Definition: WeArtMessageListener.h:9
Object used to track a single thimble object and its closure value.
Definition: WeArtThimbleTrackingObject.h:12
Object used to track the raw sensors data for a single thimble.
Definition: WeArtTrackingRawData.h:13