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