-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEasySocket.h
58 lines (49 loc) · 1.53 KB
/
EasySocket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* \file EasySocket.h
* \brief A WebSocket implementation that wraps easywsclient.
*
* easywsclient is relatively spartan, not passing callbacks when expected.
* It is wrapped to fake those callbacks.
*
*/
#ifndef EasySocket_H
#define EasySocket_H
#include "SocketDelegate.h"
#include "ThreadPool.h"
#include "WebSocket.h"
#include "easywsclient.hpp"
#include <string>
class EasySocket : public WebSocket {
private:
/*!< Queue used for receiving messages. */
ThreadPool receiveQueue;
/*!< The mutex used when sending/polling messages over the socket. */
std::mutex socketMutex;
/*!< The underlying socket EasySocket wraps. */
easywsclient::WebSocket::pointer socket;
/*!< Keep track of Socket State.
This is used instead of easywsclient's SocketState. */
SocketState state;
/**
* \brief Function used to trigger WebSocket::webSocketDidReceive.
*
* \param message received.
* \return void
*/
void handleMessage(const std::string& message);
public:
// Make sure to implement this constructor if you take out the
// Base class constructor call.
// Otherwise, it'll throw `symbol not found` exceptions when compiling.
EasySocket(const std::string& url, SocketDelegate* delegate);
// WebSocket
void open();
void close();
void send(const std::string& message);
SocketState getSocketState();
void setDelegate(SocketDelegate* delegate);
SocketDelegate* getDelegate();
void setURL(const std::string& url);
// WebSocket
};
#endif