Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
42#ifndef PW_RPC_COMPLETION_REQUEST_CALLBACK
43#define PW_RPC_COMPLETION_REQUEST_CALLBACK 0
44#endif // PW_RPC_COMPLETION_REQUEST_CALLBACK
45
50#ifndef PW_RPC_METHOD_STORES_TYPE
51#define PW_RPC_METHOD_STORES_TYPE 0
52#endif // PW_RPC_METHOD_STORES_TYPE
53
66#ifndef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
67#define PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE 64
68#endif // PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
69
83#ifndef PW_RPC_USE_GLOBAL_MUTEX
84#define PW_RPC_USE_GLOBAL_MUTEX 1
85#endif // PW_RPC_USE_GLOBAL_MUTEX
86
111#ifndef PW_RPC_YIELD_MODE
112#if PW_RPC_USE_GLOBAL_MUTEX == 0
113#define PW_RPC_YIELD_MODE PW_RPC_YIELD_MODE_BUSY_LOOP
114#else
115#define PW_RPC_YIELD_MODE PW_RPC_YIELD_MODE_SLEEP
116#endif // PW_RPC_USE_GLOBAL_MUTEX == 0
117#endif // PW_RPC_YIELD_MODE
118
124// LINT.IfChange
125#define PW_RPC_YIELD_MODE_BUSY_LOOP 100
126#define PW_RPC_YIELD_MODE_SLEEP 101
127#define PW_RPC_YIELD_MODE_YIELD 102
128// LINT.ThenChange(//pw_rpc/BUILD.bazel)
129
134#ifndef PW_RPC_YIELD_SLEEP_DURATION
135
136// When building for a desktop operating system, use a 1ms sleep by default.
137// 1-tick duration sleeps can result in spurious timeouts.
138#if defined(_WIN32) || defined(__APPLE__) || \
139 defined(__linux__) && !defined(__ZEPHYR__)
140#define PW_RPC_YIELD_SLEEP_DURATION std::chrono::milliseconds(1)
141#else
142#define PW_RPC_YIELD_SLEEP_DURATION pw::chrono::SystemClock::duration(1)
143#endif // defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
144 // && !defined(__ZEPHYR__)
145
146#endif // PW_RPC_YIELD_SLEEP_DURATION
147
148// PW_RPC_YIELD_SLEEP_DURATION is not needed for non-sleep yield modes.
149#if PW_RPC_YIELD_MODE != PW_RPC_YIELD_MODE_SLEEP
150#undef PW_RPC_YIELD_SLEEP_DURATION
151#endif // PW_RPC_YIELD_MODE != PW_RPC_YIELD_MODE_SLEEP
152
168#ifndef PW_RPC_CALLBACK_TIMEOUT_TICKS
169#define PW_RPC_CALLBACK_TIMEOUT_TICKS 10000
170#endif // PW_RPC_CALLBACK_TIMEOUT_TICKS
171
190#ifndef PW_RPC_DYNAMIC_ALLOCATION
191#define PW_RPC_DYNAMIC_ALLOCATION 0
192#endif // PW_RPC_DYNAMIC_ALLOCATION
193
194#if defined(PW_RPC_DYNAMIC_CONTAINER) || \
195 defined(PW_RPC_DYNAMIC_CONTAINER_INCLUDE)
196static_assert(
197 PW_RPC_DYNAMIC_ALLOCATION == 1,
198 "PW_RPC_DYNAMIC_ALLOCATION is disabled, so PW_RPC_DYNAMIC_CONTAINER and "
199 "PW_RPC_DYNAMIC_CONTAINER_INCLUDE have no effect and should not be set.");
200#endif // PW_RPC_DYNAMIC_CONTAINER || PW_RPC_DYNAMIC_CONTAINER_INCLUDE
201
216#ifndef PW_RPC_DYNAMIC_CONTAINER
217#define PW_RPC_DYNAMIC_CONTAINER(type) std::vector<type>
218#endif // PW_RPC_DYNAMIC_CONTAINER
219
225#ifndef PW_RPC_DYNAMIC_CONTAINER_INCLUDE
226#define PW_RPC_DYNAMIC_CONTAINER_INCLUDE <vector>
227#endif // PW_RPC_DYNAMIC_CONTAINER_INCLUDE
228
233#ifndef PW_RPC_MAKE_UNIQUE_PTR
234#define PW_RPC_MAKE_UNIQUE_PTR(type, ...) \
235 std::unique_ptr<type>(new type(__VA_ARGS__))
236#endif // PW_RPC_DYNAMIC_CONTAINER
237
241#ifndef PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
242#define PW_RPC_MAKE_UNIQUE_PTR_INCLUDE <memory>
243#endif // PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
244
248#ifndef PW_RPC_ENCODING_BUFFER_SIZE_BYTES
249#define PW_RPC_ENCODING_BUFFER_SIZE_BYTES 512
250#endif // PW_RPC_ENCODING_BUFFER_SIZE_BYTES
251
253#ifndef PW_RPC_CONFIG_LOG_LEVEL
254#define PW_RPC_CONFIG_LOG_LEVEL PW_LOG_LEVEL_INFO
255#endif // PW_RPC_CONFIG_LOG_LEVEL
256
258#ifndef PW_RPC_CONFIG_LOG_MODULE_NAME
259#define PW_RPC_CONFIG_LOG_MODULE_NAME "PW_RPC"
260#endif // PW_RPC_CONFIG_LOG_MODULE_NAME
261
262namespace pw::rpc::cfg {
263
264template <typename...>
265constexpr std::bool_constant<PW_RPC_COMPLETION_REQUEST_CALLBACK>
266 kClientStreamEndCallbackEnabled;
267
268template <typename...>
269constexpr std::bool_constant<PW_RPC_METHOD_STORES_TYPE> kMethodStoresType;
270
271template <typename...>
272constexpr std::bool_constant<PW_RPC_DYNAMIC_ALLOCATION>
273 kDynamicAllocationEnabled;
274
275inline constexpr size_t kNanopbStructMinBufferSize =
276 PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE;
277
278inline constexpr size_t kEncodingBufferSizeBytes =
279 PW_RPC_ENCODING_BUFFER_SIZE_BYTES;
280
281#undef PW_RPC_NANOPB_STRUCT_MIN_BUFFER_SIZE
282#undef PW_RPC_ENCODING_BUFFER_SIZE_BYTES
283
284} // namespace pw::rpc::cfg
285
290#ifndef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
291#define PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE 1
292#endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
293
295#if PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
296#define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS
297#else
298#define _PW_RPC_NANOPB_STRUCT_STORAGE_CLASS static
299#endif // PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE
300
301#undef PW_RPC_NANOPB_STRUCT_BUFFER_STACK_ALLOCATE