Pigweed
C/C++ API Reference
Home
Modules
Loading...
Searching...
No Matches
client_server.h
1
// Copyright 2021 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 "pw_rpc/client.h"
17
#include "pw_rpc/server.h"
18
19
namespace
pw::rpc {
20
22
23
// Class that wraps both an RPC client and a server, simplifying RPC setup when
24
// a device needs to function as both.
25
class
ClientServer
{
26
public
:
27
// If dynamic allocation is supported, it is not necessary to preallocate a
28
// channels list.
29
#if PW_RPC_DYNAMIC_ALLOCATION
30
_PW_RPC_CONSTEXPR
ClientServer
() =
default
;
31
#endif
// PW_RPC_DYNAMIC_ALLOCATION
32
33
_PW_RPC_CONSTEXPR
ClientServer
(
span<Channel>
channels)
34
: client_(channels), server_(channels) {}
35
36
// Sends a packet to either the client or the server, depending on its type.
37
Status
ProcessPacket(
ConstByteSpan
packet);
38
39
constexpr
Client
& client() {
return
client_; }
40
constexpr
Server
& server() {
return
server_; }
41
42
private
:
43
Client
client_;
44
Server
server_;
45
};
46
48
49
}
// namespace pw::rpc
pw::Status
Definition:
status.h:109
pw::rpc::Client
Definition:
client.h:28
pw::rpc::ClientServer
Definition:
client_server.h:25
pw::rpc::Server
Definition:
server.h:36
pw::span
Definition:
span_impl.h:235
pw_rpc
public
pw_rpc
client_server.h
Generated by
1.9.6