• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 DISTRIBUTED_INPUT_HANDLER_H
17 #define DISTRIBUTED_INPUT_HANDLER_H
18 
19 #include <functional>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 
24 #include <sys/epoll.h>
25 #include <linux/input.h>
26 
27 #include "ihardware_handler.h"
28 #include "single_instance.h"
29 
30 #include "constants_dinput.h"
31 #include "input_hub.h"
32 
33 #ifndef API_EXPORT
34 #define API_EXPORT __attribute__((visibility("default")))
35 #endif
36 
37 namespace OHOS {
38 namespace DistributedHardware {
39 namespace DistributedInput {
40 class DistributedInputHandler : public IHardwareHandler {
41 DECLARE_SINGLE_INSTANCE_BASE(DistributedInputHandler);
42 public:
43     API_EXPORT int32_t Initialize() override;
44     API_EXPORT virtual std::vector<DHItem> Query() override;
45     API_EXPORT virtual std::map<std::string, std::string> QueryExtraInfo() override;
46     API_EXPORT bool IsSupportPlugin() override;
47     API_EXPORT void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
48     API_EXPORT void UnRegisterPluginListener() override;
49 
50     API_EXPORT void FindDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas);
51     API_EXPORT void FindDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
52 private:
53     DistributedInputHandler();
54     ~DistributedInputHandler();
55     void StructTransJson(const InputDevice &pBuf, std::string &strDescriptor);
56     std::shared_ptr<PluginListener> m_listener;
57     bool InitCollectEventsThread();
58     void NotifyHardWare(int iCnt);
59 
60     pthread_t collectThreadID_;
61     bool isCollectingEvents_;
62     bool isStartCollectEventThread;
63     static void *CollectEventsThread(void *param);
64     void StartInputMonitorDeviceThread();
65     void StopInputMonitorDeviceThread();
66 
67     // The event queue.
68     static const int inputDeviceBufferSize = 32;
69     InputDeviceEvent mEventBuffer[inputDeviceBufferSize] = {};
70     std::mutex operationMutex_;
71     std::unique_ptr<InputHub> inputHub_;
72 };
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 API_EXPORT IHardwareHandler* GetHardwareHandler();
78 #ifdef __cplusplus
79 }
80 #endif
81 } // namespace DistributedInput
82 } // namespace DistributedHardware
83 } // namespace OHOS
84 
85 #endif // DISTRIBUTED_INPUT_HANDLER_H
86