C/C++ API Reference
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
124
131template <
132 auto kRpcMethod,
133 typename Response = typename internal::MethodInfo<kRpcMethod>::Response>
135 Client& client,
136 uint32_t channel_id,
137 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
138 return internal::StructSynchronousCall<kRpcMethod, Response>(
139 internal::CallFreeFunctionWithCustomResponse<kRpcMethod, Response>(
140 client, channel_id, request));
141}
142
148template <auto kRpcMethod, typename GeneratedClient>
149SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
151 const GeneratedClient& client,
152 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
153 return internal::StructSynchronousCall<kRpcMethod>(
154 internal::CallGeneratedClient<kRpcMethod>(client, request));
155}
156
159template <auto kRpcMethod>
161 uint32_t channel_id,
162 ConstByteSpan request,
163 Function<void(ConstByteSpan, Status)>&& on_completed) {
164 return internal::RawSynchronousCall<kRpcMethod>(
165 std::move(on_completed),
166 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request));
167}
168
171template <auto kRpcMethod>
173 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
174 ConstByteSpan request,
175 Function<void(ConstByteSpan, Status)>&& on_completed) {
176 return internal::RawSynchronousCall<kRpcMethod>(
177 std::move(on_completed),
178 internal::CallGeneratedClient<kRpcMethod>(client, request));
179}
180
188template <auto kRpcMethod>
189SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
191 Client& client,
192 uint32_t channel_id,
193 const typename internal::MethodInfo<kRpcMethod>::Request& request,
195 return internal::StructSynchronousCall<kRpcMethod>(
196 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
197 timeout);
198}
199
206template <auto kRpcMethod, typename GeneratedClient>
207SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
209 const GeneratedClient& client,
210 const typename internal::MethodInfo<kRpcMethod>::Request& request,
212 return internal::StructSynchronousCall<kRpcMethod>(
213 internal::CallGeneratedClient<kRpcMethod>(client, request), timeout);
214}
215
218template <auto kRpcMethod>
220 Client& client,
221 uint32_t channel_id,
222 ConstByteSpan request,
224 Function<void(ConstByteSpan, Status)>&& on_completed) {
225 return internal::RawSynchronousCall<kRpcMethod>(
226 std::move(on_completed),
227 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
228 timeout);
229}
230
233template <auto kRpcMethod>
235 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
236 ConstByteSpan request,
238 Function<void(ConstByteSpan, Status)>&& on_completed) {
239 return internal::RawSynchronousCall<kRpcMethod>(
240 std::move(on_completed),
241 internal::CallGeneratedClient<kRpcMethod>(client, request),
242 timeout);
243}
244
252template <auto kRpcMethod>
253SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
255 Client& client,
256 uint32_t channel_id,
257 const typename internal::MethodInfo<kRpcMethod>::Request& request,
258 chrono::SystemClock::time_point deadline) {
259 return internal::StructSynchronousCall<kRpcMethod>(
260 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
261 deadline);
262}
263
270template <auto kRpcMethod>
271SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
273 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
274 const typename internal::MethodInfo<kRpcMethod>::Request& request,
275 chrono::SystemClock::time_point deadline) {
276 return internal::StructSynchronousCall<kRpcMethod>(
277 internal::CallGeneratedClient<kRpcMethod>(client, request), deadline);
278}
279
282template <auto kRpcMethod>
284 Client& client,
285 uint32_t channel_id,
286 ConstByteSpan request,
287 chrono::SystemClock::time_point deadline,
288 Function<void(ConstByteSpan, Status)>&& on_completed) {
289 return internal::RawSynchronousCall<kRpcMethod>(
290 std::move(on_completed),
291 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
292 deadline);
293}
294
297template <auto kRpcMethod>
299 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
300 ConstByteSpan request,
301 chrono::SystemClock::time_point deadline,
302 Function<void(ConstByteSpan, Status)>&& on_completed) {
303 return internal::RawSynchronousCall<kRpcMethod>(
304 std::move(on_completed),
305 internal::CallGeneratedClient<kRpcMethod>(client, request),
306 deadline);
307}
308
310
311} // namespace pw::rpc
Definition: status.h:109
Definition: client.h:28
Definition: synchronous_call_result.h:73
std::chrono::duration< rep, period > duration
Alias for durations representable with this clock.
Definition: system_clock.h:90
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
SynchronousCallResult< Response > SynchronousCall(Client &client, uint32_t channel_id, const typename internal::MethodInfo< kRpcMethod >::Request &request)
Definition: synchronous_call.h:134
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:190
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:254