wamp_websocketpp_websocket_transport.hpp
1 //
3 // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors.
4 //
5 // Boost Software License - Version 1.0 - August 17th, 2003
6 //
7 // Permission is hereby granted, free of charge, to any person or organization
8 // obtaining a copy of the software and accompanying documentation covered by
9 // this license (the "Software") to use, reproduce, display, distribute,
10 // execute, and transmit the Software, and to prepare derivative works of the
11 // Software, and to permit third-parties to whom the Software is furnished to
12 // do so, all subject to the following:
13 //
14 // The copyright notices in the Software and this entire statement, including
15 // the above license grant, this restriction and the following disclaimer,
16 // must be included in all copies of the Software, in whole or in part, and
17 // all derivative works of the Software, unless such copies or derivative
18 // works are solely in the form of machine-executable object code generated by
19 // a source language processor.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 // DEALINGS IN THE SOFTWARE.
28 //
30 
31 #ifndef AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP
32 #define AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP
33 
34 #include "boost_config.hpp"
35 
36 #ifdef _WIN32
37 #ifdef _MSC_VER
38 #pragma warning(disable:4996) //Windows XP cancel async IO always fails with operation_not_supported
39 #endif
40 //Recommended WebSocket++ settings for Windows
41 #define _WEBSOCKETPP_CPP11_FUNCTIONAL_
42 #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
43 #define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_
44 #define _WEBSOCKETPP_CPP11_MEMORY_
45 #define _WEBSOCKETPP_NOEXCEPT_
46 #endif
47 
48 
49 #include "wamp_websocket_transport.hpp"
50 
51 
52 #include <websocketpp/config/asio_client.hpp>
53 #include <websocketpp/client.hpp>
54 
55 namespace autobahn {
56 
60  template <typename Config>
63  {
64  public:
65  typedef websocketpp::client<Config> client_type;
66  typedef boost::lock_guard<boost::mutex> scoped_lock;
67 
69  client_type& client,
70  const std::string& uri,
71  bool debug_enabled = false);
72 
73  virtual ~wamp_websocketpp_websocket_transport() override;
74 
75  virtual bool is_connected() const override;
76 
77  private:
78  virtual bool is_open() const override;
79  virtual void close() override;
80  virtual void async_connect(const std::string& uri, boost::promise<void>& connect_promise) override;
81  virtual void write(void const * payload, size_t len) override;
82 
83  private:
84 
85  void on_ws_open(websocketpp::connection_hdl);
86  void on_ws_close(websocketpp::connection_hdl);
87  void on_ws_fail(websocketpp::connection_hdl);
88  void on_ws_message(websocketpp::connection_hdl, typename client_type::message_ptr msg);
89  private:
93  client_type &m_client;
94 
95  websocketpp::connection_hdl m_hdl;
96  boost::mutex m_lock;
97  bool m_open;
98  bool m_done;
99  };
100 
101 } // namespace autobahn
102 
103 #include "wamp_websocketpp_websocket_transport.ipp"
104 #endif //AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP
virtual bool is_connected() const override
Determines if the transport is connected.
A transport that provides websocket support using WebSocket++ https://github.com/zaphoyd/websocketpp...
A class that represents a base websocket transport.