blob: b4374acdcc1a4a36b904008c17fcb02e7acfd03f [file] [log] [blame]
Michael Wright872db4f2014-04-22 15:03:51 -07001/*
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 Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Michael Wright872db4f2014-04-22 15:03:51 -070018
19#include <input/Input.h>
20#include <android/keycodes.h>
Chris Yefff9edb2020-08-13 16:12:54 -070021#include <unordered_map>
Michael Wright872db4f2014-04-22 15:03:51 -070022
Michael Wright872db4f2014-04-22 15:03:51 -070023namespace android {
24
25template<typename T, size_t N>
26size_t size(T (&)[N]) { return N; }
27
28struct InputEventLabel {
29 const char *literal;
30 int value;
31};
32
Chris Ye4958d062020-08-20 13:21:10 -070033// NOTE: If you want a new key code, axis code, led code or flag code in keylayout file,
34// then you must add it to InputEventLabels.cpp.
Michael Wright872db4f2014-04-22 15:03:51 -070035
Chris Ye4958d062020-08-20 13:21:10 -070036class InputEventLookup {
37public:
38 static int lookupValueByLabel(const std::unordered_map<std::string, int>& map,
39 const char* literal);
40
41 static const char* lookupLabelByValue(const std::vector<InputEventLabel>& vec, int value);
42
43 static int32_t getKeyCodeByLabel(const char* label);
44
45 static const char* getLabelByKeyCode(int32_t keyCode);
46
47 static uint32_t getKeyFlagByLabel(const char* label);
48
49 static int32_t getAxisByLabel(const char* label);
50
51 static const char* getAxisLabel(int32_t axisId);
52
53 static int32_t getLedByLabel(const char* label);
54
55private:
56 static const std::unordered_map<std::string, int> KEYCODES;
57
58 static const std::vector<InputEventLabel> KEY_NAMES;
59
60 static const std::unordered_map<std::string, int> AXES;
61
62 static const std::vector<InputEventLabel> AXES_NAMES;
63
64 static const std::unordered_map<std::string, int> LEDS;
65
66 static const std::unordered_map<std::string, int> FLAGS;
Michael Wright872db4f2014-04-22 15:03:51 -070067};
68
Michael Wright872db4f2014-04-22 15:03:51 -070069} // namespace android