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