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 18 #include "pw_bytes/span.h" 19 #include "pw_rpc/channel.h" 20 #include "pw_rpc/internal/channel.h" 21 #include "pw_rpc/internal/endpoint.h" 22 #include "pw_rpc/internal/lock.h" 23 #include "pw_span/span.h" 24 25 namespace pw::rpc { 26 27 class Client : public internal::Endpoint { 28 public: 29 // If dynamic allocation is supported, it is not necessary to preallocate a 30 // channels list. 31 #if PW_RPC_DYNAMIC_ALLOCATION 32 _PW_RPC_CONSTEXPR Client() = default; 33 #endif // PW_RPC_DYNAMIC_ALLOCATION 34 35 // Creates a client that uses a set of RPC channels. Channels can be shared 36 // between multiple clients and servers. Client(span<Channel> channels)37 _PW_RPC_CONSTEXPR Client(span<Channel> channels) : Endpoint(channels) {} 38 39 // Processes an incoming RPC packet. The packet may be an RPC response or a 40 // control packet, the result of which is processed in this function. Returns 41 // whether the packet was able to be processed: 42 // 43 // OK - The packet was processed by the client. 44 // DATA_LOSS - Failed to decode the packet. 45 // INVALID_ARGUMENT - The packet is intended for a server, not a client. 46 // UNAVAILABLE - No RPC channel with the requested ID was found. 47 // 48 Status ProcessPacket(ConstByteSpan data) 49 PW_LOCKS_EXCLUDED(internal::rpc_lock()); 50 51 private: 52 // Remove these internal::Endpoint functions from the public interface. 53 using Endpoint::active_call_count; 54 using Endpoint::ClaimLocked; 55 using Endpoint::CleanUpCalls; 56 using Endpoint::GetInternalChannel; 57 }; 58 59 } // namespace pw::rpc 60