31 #ifndef AUTOBAHN_SESSION_HPP 32 #define AUTOBAHN_SESSION_HPP 34 #include "wamp_call_options.hpp" 35 #include "wamp_call_result.hpp" 36 #include "wamp_event_handler.hpp" 37 #include "wamp_message.hpp" 38 #include "wamp_procedure.hpp" 39 #include "wamp_publish_options.hpp" 40 #include "wamp_subscribe_options.hpp" 41 #include "wamp_transport_handler.hpp" 42 #include "boost_config.hpp" 44 #include <boost/asio.hpp> 51 #include <msgpack.hpp> 57 #if defined(_WIN32) || defined(WIN32) 58 #define WIN32_LEAN_AND_MEAN 69 class wamp_register_request;
70 class wamp_registration;
71 class wamp_subscribe_request;
72 class wamp_subscription;
74 class wamp_unregister_request;
75 class wamp_unsubscribe_request;
76 class wamp_authenticate;
89 public wamp_transport_handler,
90 public std::enable_shared_from_this<wamp_session>
101 boost::asio::io_service& io_service,
102 bool debug_enabled =
false);
111 boost::future<void>
start();
118 boost::future<void>
stop();
128 boost::future<uint64_t>
join(
129 const std::string& realm,
130 const std::vector<std::string>& authmethods = std::vector<std::string>(),
131 const std::string& authid =
"");
139 boost::future<std::string>
leave(
140 const std::string& reason = std::string(
"wamp.error.close_realm"));
150 boost::future<void>
publish(
const std::string& topic,
151 const wamp_publish_options& options = wamp_publish_options());
161 template <
typename List>
162 boost::future<void>
publish(
const std::string& topic,
const List& arguments,
163 const wamp_publish_options& options = wamp_publish_options());
174 template <
typename List,
typename Map>
176 const std::string& topic,
177 const List& arguments,
178 const Map& kw_arguments,
179 const wamp_publish_options& options = wamp_publish_options());
189 boost::future<wamp_subscription>
subscribe(
190 const std::string& topic,
191 const wamp_event_handler& handler,
192 const wamp_subscribe_options& options = wamp_subscribe_options());
200 boost::future<void>
unsubscribe(
const wamp_subscription& subscription);
209 boost::future<wamp_call_result>
call(
210 const std::string& procedure,
211 const wamp_call_options& options = wamp_call_options());
221 template <
typename List>
222 boost::future<wamp_call_result>
call(
223 const std::string& procedure,
224 const List& arguments,
225 const wamp_call_options& options = wamp_call_options());
236 template<
typename List,
typename Map>
237 boost::future<wamp_call_result>
call(
238 const std::string& procedure,
239 const List& arguments,
const Map& kw_arguments,
240 const wamp_call_options& options = wamp_call_options());
250 boost::future<wamp_registration>
provide(
251 const std::string& uri,
252 const wamp_procedure& procedure,
253 const provide_options& options = provide_options());
261 boost::future<void>
unprovide(
const wamp_registration& registration);
271 virtual boost::future<wamp_authenticate>
on_challenge(
const wamp_challenge& challenge);
305 const std::unordered_map<std::string, msgpack::object>&
welcome_details();
309 virtual void on_attach(
const std::shared_ptr<wamp_transport>& transport)
override;
310 virtual void on_detach(
bool was_clean,
const std::string& reason)
override;
311 virtual void on_message(wamp_message&& message)
override;
314 void process_error(wamp_message&& message);
315 void process_welcome(wamp_message&& message);
316 void process_abort(wamp_message&& message);
317 void process_challenge(wamp_message&& message);
318 void process_call_result(wamp_message&& message);
319 void process_subscribed(wamp_message&& message);
320 void process_unsubscribed(wamp_message&& message);
321 void process_event(wamp_message&& message);
322 void process_registered(wamp_message&& message);
323 void process_unregistered(wamp_message&& message);
324 void process_invocation(wamp_message&& message);
325 void process_goodbye(wamp_message&& message);
328 void send_message(wamp_message&& message,
bool session_established =
true);
329 void receive_message();
331 void got_handshake_reply(
const boost::system::error_code& error);
332 void got_message_header(
const boost::system::error_code& error);
333 void got_message_body(
const boost::system::error_code& error);
334 void got_message(wamp_message&& message);
336 bool m_debug_enabled;
338 boost::asio::io_service& m_io_service;
341 std::shared_ptr<wamp_transport> m_transport;
344 std::atomic<uint64_t> m_request_id;
347 uint64_t m_session_id;
350 boost::promise<void> m_session_start;
353 boost::promise<uint64_t> m_session_join;
358 boost::promise<std::string> m_session_leave;
364 boost::promise<void> m_session_stop;
370 std::map<uint64_t , std::shared_ptr<wamp_call>> m_calls;
376 std::map<uint64_t , std::shared_ptr<wamp_subscribe_request>> m_subscribe_requests;
379 std::map<uint64_t , std::shared_ptr<wamp_unsubscribe_request>> m_unsubscribe_requests;
382 std::multimap<uint64_t , wamp_event_handler> m_subscription_handlers;
388 std::map<uint64_t, std::shared_ptr<wamp_register_request>> m_register_requests;
391 std::map<uint64_t, std::shared_ptr<wamp_unregister_request>> m_unregister_requests;
394 std::map<uint64_t, wamp_procedure> m_procedures;
397 std::unordered_map<std::string, msgpack::object> m_welcome_details;
403 #include "wamp_session.ipp" 405 #endif // AUTOBAHN_SESSION_HPP boost::future< wamp_registration > provide(const std::string &uri, const wamp_procedure &procedure, const provide_options &options=provide_options())
Register a procedure that can be called remotely.
boost::future< wamp_call_result > call(const std::string &procedure, const wamp_call_options &options=wamp_call_options())
Calls a remote procedure with no arguments.
boost::future< void > stop()
Stops the session with the router.
wamp_session(boost::asio::io_service &io_service, bool debug_enabled=false)
Create a new WAMP session.
boost::future< wamp_subscription > subscribe(const std::string &topic, const wamp_event_handler &handler, const wamp_subscribe_options &options=wamp_subscribe_options())
Subscribe a handler to a topic to receive events.
boost::future< void > publish(const std::string &topic, const wamp_publish_options &options=wamp_publish_options())
Publish an event with empty payload to a topic.
boost::future< void > unprovide(const wamp_registration ®istration)
Unregister a handler to previosly registered service.
boost::future< void > start()
Establishes a session with the router.
boost::future< uint64_t > join(const std::string &realm, const std::vector< std::string > &authmethods=std::vector< std::string >(), const std::string &authid="")
Join a realm with the session.
boost::future< void > unsubscribe(const wamp_subscription &subscription)
Unubscribe a handler to previously subscribed topic.
boost::future< std::string > leave(const std::string &reason=std::string("wamp.error.close_realm"))
Leave the realm.
const std::unordered_map< std::string, msgpack::object > & welcome_details()
Accessor method to WELCOME DETAILS dictionary containing router roles and corresponding features...
virtual boost::future< wamp_authenticate > on_challenge(const wamp_challenge &challenge)
Function called by the session when authenticating.