Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Prabir Pradhan | c08b0db | 2022-09-10 00:57:15 +0000 | [diff] [blame] | 17 | #pragma once |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 18 | |
| 19 | #include <input/Input.h> |
| 20 | #include <android/keycodes.h> |
Chris Ye | fff9edb | 2020-08-13 16:12:54 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 22 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | |
| 25 | template<typename T, size_t N> |
| 26 | size_t size(T (&)[N]) { return N; } |
| 27 | |
| 28 | struct InputEventLabel { |
| 29 | const char *literal; |
| 30 | int value; |
| 31 | }; |
| 32 | |
Prabir Pradhan | 1e63fc2 | 2023-02-23 19:03:03 +0000 | [diff] [blame] | 33 | struct EvdevEventLabel { |
| 34 | std::string type; |
| 35 | std::string code; |
| 36 | std::string value; |
| 37 | }; |
| 38 | |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 39 | // NOTE: If you want a new key code, axis code, led code or flag code in keylayout file, |
| 40 | // then you must add it to InputEventLabels.cpp. |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 41 | |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 42 | class InputEventLookup { |
| 43 | public: |
Siarhei Vishniakou | 5df3493 | 2023-01-23 12:41:01 -0800 | [diff] [blame] | 44 | static std::optional<int> lookupValueByLabel(const std::unordered_map<std::string, int>& map, |
| 45 | const char* literal); |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 46 | |
| 47 | static const char* lookupLabelByValue(const std::vector<InputEventLabel>& vec, int value); |
| 48 | |
Siarhei Vishniakou | 5df3493 | 2023-01-23 12:41:01 -0800 | [diff] [blame] | 49 | static std::optional<int> getKeyCodeByLabel(const char* label); |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 50 | |
| 51 | static const char* getLabelByKeyCode(int32_t keyCode); |
| 52 | |
Siarhei Vishniakou | 5df3493 | 2023-01-23 12:41:01 -0800 | [diff] [blame] | 53 | static std::optional<int> getKeyFlagByLabel(const char* label); |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 54 | |
Siarhei Vishniakou | 5df3493 | 2023-01-23 12:41:01 -0800 | [diff] [blame] | 55 | static std::optional<int> getAxisByLabel(const char* label); |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 56 | |
| 57 | static const char* getAxisLabel(int32_t axisId); |
| 58 | |
Siarhei Vishniakou | 5df3493 | 2023-01-23 12:41:01 -0800 | [diff] [blame] | 59 | static std::optional<int> getLedByLabel(const char* label); |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 60 | |
Prabir Pradhan | 1e63fc2 | 2023-02-23 19:03:03 +0000 | [diff] [blame] | 61 | static EvdevEventLabel getLinuxEvdevLabel(int32_t type, int32_t code, int32_t value); |
| 62 | |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 63 | private: |
| 64 | static const std::unordered_map<std::string, int> KEYCODES; |
| 65 | |
| 66 | static const std::vector<InputEventLabel> KEY_NAMES; |
| 67 | |
| 68 | static const std::unordered_map<std::string, int> AXES; |
| 69 | |
| 70 | static const std::vector<InputEventLabel> AXES_NAMES; |
| 71 | |
| 72 | static const std::unordered_map<std::string, int> LEDS; |
| 73 | |
| 74 | static const std::unordered_map<std::string, int> FLAGS; |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 77 | } // namespace android |