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
15 #include "pw_rpc/raw/internal/method.h"
16
17 #include <cstddef>
18 #include <cstring>
19
20 #include "pw_rpc/internal/packet.h"
21
22 namespace pw::rpc::internal {
23
AsynchronousUnaryInvoker(const CallContext & context,const Packet & request)24 void RawMethod::AsynchronousUnaryInvoker(const CallContext& context,
25 const Packet& request) {
26 RawUnaryResponder responder(context.ClaimLocked());
27 context.server().CleanUpCalls();
28 static_cast<const RawMethod&>(context.method())
29 .function_.asynchronous_unary(
30 context.service(), request.payload(), responder);
31 }
32
ServerStreamingInvoker(const CallContext & context,const Packet & request)33 void RawMethod::ServerStreamingInvoker(const CallContext& context,
34 const Packet& request) {
35 RawServerWriter server_writer(context.ClaimLocked());
36 context.server().CleanUpCalls();
37 static_cast<const RawMethod&>(context.method())
38 .function_.server_streaming(
39 context.service(), request.payload(), server_writer);
40 }
41
ClientStreamingInvoker(const CallContext & context,const Packet &)42 void RawMethod::ClientStreamingInvoker(const CallContext& context,
43 const Packet&) {
44 RawServerReader reader(context.ClaimLocked());
45 context.server().CleanUpCalls();
46 static_cast<const RawMethod&>(context.method())
47 .function_.stream_request(context.service(), reader);
48 }
49
BidirectionalStreamingInvoker(const CallContext & context,const Packet &)50 void RawMethod::BidirectionalStreamingInvoker(const CallContext& context,
51 const Packet&) {
52 RawServerReaderWriter reader_writer(context.ClaimLocked());
53 context.server().CleanUpCalls();
54 static_cast<const RawMethod&>(context.method())
55 .function_.stream_request(context.service(), reader_writer);
56 }
57
58 } // namespace pw::rpc::internal
59