• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://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,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MMI_ADAPTER_H
17 #define MMI_ADAPTER_H
18 
19 #include <functional>
20 #include <string>
21 
22 namespace OHOS::NWeb {
23 enum MMIAdapterKeyboardType : int32_t {
24     NONE = 0,
25     UNKNOWN_TYPE = 1,
26     ALPHABETIC_KEYBOARD = 2,
27     DIGITAL_KEYBOARD = 3,
28     HANDWRITING_PEN = 4,
29     REMOTE_CONTROL = 5,
30 };
31 
32 struct MMIDeviceInfoAdapter {
33 public:
34     int32_t id = -1;
35     int32_t type = 0;
36     int32_t bus = 0;
37     int32_t version = 0;
38     int32_t product = 0;
39     int32_t vendor = 0;
40     std::string name;
41     std::string phys;
42     std::string uniq;
43 };
44 
45 class MMIListenerAdapter {
46 public:
47     MMIListenerAdapter() = default;
48     virtual ~MMIListenerAdapter() = default;
49     virtual void OnDeviceAdded(int32_t deviceId, const std::string &type) = 0;
50     virtual void OnDeviceRemoved(int32_t deviceId, const std::string &type) = 0;
51 };
52 
53 using InputEventCallback = std::function<void(int32_t, int32_t)>;
54 
55 class MMIAdapter {
56 public:
57     MMIAdapter() = default;
58 
59     virtual ~MMIAdapter() = default;
60 
61     virtual const char* KeyCodeToString(int32_t keyCode) = 0;
62 
63     virtual int32_t RegisterMMIInputListener(const InputEventCallback&& eventCallback) = 0;
64 
65     virtual void UnregisterMMIInputListener(int32_t monitorId) = 0;
66 
67     virtual int32_t RegisterDevListener(std::string type, std::shared_ptr<MMIListenerAdapter> listener) = 0;
68 
69     virtual int32_t UnregisterDevListener(std::string type) = 0;
70 
71     virtual int32_t GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback) = 0;
72 
73     virtual int32_t GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback) = 0;
74 
75     virtual int32_t GetDeviceInfo(int32_t deviceId, std::function<void(const MMIDeviceInfoAdapter&)> callback) = 0;
76 };
77 } // namespace OHOS::NWeb
78 
79 #endif // MMI_ADAPTER_H