C/C++ API Reference
Loading...
Searching...
No Matches
config.h
1// Copyright 2020 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
15// Configuration macros for the pw_rpc module.
16#pragma once
17
18#include <cstddef>
19#include <type_traits>
20
21#if defined(PW_RPC_CLIENT_STREAM_END_CALLBACK) && \
22 PW_RPC_CLIENT_STREAM_END_CALLBACK
23#pragma message( \
24 "Warning PW_RPC_CLIENT_STREAM_END_CALLBACK is deprecated! " \
25 "Use PW_RPC_COMPLETION_REQUEST_CALLBACK instead.")
26#define PW_RPC_COMPLETION_REQUEST_CALLBACK 1
27#endif
28
29#undef PW_RPC_CLIENT_STREAM_END_CALLBACK
30
32
44#ifndef PW_RPC_COMPLETION_REQUEST_CALLBACK
45#define PW_RPC_COMPLETION_REQUEST_CALLBACK 0
46#endif // PW_RPC_COMPLETION_REQUEST_CALLBACK
47
52#ifndef PW_RPC_METHOD_STORES_TYPE
53#define PW_RPC_METHOD_STORES_TYPE 0
54#endif // PW_RPC_METHOD_STORES_TYPE
55
68#ifndef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
69#define PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE 64
70#endif // PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
71
85#ifndef PW_RPC_USE_GLOBAL_MUTEX
86#define PW_RPC_USE_GLOBAL_MUTEX 1
87#endif // PW_RPC_USE_GLOBAL_MUTEX
88
113#ifndef PW_RPC_YIELD_MODE
114#if PW_RPC_USE_GLOBAL_MUTEX == 0
115#define PW_RPC_YIELD_MODE PW_RPC_YIELD_MODE_BUSY_LOOP
116#else
117#define PW_RPC_YIELD_MODE PW_RPC_YIELD_MODE_SLEEP
118#endif // PW_RPC_USE_GLOBAL_MUTEX == 0
119#endif // PW_RPC_YIELD_MODE
120
126// LINT.IfChange
127#define PW_RPC_YIELD_MODE_BUSY_LOOP 100
128#define PW_RPC_YIELD_MODE_SLEEP 101
129#define PW_RPC_YIELD_MODE_YIELD 102
130// LINT.ThenChange(//pw_rpc/BUILD.bazel)
131
136#ifndef PW_RPC_YIELD_SLEEP_DURATION
137
138// When building for a desktop operating system, use a 1ms sleep by default.
139// 1-tick duration sleeps can result in spurious timeouts.
140#if defined(_WIN32) || defined(__APPLE__) || \
141 defined(__linux__) && !defined(__ZEPHYR__)
142#define PW_RPC_YIELD_SLEEP_DURATION std::chrono::milliseconds(1)
143#else
144#define PW_RPC_YIELD_SLEEP_DURATION pw::chrono::SystemClock::duration(1)
145#endif // defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
146 // && !defined(__ZEPHYR__)
147
148#endif // PW_RPC_YIELD_SLEEP_DURATION
149
150// PW_RPC_YIELD_SLEEP_DURATION is not needed for non-sleep yield modes.
151#if PW_RPC_YIELD_MODE != PW_RPC_YIELD_MODE_SLEEP
152#undef PW_RPC_YIELD_SLEEP_DURATION
153#endif // PW_RPC_YIELD_MODE != PW_RPC_YIELD_MODE_SLEEP
154
170#ifndef PW_RPC_CALLBACK_TIMEOUT_TICKS
171#define PW_RPC_CALLBACK_TIMEOUT_TICKS 10000
172#endif // PW_RPC_CALLBACK_TIMEOUT_TICKS
173
192#ifndef PW_RPC_DYNAMIC_ALLOCATION
193#define PW_RPC_DYNAMIC_ALLOCATION 0
194#endif // PW_RPC_DYNAMIC_ALLOCATION
195
196#if defined(PW_RPC_DYNAMIC_CONTAINER) || \
197 defined(PW_RPC_DYNAMIC_CONTAINER_INCLUDE)
198static_assert(
200 "PW_RPC_DYNAMIC_ALLOCATION is disabled, so PW_RPC_DYNAMIC_CONTAINER and "
201 "PW_RPC_DYNAMIC_CONTAINER_INCLUDE have no effect and should not be set.");
202#endif // PW_RPC_DYNAMIC_CONTAINER || PW_RPC_DYNAMIC_CONTAINER_INCLUDE
203
218#ifndef PW_RPC_DYNAMIC_CONTAINER
219#define PW_RPC_DYNAMIC_CONTAINER(type) std::vector<type>
220#endif // PW_RPC_DYNAMIC_CONTAINER
221
227#ifndef PW_RPC_DYNAMIC_CONTAINER_INCLUDE
228#define PW_RPC_DYNAMIC_CONTAINER_INCLUDE <vector>
229#endif // PW_RPC_DYNAMIC_CONTAINER_INCLUDE
230
235#ifndef PW_RPC_MAKE_UNIQUE_PTR
236#define PW_RPC_MAKE_UNIQUE_PTR(type, ...) \
237 std::unique_ptr<type>(new type(__VA_ARGS__))
238#endif // PW_RPC_DYNAMIC_CONTAINER
239
243#ifndef PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
244#define PW_RPC_MAKE_UNIQUE_PTR_INCLUDE <memory>
245#endif // PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
246
253#ifndef PW_RPC_ENCODING_BUFFER_SIZE_BYTES
254#define PW_RPC_ENCODING_BUFFER_SIZE_BYTES 512
255#endif // PW_RPC_ENCODING_BUFFER_SIZE_BYTES
256
258#ifndef PW_RPC_CONFIG_LOG_LEVEL
259#define PW_RPC_CONFIG_LOG_LEVEL PW_LOG_LEVEL_INFO
260#endif // PW_RPC_CONFIG_LOG_LEVEL
261
263#ifndef PW_RPC_CONFIG_LOG_MODULE_NAME
264#define PW_RPC_CONFIG_LOG_MODULE_NAME "PW_RPC"
265#endif // PW_RPC_CONFIG_LOG_MODULE_NAME
266
267namespace pw::rpc::cfg {
268
269template <typename...>
270constexpr std::bool_constant<PW_RPC_COMPLETION_REQUEST_CALLBACK>
271 kClientStreamEndCallbackEnabled;
272
273template <typename...>
274constexpr std::bool_constant<PW_RPC_METHOD_STORES_TYPE> kMethodStoresType;
275
276template <typename...>
277constexpr std::bool_constant<PW_RPC_DYNAMIC_ALLOCATION>
278 kDynamicAllocationEnabled;
279
280inline constexpr size_t kNanopbStructMinBufferSize =
282
283inline constexpr size_t kEncodingBufferSizeBytes =
285
286#undef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
287#undef PW_RPC_ENCODING_BUFFER_SIZE_BYTES
288
289} // namespace pw::rpc::cfg
290
295#ifndef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
296#define PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE 1
297#endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
298
300#if PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
301#define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
302#else
303#define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS static
304#endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
305
306#undef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
307
#define PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
Definition: config.h:69
#define PW_RPC_DYNAMIC_ALLOCATION
Definition: config.h:193
#define PW_RPC_ENCODING_BUFFER_SIZE_BYTES
Definition: config.h:254