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
17 #ifndef _LIBINPUT_INPUT_EVENT_LABELS_H
18 #define _LIBINPUT_INPUT_EVENT_LABELS_H
19
20 #include <input/Input.h>
21 #include <android/keycodes.h>
22 #include <unordered_map>
23
24 namespace android {
25
26 template<typename T, size_t N>
size(T (&)[N])27 size_t size(T (&)[N]) { return N; }
28
29 struct InputEventLabel {
30 const char *literal;
31 int value;
32 };
33
34 // NOTE: If you want a new key code, axis code, led code or flag code in keylayout file,
35 // then you must add it to InputEventLabels.cpp.
36
37 class InputEventLookup {
38 public:
39 static int lookupValueByLabel(const std::unordered_map<std::string, int>& map,
40 const char* literal);
41
42 static const char* lookupLabelByValue(const std::vector<InputEventLabel>& vec, int value);
43
44 static int32_t getKeyCodeByLabel(const char* label);
45
46 static const char* getLabelByKeyCode(int32_t keyCode);
47
48 static uint32_t getKeyFlagByLabel(const char* label);
49
50 static int32_t getAxisByLabel(const char* label);
51
52 static const char* getAxisLabel(int32_t axisId);
53
54 static int32_t getLedByLabel(const char* label);
55
56 private:
57 static const std::unordered_map<std::string, int> KEYCODES;
58
59 static const std::vector<InputEventLabel> KEY_NAMES;
60
61 static const std::unordered_map<std::string, int> AXES;
62
63 static const std::vector<InputEventLabel> AXES_NAMES;
64
65 static const std::unordered_map<std::string, int> LEDS;
66
67 static const std::unordered_map<std::string, int> FLAGS;
68 };
69
70 } // namespace android
71 #endif // _LIBINPUT_INPUT_EVENT_LABELS_H
72