#ifndef _SSL_WS_H_ #define _SSL_WS_H_ #include #include #include //#include "../parser/parser.h" #include "../common/common.h" #include "../safe_queue/safe_queue.h" #include #include #include #include #include namespace ws { typedef websocketpp::client client; typedef std::shared_ptr context_ptr; class connection_metadata { public: typedef websocketpp::lib::shared_ptr ptr; connection_metadata(client*, int, websocketpp::connection_hdl, std::string); void on_open(client *, websocketpp::connection_hdl); void on_fail(client *, websocketpp::connection_hdl); void on_close(client *, websocketpp::connection_hdl); void on_message(websocketpp::connection_hdl, client::message_ptr); websocketpp::connection_hdl get_hdl() const; int get_id() const; std::string get_status() const; friend std::ostream & operator<< (std::ostream &, connection_metadata const &); bool msg_queue_empty(void); std::string pop_message(void); private: int m_id; websocketpp::connection_hdl m_hdl; std::string m_status; std::string m_uri; std::string m_server; std::string m_error_reason; //std::vector m_messages; client *m_endpoint; std::queue m_msg_q; mutable std::mutex m_msg_q_mutex; std::condition_variable m_msg_q_cdt; void push_message(std::string); }; class websocket_endpoint { public: websocket_endpoint(); ~websocket_endpoint(); int connect(std::string const &); void close(int, websocketpp::close::status::value, std::string); void send(int, std::string); connection_metadata::ptr get_metadata(int) const; std::string get_queue_front(int) const; private: typedef std::map con_list; client m_endpoint; websocketpp::lib::shared_ptr m_thread; con_list m_connection_list; int m_next_id; }; } #endif