MetaSoul

Loading...
Searching...
No Matches
sio_socket.h
Go to the documentation of this file.
1
2
3#ifndef EMOSHAPEIO_SOCKET_H
4#define EMOSHAPEIO_SOCKET_H
5#include "sio_message.h"
6#include <functional>
7 namespace emoshapeio
8{
9 class event_adapter;
10
11 class event
12 {
13 public:
14 const std::string& get_nsp() const;
15
16 const std::string& get_name() const;
17
18 const message::ptr& get_message() const;
19
20 const message::list& get_messages() const;
21
22 bool need_ack() const;
23
24 void put_ack_message(message::list const& ack_message);
25
26 message::list const& get_ack_message() const;
27
28 protected:
29 event(std::string const& nsp,std::string const& name,message::list const& messages,bool need_ack);
30 event(std::string const& nsp,std::string const& name,message::list&& messages,bool need_ack);
31
32 message::list& get_ack_message_impl();
33
34 private:
35 const std::string m_nsp;
36 const std::string m_name;
37 const message::list m_messages;
38 const bool m_need_ack;
39 message::list m_ack_message;
40
41 friend class event_adapter;
42 };
43
44 class client_impl_base;
45 class packet;
46
47 //The name 'socket' is taken from concept of official socket.io.
48 class EMOSHAPESUBSYSTEM_API socket
49 {
50 public:
51 typedef std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::list& ack_message)> event_listener_aux;
52
53 typedef std::function<void(event& event)> event_listener;
54
55 typedef std::function<void(message::ptr const& message)> error_listener;
56
57 typedef std::shared_ptr<socket> ptr;
58
59 ~socket();
60
61 void on(std::string const& event_name,event_listener const& func);
62
63 void on(std::string const& event_name,event_listener_aux const& func);
64
65 void off(std::string const& event_name);
66
67 void off_all();
68
69 void close();
70
71 void on_error(error_listener const& l);
72
73 void off_error();
74
75 void emit(std::string const& name, message::list const& msglist = nullptr, std::function<void (message::list const&)> const& ack = nullptr);
76
77 std::string const& get_namespace() const;
78
79 socket(client_impl_base*,std::string const&);
80
81 protected:
82
83 void on_connected();
84
85 void on_close();
86
87 void on_open();
88
89 void on_disconnect();
90
91 void on_message_packet(packet const& p);
92
93 friend class client_impl_base;
94
95 private:
96 //disable copy constructor and assign operator.
97 socket(socket const&){}
98 void operator=(socket const&){}
99
100 class impl;
101 impl *m_impl;
102 };
103}
104#endif // EMOSHAPEIO_SOCKET_H
emoshapeio::client_impl_base
Definition sio_client_impl.h:88
emoshapeio::client
Definition sio_client.h:13
emoshapeio::client::client
client()
Definition sio_client.cpp:24
emoshapeio::client::socket
emoshapeio::socket::ptr const & socket(const std::string &nsp="")
Definition sio_client.cpp:127
emoshapeio::client::close
void close()
Definition sio_client.cpp:133
emoshapeio::event_adapter
Definition sio_socket.cpp:48
emoshapeio::event
Definition sio_socket.h:12
emoshapeio::event::get_nsp
const std::string & get_nsp() const
Definition sio_socket.cpp:66
emoshapeio::event::get_ack_message_impl
message::list & get_ack_message_impl()
Definition sio_socket.cpp:127
emoshapeio::event::put_ack_message
void put_ack_message(message::list const &ack_message)
Definition sio_socket.cpp:97
emoshapeio::event::get_message
const message::ptr & get_message() const
Definition sio_socket.cpp:76
emoshapeio::event::event
event(std::string const &nsp, std::string const &name, message::list const &messages, bool need_ack)
Definition sio_socket.cpp:113
emoshapeio::event::get_messages
const message::list & get_messages() const
Definition sio_socket.cpp:87
emoshapeio::event::need_ack
bool need_ack() const
Definition sio_socket.cpp:92
emoshapeio::event::get_name
const std::string & get_name() const
Definition sio_socket.cpp:71
emoshapeio::event::get_ack_message
message::list const & get_ack_message() const
Definition sio_socket.cpp:121
emoshapeio::message::list
Definition sio_message.h:411
emoshapeio::message
Definition sio_message.h:14
emoshapeio::message::ptr
std::shared_ptr< message > ptr
Definition sio_message.h:37
emoshapeio::packet
Definition sio_packet.h:20
emoshapeio::socket
Definition sio_socket.h:49
emoshapeio::socket::event_listener_aux
std::function< void(const std::string &name, message::ptr const &message, bool need_ack, message::list &ack_message) event_listener_aux)
Definition sio_socket.h:51
emoshapeio::socket::event_listener
std::function< void(event &event) event_listener)
Definition sio_socket.h:53
emoshapeio::socket::ptr
std::shared_ptr< socket > ptr
Definition sio_socket.h:57
emoshapeio::socket::error_listener
std::function< void(message::ptr const &message) error_listener)
Definition sio_socket.h:55
emoshapeio
Definition sio_client_impl.cpp:51
sio_message.h