C/C++ API Reference
Loading...
Searching...
No Matches
synchronous_call.h
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
24// Docs on using the client synchronous call wrappers defined in this header:
25// https://pigweed.dev/pw_rpc/cpp.html#module-pw_rpc-client-sync-call-wrappers
26
27namespace pw::rpc {
28
30
37template <
38 auto kRpcMethod,
39 typename Response = typename internal::MethodInfo<kRpcMethod>::Response>
41 Client& client,
42 uint32_t channel_id,
43 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
44 return internal::StructSynchronousCall<kRpcMethod, Response>(
45 internal::CallFreeFunctionWithCustomResponse<kRpcMethod, Response>(
46 client, channel_id, request));
47}
48
54template <auto kRpcMethod, typename GeneratedClient>
55SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
57 const GeneratedClient& client,
58 const typename internal::MethodInfo<kRpcMethod>::Request& request) {
59 return internal::StructSynchronousCall<kRpcMethod>(
60 internal::CallGeneratedClient<kRpcMethod>(client, request));
61}
62
65template <auto kRpcMethod>
67 uint32_t channel_id,
68 ConstByteSpan request,
69 Function<void(ConstByteSpan, Status)>&& on_completed) {
70 return internal::RawSynchronousCall<kRpcMethod>(
71 std::move(on_completed),
72 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request));
73}
74
77template <auto kRpcMethod>
79 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
80 ConstByteSpan request,
81 Function<void(ConstByteSpan, Status)>&& on_completed) {
82 return internal::RawSynchronousCall<kRpcMethod>(
83 std::move(on_completed),
84 internal::CallGeneratedClient<kRpcMethod>(client, request));
85}
86
94template <auto kRpcMethod>
95SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
97 Client& client,
98 uint32_t channel_id,
99 const typename internal::MethodInfo<kRpcMethod>::Request& request,
101 return internal::StructSynchronousCall<kRpcMethod>(
102 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
103 timeout);
104}
105
112template <auto kRpcMethod, typename GeneratedClient>
113SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
115 const GeneratedClient& client,
116 const typename internal::MethodInfo<kRpcMethod>::Request& request,
118 return internal::StructSynchronousCall<kRpcMethod>(
119 internal::CallGeneratedClient<kRpcMethod>(client, request), timeout);
120}
121
124template <auto kRpcMethod>
126 Client& client,
127 uint32_t channel_id,
128 ConstByteSpan request,
130 Function<void(ConstByteSpan, Status)>&& on_completed) {
131 return internal::RawSynchronousCall<kRpcMethod>(
132 std::move(on_completed),
133 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
134 timeout);
135}
136
139template <auto kRpcMethod>
141 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
142 ConstByteSpan request,
144 Function<void(ConstByteSpan, Status)>&& on_completed) {
145 return internal::RawSynchronousCall<kRpcMethod>(
146 std::move(on_completed),
147 internal::CallGeneratedClient<kRpcMethod>(client, request),
148 timeout);
149}
150
158template <auto kRpcMethod>
159SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
161 Client& client,
162 uint32_t channel_id,
163 const typename internal::MethodInfo<kRpcMethod>::Request& request,
164 chrono::SystemClock::time_point deadline) {
165 return internal::StructSynchronousCall<kRpcMethod>(
166 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
167 deadline);
168}
169
176template <auto kRpcMethod>
177SynchronousCallResult<typename internal::MethodInfo<kRpcMethod>::Response>
179 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
180 const typename internal::MethodInfo<kRpcMethod>::Request& request,
181 chrono::SystemClock::time_point deadline) {
182 return internal::StructSynchronousCall<kRpcMethod>(
183 internal::CallGeneratedClient<kRpcMethod>(client, request), deadline);
184}
185
188template <auto kRpcMethod>
190 Client& client,
191 uint32_t channel_id,
192 ConstByteSpan request,
193 chrono::SystemClock::time_point deadline,
194 Function<void(ConstByteSpan, Status)>&& on_completed) {
195 return internal::RawSynchronousCall<kRpcMethod>(
196 std::move(on_completed),
197 internal::CallFreeFunction<kRpcMethod>(client, channel_id, request),
198 deadline);
199}
200
203template <auto kRpcMethod>
205 const typename internal::MethodInfo<kRpcMethod>::GeneratedClient& client,
206 ConstByteSpan request,
207 chrono::SystemClock::time_point deadline,
208 Function<void(ConstByteSpan, Status)>&& on_completed) {
209 return internal::RawSynchronousCall<kRpcMethod>(
210 std::move(on_completed),
211 internal::CallGeneratedClient<kRpcMethod>(client, request),
212 deadline);
213}
214
216
217} // namespace pw::rpc
Definition: status.h:120
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:40
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:96
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:160