2626
2727namespace jsonrpc {
2828
29+ // / A JSON-RPC 2.0 client.
2930class client
3031{
3132 std::unique_ptr<any_stream> stream_;
@@ -47,49 +48,70 @@ class client
4748 using next_layer_type = any_stream;
4849
4950 // / The type of the executor associated with the object.
50- using executor_type = typename next_layer_type ::executor_type;
51+ using executor_type = typename any_stream ::executor_type;
5152
53+ /* * Constructor.
54+
55+ Constructs a client capable of connecting to
56+ an HTTP or HTTPS endpoint.
57+ */
5258 client (
5359 boost::urls::url endpoint,
5460 const boost::rts::context& rts_ctx,
5561 boost::asio::any_io_executor exec,
5662 boost::asio::ssl::context& ssl_ctx);
5763
64+ /* * Constructor.
65+
66+ Constructs a client using the supplied
67+ @ref any_stream instance.
68+ */
5869 client (
5970 boost::urls::url endpoint,
6071 const boost::rts::context& rts_ctx,
6172 std::unique_ptr<any_stream> stream);
6273
74+ // / Get the executor associated with the object.
6375 executor_type
6476 get_executor () noexcept
6577 {
6678 return stream_->get_executor ();
6779 }
6880
81+ // / Get a reference to the next layer.
6982 next_layer_type&
7083 next_layer () noexcept
7184 {
7285 return *stream_;
7386 }
7487
88+ // / Get a reference to the next layer.
7589 next_layer_type const &
7690 next_layer () const noexcept
7791 {
7892 return *stream_;
7993 }
8094
95+ // / Return the endpoint that the client is configured with.
8196 boost::urls::url_view
8297 endpoint () const noexcept
8398 {
8499 return endpoint_;
85100 }
86101
102+ /* * Return a reference to the fields container of the HTTP
103+ request message.
104+
105+ This function can be used to customize HTTP headers, for
106+ example, to add the required credentials.
107+ */
87108 boost::http_proto::fields_base&
88109 http_fields ()
89110 {
90111 return req_;
91112 }
92113
114+ // / Connect to the endpoint.
93115 template <
94116 BOOST_ASIO_COMPLETION_TOKEN_FOR (void (boost::system::error_code))
95117 CompletionToken = boost::asio::deferred_t >
@@ -103,6 +125,7 @@ class client
103125 this );
104126 }
105127
128+ // / Shutdown the stream.
106129 template <
107130 BOOST_ASIO_COMPLETION_TOKEN_FOR (void (boost::system::error_code))
108131 CompletionToken = boost::asio::deferred_t >
@@ -119,7 +142,7 @@ class client
119142 template <typename Signature>
120143 class invoker ;
121144
122- /* * Calls a remote procedure that takes no parameters.
145+ /* * Call a remote procedure that takes no parameters.
123146
124147 Instances of this type are returned from @ref operator[].
125148
@@ -131,6 +154,14 @@ class client
131154 using invoker_base::invoker_base;
132155 public:
133156
157+ /* * Call a remote procedure that takes no parameters.
158+
159+ The result type depends on the signature of the @ref method object
160+ used to instantiate the invoker.
161+
162+ @param token The completion token used to produce a completion
163+ handler, which will be invoked when the call completes.
164+ */
134165 template <
135166 BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
136167 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -145,7 +176,7 @@ class client
145176 }
146177 };
147178
148- /* * Calls a remote procedure with positional parameters (as an array).
179+ /* * Call a remote procedure with positional parameters (array).
149180
150181 Instances of this type are returned from @ref operator[].
151182
@@ -157,6 +188,17 @@ class client
157188 using invoker_base::invoker_base;
158189 public:
159190
191+ /* * Call a remote procedure with positional parameters (array).
192+
193+ The result type depends on the signature of the @ref method object
194+ used to instantiate the invoker.
195+
196+ @param params A JSON array containing the positional parameters to
197+ use when calling the server method.
198+
199+ @param token The completion token used to produce a completion
200+ handler, which will be invoked when the call completes.
201+ */
160202 template <
161203 BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
162204 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -172,7 +214,7 @@ class client
172214 }
173215 };
174216
175- /* * Calls a remote procedure with named parameters (as an object).
217+ /* * Call a remote procedure with named parameters (object).
176218
177219 Instances of this type are returned from @ref operator[].
178220
@@ -184,6 +226,17 @@ class client
184226 using invoker_base::invoker_base;
185227 public:
186228
229+ /* * Call a remote procedure with named parameters (object).
230+
231+ The result type depends on the signature of the @ref method object
232+ used to instantiate the invoker.
233+
234+ @param params A JSON object containing the named parameters to use
235+ when calling the server method.
236+
237+ @param token The completion token used to produce a completion
238+ handler, which will be invoked when the call completes.
239+ */
187240 template <
188241 BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
189242 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -199,6 +252,20 @@ class client
199252 }
200253 };
201254
255+ /* * Return an @ref invoker instance that can be used to asynchronously
256+ invoke the specified method.
257+
258+ Example:
259+ @code
260+ client[method_a]({ "param1", "param2" }, completion_token);
261+ @endcode
262+
263+ @return An @ref invoker capable of asynchronously calling the specified
264+ method.
265+
266+ @param m The @ref method object containing the name and signature of the
267+ remote procedure.
268+ */
202269 template <typename Signature>
203270 invoker<Signature>
204271 operator [](method<Signature> m) noexcept
0 commit comments