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_assert/assert.h" 20 #include "pw_rpc/internal/channel.h" 21 22 namespace pw::rpc { 23 24 class ServerContext; 25 class Service; 26 27 namespace internal { 28 29 class Method; 30 class Server; 31 32 // Collects information for an ongoing RPC being processed by the server. 33 // The Server creates a ServerCall object to represent a method invocation. The 34 // ServerCall is copied into a ServerWriter or ServerReader for streaming RPCs. 35 // 36 // ServerCall is a strictly internal class. ServerContext is the public 37 // interface to the internal::ServerCall. 38 class ServerCall { 39 public: ServerCall()40 constexpr ServerCall() 41 : server_(nullptr), 42 channel_(nullptr), 43 service_(nullptr), 44 method_(nullptr) {} 45 ServerCall(Server & server,Channel & channel,Service & service,const internal::Method & method)46 constexpr ServerCall(Server& server, 47 Channel& channel, 48 Service& service, 49 const internal::Method& method) 50 : server_(&server), 51 channel_(&channel), 52 service_(&service), 53 method_(&method) {} 54 55 constexpr ServerCall(const ServerCall&) = default; 56 constexpr ServerCall& operator=(const ServerCall&) = default; 57 58 // Access the ServerContext for this call. Defined in pw_rpc/server_context.h. 59 ServerContext& context(); 60 server()61 Server& server() const { 62 PW_DCHECK_NOTNULL(server_); 63 return *server_; 64 } 65 channel()66 Channel& channel() const { 67 PW_DCHECK_NOTNULL(channel_); 68 return *channel_; 69 } 70 service()71 Service& service() const { 72 PW_DCHECK_NOTNULL(service_); 73 return *service_; 74 } 75 method()76 const internal::Method& method() const { 77 PW_DCHECK_NOTNULL(method_); 78 return *method_; 79 } 80 81 private: 82 Server* server_; 83 Channel* channel_; 84 Service* service_; 85 const internal::Method* method_; 86 }; 87 88 } // namespace internal 89 } // namespace pw::rpc 90