1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
19 #include "pw_rpc/internal/call.h"
23 // The ServerContext collects context for an RPC being invoked on a server. The
24 // ServerContext is passed into RPC functions and is user-facing.
26 // The ServerContext is a public-facing view of the internal::ServerCall class.
27 // It uses inheritance to avoid copying or creating an extra reference to the
28 // underlying ServerCall. Private inheritance prevents exposing the
29 // internal-facing ServerCall interface.
30 class ServerContext : private internal::ServerCall {
32 // Returns the ID for the channel this RPC is using.
33 uint32_t channel_id() const { return channel().id(); }
35 constexpr ServerContext() = delete;
37 constexpr ServerContext(const ServerContext&) = delete;
38 constexpr ServerContext& operator=(const ServerContext&) = delete;
40 constexpr ServerContext(ServerContext&&) = delete;
41 constexpr ServerContext& operator=(ServerContext&&) = delete;
43 friend class internal::ServerCall; // Allow down-casting from ServerCall.
48 inline ServerContext& ServerCall::context() {
49 return static_cast<ServerContext&>(*this);
52 } // namespace internal
53 } // namespace pw::rpc