Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
synchronous_call.h
Go to the documentation of this file.
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <utility>
17
18#include "pw_chrono/system_clock.h"
19#include "pw_rpc/client.h"
20#include "pw_rpc/internal/method_info.h"
21#include "pw_rpc/internal/synchronous_call_impl.h"
22#include "pw_rpc/synchronous_call_result.h"
23
121namespace pw::rpc {
122
129template <
130 auto kRpcMethod,
131 typename Response = typename internal::MethodInfo<kRpcMethod>::Response>
132SynchronousCallResult<Response> SynchronousCall(
133 Client& client,
134 uint32_t channel_id,
135 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
136 return internal::StructSynchronousCall<kRpcMethod, Response>(
137 internal::CallFreeFunctionWithCustomResponse<kRpcMethod, Response>(
138 client, channel_id, request));
139}
140
146template <auto kRpcMethod, typename GeneratedClient>
147SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
149 const GeneratedClient& client,
150 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
151 return internal::StructSynchronousCall<kRpcMethod>(
152 internal::CallGeneratedClient<kRpcMethod>(client, request));
153}
154
157template <auto kRpcMethod>
158Status SynchronousCall(Client& client,
159 uint32_t channel_id,
160 ConstByteSpan request,
161 Function<void(ConstByteSpan, Status)>&& on_completed) {
162 return internal::RawSynchronousCall<kRpcMethod>(
163 std::move(on_completed),
164 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request));
165}
166
169template <auto kRpcMethod>
171 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
172 ConstByteSpan request,
173 Function<void(ConstByteSpan, Status)>&& on_completed) {
174 return internal::RawSynchronousCall<kRpcMethod>(
175 std::move(on_completed),
176 internal::CallGeneratedClient<kRpcMethod>(client, request));
177}
178
186template <auto kRpcMethod>
187SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
189 Client& client,
190 uint32_t channel_id,
191 const typename internal::MethodInfo<kRpcMethod>::Request& request,
193 return internal::StructSynchronousCall<kRpcMethod>(
194 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
195 timeout);
196}
197
204template <auto kRpcMethod, typename GeneratedClient>
205SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
207 const GeneratedClient& client,
208 const typename internal::MethodInfo<kRpcMethod>::Request& request,
210 return internal::StructSynchronousCall<kRpcMethod>(
211 internal::CallGeneratedClient<kRpcMethod>(client, request), timeout);
212}
213
216template <auto kRpcMethod>
218 Client& client,
219 uint32_t channel_id,
220 ConstByteSpan request,
222 Function<void(ConstByteSpan, Status)>&& on_completed) {
223 return internal::RawSynchronousCall<kRpcMethod>(
224 std::move(on_completed),
225 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
226 timeout);
227}
228
231template <auto kRpcMethod>
233 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
234 ConstByteSpan request,
236 Function<void(ConstByteSpan, Status)>&& on_completed) {
237 return internal::RawSynchronousCall<kRpcMethod>(
238 std::move(on_completed),
239 internal::CallGeneratedClient<kRpcMethod>(client, request),
240 timeout);
241}
242
250template <auto kRpcMethod>
251SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
253 Client& client,
254 uint32_t channel_id,
255 const typename internal::MethodInfo<kRpcMethod>::Request& request,
256 chrono::SystemClock::time_point deadline) {
257 return internal::StructSynchronousCall<kRpcMethod>(
258 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
259 deadline);
260}
261
268template <auto kRpcMethod>
269SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
271 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
272 const typename internal::MethodInfo<kRpcMethod>::Request& request,
273 chrono::SystemClock::time_point deadline) {
274 return internal::StructSynchronousCall<kRpcMethod>(
275 internal::CallGeneratedClient<kRpcMethod>(client, request), deadline);
276}
277
280template <auto kRpcMethod>
282 Client& client,
283 uint32_t channel_id,
284 ConstByteSpan request,
285 chrono::SystemClock::time_point deadline,
286 Function<void(ConstByteSpan, Status)>&& on_completed) {
287 return internal::RawSynchronousCall<kRpcMethod>(
288 std::move(on_completed),
289 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
290 deadline);
291}
292
295template <auto kRpcMethod>
297 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
298 ConstByteSpan request,
299 chrono::SystemClock::time_point deadline,
300 Function<void(ConstByteSpan, Status)>&& on_completed) {
301 return internal::RawSynchronousCall<kRpcMethod>(
302 std::move(on_completed),
303 internal::CallGeneratedClient<kRpcMethod>(client, request),
304 deadline);
305}
306
307} // namespace pw::rpc
Definition: status.h:85
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:74
std::chrono::duration< rep, period > duration
Alias for durations representable with this clock.
Definition: system_clock.h:86
SynchronousCallResult< Response > SynchronousCall(Client &client, uint32_t channel_id, const typename internal::MethodInfo< kRpcMethod >::Request &request)
Definition: synchronous_call.h:132
SynchronousCallResult< typename internal::MethodInfo< kRpcMethod >::Response > SynchronousCallFor(Client &client, uint32_t channel_id, const typename internal::MethodInfo< kRpcMethod >::Request &request, chrono::SystemClock::duration timeout)
Definition: synchronous_call.h:188
SynchronousCallResult< typename internal::MethodInfo< kRpcMethod >::Response > SynchronousCallUntil(Client &client, uint32_t channel_id, const typename internal::MethodInfo< kRpcMethod >::Request &request, chrono::SystemClock::time_point deadline)
Definition: synchronous_call.h:252