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/channel.h" 20 21 namespace pw::rpc { 22 23 class Service; 24 25 namespace internal { 26 27 class Endpoint; 28 class Method; 29 30 // The Server creates a CallContext object to represent a method invocation. The 31 // CallContext is used to initialize a call object for the RPC. 32 class CallContext { 33 public: CallContext(Endpoint & server,uint32_t channel_id,Service & service,const internal::Method & method,uint32_t call_id)34 constexpr CallContext(Endpoint& server, 35 uint32_t channel_id, 36 Service& service, 37 const internal::Method& method, 38 uint32_t call_id) 39 : server_(server), 40 channel_id_(channel_id), 41 service_(service), 42 method_(method), 43 call_id_(call_id) {} 44 server()45 constexpr Endpoint& server() const { return server_; } 46 channel_id()47 constexpr const uint32_t& channel_id() const { return channel_id_; } 48 service()49 constexpr Service& service() const { return service_; } 50 method()51 constexpr const internal::Method& method() const { return method_; } 52 call_id()53 constexpr const uint32_t& call_id() const { return call_id_; } 54 55 // For testing use only set_channel_id(uint32_t channel_id)56 void set_channel_id(uint32_t channel_id) { channel_id_ = channel_id; } 57 58 private: 59 Endpoint& server_; 60 uint32_t channel_id_; 61 Service& service_; 62 const internal::Method& method_; 63 uint32_t call_id_; 64 }; 65 66 } // namespace internal 67 } // namespace pw::rpc 68