aboutsummaryrefslogtreecommitdiff
path: root/pw_rpc/public/pw_rpc/internal/config.h
diff options
context:
space:
mode:
Diffstat (limited to 'pw_rpc/public/pw_rpc/internal/config.h')
-rw-r--r--pw_rpc/public/pw_rpc/internal/config.h50
1 files changed, 40 insertions, 10 deletions
diff --git a/pw_rpc/public/pw_rpc/internal/config.h b/pw_rpc/public/pw_rpc/internal/config.h
index 24a227159..dec868b05 100644
--- a/pw_rpc/public/pw_rpc/internal/config.h
+++ b/pw_rpc/public/pw_rpc/internal/config.h
@@ -18,18 +18,30 @@
#include <cstddef>
#include <type_traits>
-/// In client and bidirectional RPCs, pw_rpc clients may signal that they have
-/// finished sending requests with a `CLIENT_STREAM_END` packet. While this can
-/// be useful in some circumstances, it is often not necessary.
+#if defined(PW_RPC_CLIENT_STREAM_END_CALLBACK) && \
+ PW_RPC_CLIENT_STREAM_END_CALLBACK
+#pragma message( \
+ "Warning PW_RPC_CLIENT_STREAM_END_CALLBACK is deprecated! " \
+ "Use PW_RPC_COMPLETION_REQUEST_CALLBACK instead.")
+#define PW_RPC_COMPLETION_REQUEST_CALLBACK 1
+#endif
+
+#undef PW_RPC_CLIENT_STREAM_END_CALLBACK
+
+/// pw_rpc clients may request call completion by sending
+/// `CLIENT_REQUEST_COMPLETION` packet. For client streaming or bi-direction
+/// RPCs, this also indicates that the client is done sending requests. While
+/// this can be useful in some circumstances, it is often not necessary.
///
/// This option controls whether or not include a callback that is called when
-/// the client stream ends. The callback is included in all ServerReader/Writer
-/// objects as a @cpp_type{pw::Function}, so may have a significant cost.
+/// the client stream requests for completion. The callback is included in all
+/// ServerReader/Writer objects as a @cpp_type{pw::Function}, so may have a
+/// significant cost.
///
/// This is disabled by default.
-#ifndef PW_RPC_CLIENT_STREAM_END_CALLBACK
-#define PW_RPC_CLIENT_STREAM_END_CALLBACK 0
-#endif // PW_RPC_CLIENT_STREAM_END_CALLBACK
+#ifndef PW_RPC_COMPLETION_REQUEST_CALLBACK
+#define PW_RPC_COMPLETION_REQUEST_CALLBACK 0
+#endif // PW_RPC_COMPLETION_REQUEST_CALLBACK
/// The Nanopb-based pw_rpc implementation allocates memory to use for Nanopb
/// structs for the request and response protobufs. The template function that
@@ -96,11 +108,13 @@
// When building for a desktop operating system, use a 1ms sleep by default.
// 1-tick duration sleeps can result in spurious timeouts.
-#if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
+#if defined(_WIN32) || defined(__APPLE__) || \
+ defined(__linux__) && !defined(__ZEPHYR__)
#define PW_RPC_YIELD_SLEEP_DURATION std::chrono::milliseconds(1)
#else
#define PW_RPC_YIELD_SLEEP_DURATION pw::chrono::SystemClock::duration(1)
#endif // defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
+ // && !defined(__ZEPHYR__)
#endif // PW_RPC_YIELD_SLEEP_DURATION
@@ -185,6 +199,22 @@ static_assert(
#define PW_RPC_DYNAMIC_CONTAINER_INCLUDE <vector>
#endif // PW_RPC_DYNAMIC_CONTAINER_INCLUDE
+/// If @c_macro{PW_RPC_DYNAMIC_ALLOCATION} is enabled, this macro must expand to
+/// a statement that creates a `std::unique_ptr`-like smart pointer.
+/// @param type The type of the object to construct (e.g. with `new`)
+/// @param ... Arguments to pass to the constructor, if any
+#ifndef PW_RPC_MAKE_UNIQUE_PTR
+#define PW_RPC_MAKE_UNIQUE_PTR(type, ...) \
+ std::unique_ptr<type>(new type(__VA_ARGS__))
+#endif // PW_RPC_DYNAMIC_CONTAINER
+
+/// If @c_macro{PW_RPC_DYNAMIC_ALLOCATION} is enabled, this header file is
+/// included in files that use @c_macro{PW_RPC_MAKE_UNIQUE_PTR}. Defaults to
+/// `<memory>` for `std::make_unique`.
+#ifndef PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
+#define PW_RPC_MAKE_UNIQUE_PTR_INCLUDE <memory>
+#endif // PW_RPC_MAKE_UNIQUE_PTR_INCLUDE
+
/// Size of the global RPC packet encoding buffer in bytes. If dynamic
/// allocation is enabled, this value is only used for test helpers that
/// allocate RPC encoding buffers.
@@ -205,7 +235,7 @@ static_assert(
namespace pw::rpc::cfg {
template <typename...>
-constexpr std::bool_constant<PW_RPC_CLIENT_STREAM_END_CALLBACK>
+constexpr std::bool_constant<PW_RPC_COMPLETION_REQUEST_CALLBACK>
kClientStreamEndCallbackEnabled;
template <typename...>