-
Notifications
You must be signed in to change notification settings - Fork 732
/
Copy pathsio_socket.h
105 lines (68 loc) · 2.82 KB
/
sio_socket.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef SIO_SOCKET_H
#define SIO_SOCKET_H
#include "sio_message.h"
#include <functional>
namespace sio
{
class event_adapter;
class event
{
public:
const std::string& get_nsp() const;
const std::string& get_name() const;
const message::ptr& get_message() const;
const message::list& get_messages() const;
bool need_ack() const;
void put_ack_message(message::list const& ack_message);
message::list const& get_ack_message() const;
protected:
event(std::string const& nsp,std::string const& name,message::list const& messages,bool need_ack);
event(std::string const& nsp,std::string const& name,message::list&& messages,bool need_ack);
message::list& get_ack_message_impl();
private:
const std::string m_nsp;
const std::string m_name;
const message::list m_messages;
const bool m_need_ack;
message::list m_ack_message;
friend class event_adapter;
};
class client_impl;
class packet;
//The name 'socket' is taken from concept of official socket.io.
class socket
{
public:
typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::list& ack_message)> event_listener_aux;
typedef std::function<void(event& event)> event_listener;
typedef std::function<void(message::ptr const& message)> error_listener;
typedef std::shared_ptr<socket> ptr;
~socket();
void on(std::string const& event_name,event_listener const& func);
void on(std::string const& event_name,event_listener_aux const& func);
void off(std::string const& event_name);
void on_any(event_listener const& func);
void on_any(event_listener_aux const& func);
void off_all();
void close();
void on_error(error_listener const& l);
void off_error();
void emit(std::string const& name, message::list const& msglist = nullptr, std::function<void (message::list const&)> const& ack = nullptr);
std::string const& get_namespace() const;
protected:
socket(client_impl*,std::string const&,message::ptr const&);
void on_connected();
void on_close();
void on_open();
void on_disconnect();
void on_message_packet(packet const& p);
friend class client_impl;
private:
//disable copy constructor and assign operator.
socket(socket const&){}
void operator=(socket const&){}
class impl;
impl *m_impl;
};
}
#endif // SIO_SOCKET_H