Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_rpc / public / pw_rpc / server_context.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 #pragma once
15
16 #include <cstddef>
17 #include <cstdint>
18
19 #include "pw_rpc/internal/call.h"
20
21 namespace pw::rpc {
22
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.
25 //
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 {
31  public:
32   // Returns the ID for the channel this RPC is using.
33   uint32_t channel_id() const { return channel().id(); }
34
35   constexpr ServerContext() = delete;
36
37   constexpr ServerContext(const ServerContext&) = delete;
38   constexpr ServerContext& operator=(const ServerContext&) = delete;
39
40   constexpr ServerContext(ServerContext&&) = delete;
41   constexpr ServerContext& operator=(ServerContext&&) = delete;
42
43   friend class internal::ServerCall;  // Allow down-casting from ServerCall.
44 };
45
46 namespace internal {
47
48 inline ServerContext& ServerCall::context() {
49   return static_cast<ServerContext&>(*this);
50 }
51
52 }  // namespace internal
53 }  // namespace pw::rpc