sio_client.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // sio_client.h
  3. //
  4. // Created by Melo Yao on 3/25/15.
  5. //
  6. #ifndef SIO_CLIENT_H
  7. #define SIO_CLIENT_H
  8. #include <string>
  9. #include <functional>
  10. #include "sio_message.h"
  11. #include "sio_socket.h"
  12. namespace sio
  13. {
  14. class client_impl;
  15. class client {
  16. public:
  17. enum close_reason
  18. {
  19. close_reason_normal,
  20. close_reason_drop
  21. };
  22. typedef std::function<void(void)> con_listener;
  23. typedef std::function<void(close_reason const& reason)> close_listener;
  24. typedef std::function<void(unsigned, unsigned)> reconnect_listener;
  25. typedef std::function<void(std::string const& nsp)> socket_listener;
  26. client();
  27. ~client();
  28. //set listeners and event bindings.
  29. void set_open_listener(con_listener const& l);
  30. void set_fail_listener(con_listener const& l);
  31. void set_reconnecting_listener(con_listener const& l);
  32. void set_reconnect_listener(reconnect_listener const& l);
  33. void set_close_listener(close_listener const& l);
  34. void set_socket_open_listener(socket_listener const& l);
  35. void set_socket_close_listener(socket_listener const& l);
  36. void clear_con_listeners();
  37. void clear_socket_listeners();
  38. // Client Functions - such as send, etc.
  39. void connect(const std::string& uri);
  40. void connect(const std::string& uri, const std::map<std::string,std::string>& query);
  41. void connect(const std::string& uri, const std::map<std::string,std::string>& query,
  42. const std::map<std::string,std::string>& http_extra_headers);
  43. void set_reconnect_attempts(int attempts);
  44. void set_reconnect_delay(unsigned millis);
  45. void set_reconnect_delay_max(unsigned millis);
  46. sio::socket::ptr const& socket(const std::string& nsp = "");
  47. // Closes the connection
  48. void close();
  49. void sync_close();
  50. bool opened() const;
  51. std::string const& get_sessionid() const;
  52. private:
  53. //disable copy constructor and assign operator.
  54. client(client const&){}
  55. void operator=(client const&){}
  56. client_impl* m_impl;
  57. };
  58. }
  59. #endif // __SIO_CLIENT__H__