1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "InputMapper.h"
20 
21 namespace android {
22 
23 class SwitchInputMapper : public InputMapper {
24 public:
25     template <class T, class... Args>
26     friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
27                                                 const InputReaderConfiguration& readerConfig,
28                                                 Args... args);
29     virtual ~SwitchInputMapper();
30 
31     virtual uint32_t getSources() const override;
32     [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override;
33 
34     virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) override;
35     virtual void dump(std::string& dump) override;
36 
37 private:
38     uint32_t mSwitchValues;
39     uint32_t mUpdatedSwitchMask;
40 
41     explicit SwitchInputMapper(InputDeviceContext& deviceContext,
42                                const InputReaderConfiguration& readerConfig);
43     void processSwitch(int32_t switchCode, int32_t switchValue);
44     [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when);
45 };
46 
47 } // namespace android
48