pw_rpc: Hide internal function in Server and Client
Make the internal Endpoint::ClaimLocked() function private in the Server
and Client classes.
Change-Id: I435392eed03f1301349d66fa23bcd500f8b1e7c4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/126679
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_rpc/public/pw_rpc/client.h b/pw_rpc/public/pw_rpc/client.h
index 7ceba3d..8af40b2 100644
--- a/pw_rpc/public/pw_rpc/client.h
+++ b/pw_rpc/public/pw_rpc/client.h
@@ -53,6 +53,7 @@
private:
// Remove these internal::Endpoint functions from the public interface.
using Endpoint::active_call_count;
+ using Endpoint::ClaimLocked;
using Endpoint::GetInternalChannel;
};
diff --git a/pw_rpc/public/pw_rpc/internal/endpoint.h b/pw_rpc/public/pw_rpc/internal/endpoint.h
index df1dfb4..4b884fc 100644
--- a/pw_rpc/public/pw_rpc/internal/endpoint.h
+++ b/pw_rpc/public/pw_rpc/internal/endpoint.h
@@ -39,13 +39,7 @@
public:
~Endpoint();
- // Claims that `rpc_lock()` is held, returning a wrapped endpoint.
- //
- // This function should only be called in contexts in which it is clear that
- // `rpc_lock()` is held. When calling this function from a constructor, the
- // lock annotation will not result in errors, so care should be taken to
- // ensure that `rpc_lock()` is held.
- LockedEndpoint& ClaimLocked() PW_EXCLUSIVE_LOCKS_REQUIRED(rpc_lock());
+ // Public functions
// Creates a channel with the provided ID and ChannelOutput, if a channel slot
// is available or can be allocated (if PW_RPC_DYNAMIC_ALLOCATION is enabled).
@@ -68,14 +62,23 @@
// called with the ABORTED status.
Status CloseChannel(uint32_t channel_id) PW_LOCKS_EXCLUDED(rpc_lock());
- // For internal use only: returns the number calls in the RPC calls list.
+ // Internal functions, hidden by the Client and Server classes
+
+ // Returns the number calls in the RPC calls list.
size_t active_call_count() const PW_LOCKS_EXCLUDED(rpc_lock()) {
LockGuard lock(rpc_lock());
return calls_.size();
}
- // For internal use only: finds an internal::Channel with this ID or nullptr
- // if none matches.
+ // Claims that `rpc_lock()` is held, returning a wrapped endpoint.
+ //
+ // This function should only be called in contexts in which it is clear that
+ // `rpc_lock()` is held. When calling this function from a constructor, the
+ // lock annotation will not result in errors, so care should be taken to
+ // ensure that `rpc_lock()` is held.
+ LockedEndpoint& ClaimLocked() PW_EXCLUSIVE_LOCKS_REQUIRED(rpc_lock());
+
+ // Finds an internal::Channel with this ID or nullptr if none matches.
Channel* GetInternalChannel(uint32_t channel_id)
PW_EXCLUSIVE_LOCKS_REQUIRED(rpc_lock()) {
return channels_.Get(channel_id);
@@ -152,6 +155,9 @@
uint32_t call_id) PW_EXCLUSIVE_LOCKS_REQUIRED(rpc_lock());
ChannelList channels_ PW_GUARDED_BY(rpc_lock());
+
+ // List of all active calls associated with this endpoint. Calls are added to
+ // this list when they start and removed from it when they finish.
IntrusiveList<Call> calls_ PW_GUARDED_BY(rpc_lock());
uint32_t next_call_id_ PW_GUARDED_BY(rpc_lock()) = 0;
diff --git a/pw_rpc/public/pw_rpc/server.h b/pw_rpc/public/pw_rpc/server.h
index ba6053f..425fb6e 100644
--- a/pw_rpc/public/pw_rpc/server.h
+++ b/pw_rpc/public/pw_rpc/server.h
@@ -163,6 +163,7 @@
// Remove these internal::Endpoint functions from the public interface.
using Endpoint::active_call_count;
+ using Endpoint::ClaimLocked;
using Endpoint::GetInternalChannel;
IntrusiveList<Service> services_ PW_GUARDED_BY(internal::rpc_lock());
diff --git a/pw_rpc/raw/client_test.cc b/pw_rpc/raw/client_test.cc
index 050e3b2..985c369 100644
--- a/pw_rpc/raw/client_test.cc
+++ b/pw_rpc/raw/client_test.cc
@@ -45,7 +45,7 @@
template <auto kMethod, typename Call, typename Context>
Call MakeCall(Context& context)
PW_EXCLUSIVE_LOCKS_REQUIRED(internal::rpc_lock()) {
- return Call(context.client().ClaimLocked(),
+ return Call(static_cast<internal::Endpoint&>(context.client()).ClaimLocked(),
context.channel().id(),
internal::MethodInfo<kMethod>::kServiceId,
internal::MethodInfo<kMethod>::kMethodId,