xref: /aosp_15_r20/external/pigweed/pw_digital_io/public/pw_digital_io/digital_io_service.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 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 #pragma once
16 
17 #include "pw_digital_io/digital_io.h"
18 #include "pw_digital_io/digital_io.pwpb.h"
19 #include "pw_digital_io/digital_io.rpc.pwpb.h"
20 #include "pw_function/function.h"
21 #include "pw_rpc/pwpb/server_reader_writer.h"
22 #include "pw_span/span.h"
23 
24 namespace pw::digital_io {
25 
26 // Implementation class for pw.digital_io.DigitalIo.
27 //
28 // Takes an array of DigitalIoOptional lines to be exposed via the service.
29 class DigitalIoService
30     : public pw_rpc::pwpb::DigitalIo::Service<DigitalIoService> {
31  public:
DigitalIoService(pw::span<std::reference_wrapper<DigitalIoOptional>> lines)32   explicit DigitalIoService(
33       pw::span<std::reference_wrapper<DigitalIoOptional>> lines)
34       : lines_(lines) {}
35 
36   void Enable(const pwpb::DigitalIoEnableRequest::Message& request,
37               rpc::PwpbUnaryResponder<pwpb::DigitalIoEnableResponse::Message>&
38                   responder);
39 
40   void SetState(
41       const pwpb::DigitalIoSetStateRequest::Message& request,
42       rpc::PwpbUnaryResponder<pwpb::DigitalIoSetStateResponse::Message>&
43           responder);
44 
45   void GetState(
46       const pwpb::DigitalIoGetStateRequest::Message& request,
47       rpc::PwpbUnaryResponder<pwpb::DigitalIoGetStateResponse::Message>&
48           responder);
49 
50  private:
51   pw::span<std::reference_wrapper<DigitalIoOptional>> lines_;
52 };
53 
54 }  // namespace pw::digital_io
55