wamp_invocation.hpp
1 //
3 // Copyright (c) Crossbar.io Technologies GmbH 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_WAMP_INVOCATION_HPP
32 #define AUTOBAHN_WAMP_INVOCATION_HPP
33 
34 #include "wamp_arguments.hpp"
35 
36 #include <cstdint>
37 #include <functional>
38 #include <memory>
39 #include <msgpack.hpp>
40 #include <string>
41 
42 namespace autobahn {
43 
44 class wamp_message;
45 
47 {
48 public:
50  wamp_invocation_impl(wamp_invocation_impl&&) = delete; // copy wamp_invocation instead
51 
52  //add URI and details
56  const std::string& uri() const;
60  std::size_t number_of_arguments() const;
61 
65  std::size_t number_of_kw_arguments() const;
66 
76  template <typename T>
77  T argument(std::size_t index) const;
78 
87  template <typename List>
88  List arguments() const;
89 
101  template <typename List>
102  void get_arguments(List& args) const;
103 
120  template <typename... T>
121  inline void get_each_argument(T&... args) const;
122 
140  template <typename T>
141  T kw_argument(const std::string& key) const;
142 
143  template <typename T>
144  T kw_argument(const char* key) const;
145 
163  template <typename T>
164  T kw_argument_or(const std::string& key, const T& fallback) const;
165 
166  template <typename T>
167  T kw_argument_or(const char* key, const T& fallback) const;
168 
177  template <typename Map>
178  Map kw_arguments() const;
179 
191  template <typename Map>
192  void get_kw_arguments(Map& kw_args) const;
193 
211  template <typename T>
212  T detail(const std::string& key) const;
213 
214  template <typename T>
215  T detail(const char* key) const;
216 
234  template <typename T>
235  T detail_or(const std::string& key, const T& fallback) const;
236 
237  template <typename T>
238  T detail_or(const char* key, const T& fallback) const;
239 
248  template <typename Map>
249  Map details() const;
250 
262  template <typename Map>
263  void get_details(Map& details) const;
267  bool progressive_results_expected() const;
268 
272  void empty_result();
273 
277  template <typename List>
278  void progress(const List& arguments);
279 
283  template <typename List, typename Map>
284  void progress(const List& arguments, const Map& kw_arguments);
285 
289  template <typename List>
290  void result(const List& arguments);
291 
295  template <typename List, typename Map>
296  void result(const List& arguments, const Map& kw_arguments);
297 
301  void error(const std::string& error_uri);
302 
306  template <typename List>
307  void error(const std::string& error_uri, const List& arguments);
308 
312  template <typename List, typename Map>
313  void error(
314  const std::string& error_uri,
315  const List& arguments, const Map& kw_arguments);
316 
317  //
318  // functions only called internally by wamp_session
319 
320  using result_type = enum {
321  final = 0,
322  intermediary
323  } ;
324 
325  using send_result_fn = std::function<void(const std::shared_ptr<wamp_message>&)>;
326  void set_send_result_fn(send_result_fn&&);
327  void set_details(const msgpack::object& details);
328  void set_request_id(std::uint64_t);
329  void set_zone(msgpack::zone&&);
330  void set_arguments(const msgpack::object& arguments);
331  void set_kw_arguments(const msgpack::object& kw_arguments);
332  bool sendable() const;
333 
334 private:
335  void throw_if_not_sendable() const;
336 
337  template <typename List>
338  void send_result(const List& arguments, result_type resultType);
339 
340  template <typename List, typename Map>
341  void send_result(const List& arguments, const Map& kw_arguments, result_type resultType);
342 private:
343 
344 
345  msgpack::zone m_zone;
346  msgpack::object m_arguments;
347  msgpack::object m_kw_arguments;
348  msgpack::object m_details;
349  send_result_fn m_send_result_fn;
350  std::uint64_t m_request_id;
351  std::string m_uri;
352  bool m_progressive_results_expected;
353 };
354 
355 using wamp_invocation = std::shared_ptr<wamp_invocation_impl>;
356 
357 } // namespace autobahn
358 
359 #include "wamp_invocation.ipp"
360 
361 #endif // AUTOBAHN_WAMP_INVOCATION_HPP
void empty_result()
Reply to the invocation with an empty result.
void get_each_argument(T &...args) const
Convert and assign the positional arguments to a given list of individual parameters.
void result(const List &arguments)
Reply to the invocation with positional arguments.
T kw_argument(const std::string &key) const
The keyword argument passed to the invocation with the given key, converted to type T...
void get_kw_arguments(Map &kw_args) const
Convert and assign the keyword arguments to the given kw_args map.
T argument(std::size_t index) const
The positional argument passed to the invocation with the given index, converted to type T...
T detail(const std::string &key) const
The call detail passed to the invocation with the given key, converted to type T. ...
std::size_t number_of_arguments() const
The number of positional arguments passed to the invocation.
void error(const std::string &error_uri)
Reply to the invocation with an error and no further details.
bool progressive_results_expected() const
Checks if caller expects progressive results.
std::size_t number_of_kw_arguments() const
The number of keyword arguments passed to the invocation.
Map details() const
The call details passed to the invocation, converted to a map type.
T kw_argument_or(const std::string &key, const T &fallback) const
The keyword argument passed to the invocation with the given key, converted to type T...
List arguments() const
The positional arguments passed to the invocation, converted to a list type.
const std::string & uri() const
Invocatition procedure URI.
T detail_or(const std::string &key, const T &fallback) const
The call detail passed to the invocation with the given key, converted to type T, or the given fallba...
void get_arguments(List &args) const
Convert and assign the positional arguments to the given args list.
void progress(const List &arguments)
Send progressive/partial result with positional arguments.
void get_details(Map &details) const
Convert and assign the call details to the given details map.
Map kw_arguments() const
The keyword arguments passed to the invocation, converted to a map type.