26
26
27
27
namespace jsonrpc {
28
28
29
+ // / A JSON-RPC 2.0 client.
29
30
class client
30
31
{
31
32
std::unique_ptr<any_stream> stream_;
@@ -47,49 +48,70 @@ class client
47
48
using next_layer_type = any_stream;
48
49
49
50
// / 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;
51
52
53
+ /* * Constructor.
54
+
55
+ Constructs a client capable of connecting to
56
+ an HTTP or HTTPS endpoint.
57
+ */
52
58
client (
53
59
boost::urls::url endpoint,
54
60
const boost::rts::context& rts_ctx,
55
61
boost::asio::any_io_executor exec,
56
62
boost::asio::ssl::context& ssl_ctx);
57
63
64
+ /* * Constructor.
65
+
66
+ Constructs a client using the supplied
67
+ @ref any_stream instance.
68
+ */
58
69
client (
59
70
boost::urls::url endpoint,
60
71
const boost::rts::context& rts_ctx,
61
72
std::unique_ptr<any_stream> stream);
62
73
74
+ // / Get the executor associated with the object.
63
75
executor_type
64
76
get_executor () noexcept
65
77
{
66
78
return stream_->get_executor ();
67
79
}
68
80
81
+ // / Get a reference to the next layer.
69
82
next_layer_type&
70
83
next_layer () noexcept
71
84
{
72
85
return *stream_;
73
86
}
74
87
88
+ // / Get a reference to the next layer.
75
89
next_layer_type const &
76
90
next_layer () const noexcept
77
91
{
78
92
return *stream_;
79
93
}
80
94
95
+ // / Return the endpoint that the client is configured with.
81
96
boost::urls::url_view
82
97
endpoint () const noexcept
83
98
{
84
99
return endpoint_;
85
100
}
86
101
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
+ */
87
108
boost::http_proto::fields_base&
88
109
http_fields ()
89
110
{
90
111
return req_;
91
112
}
92
113
114
+ // / Connect to the endpoint.
93
115
template <
94
116
BOOST_ASIO_COMPLETION_TOKEN_FOR (void (boost::system::error_code))
95
117
CompletionToken = boost::asio::deferred_t >
@@ -103,6 +125,7 @@ class client
103
125
this );
104
126
}
105
127
128
+ // / Shutdown the stream.
106
129
template <
107
130
BOOST_ASIO_COMPLETION_TOKEN_FOR (void (boost::system::error_code))
108
131
CompletionToken = boost::asio::deferred_t >
@@ -119,7 +142,7 @@ class client
119
142
template <typename Signature>
120
143
class invoker ;
121
144
122
- /* * Calls a remote procedure that takes no parameters.
145
+ /* * Call a remote procedure that takes no parameters.
123
146
124
147
Instances of this type are returned from @ref operator[].
125
148
@@ -131,6 +154,14 @@ class client
131
154
using invoker_base::invoker_base;
132
155
public:
133
156
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
+ */
134
165
template <
135
166
BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
136
167
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -145,7 +176,7 @@ class client
145
176
}
146
177
};
147
178
148
- /* * Calls a remote procedure with positional parameters (as an array).
179
+ /* * Call a remote procedure with positional parameters (array).
149
180
150
181
Instances of this type are returned from @ref operator[].
151
182
@@ -157,6 +188,17 @@ class client
157
188
using invoker_base::invoker_base;
158
189
public:
159
190
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
+ */
160
202
template <
161
203
BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
162
204
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -172,7 +214,7 @@ class client
172
214
}
173
215
};
174
216
175
- /* * Calls a remote procedure with named parameters (as an object).
217
+ /* * Call a remote procedure with named parameters (object).
176
218
177
219
Instances of this type are returned from @ref operator[].
178
220
@@ -184,6 +226,17 @@ class client
184
226
using invoker_base::invoker_base;
185
227
public:
186
228
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
+ */
187
240
template <
188
241
BOOST_ASIO_COMPLETION_TOKEN_FOR (void (error, Return))
189
242
CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)>
@@ -199,6 +252,20 @@ class client
199
252
}
200
253
};
201
254
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
+ */
202
269
template <typename Signature>
203
270
invoker<Signature>
204
271
operator [](method<Signature> m) noexcept
0 commit comments