1 /*
2  * Copyright (c) 2023-2024 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 OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
17 #define OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
18 
19 #include <thread>
20 
21 #include "event_handler.h"
22 
23 #ifdef SUPPORT_MULTIMODALINPUT_SERVICE
24 #include "i_input_event_consumer.h"
25 #include "input_manager.h"
26 #endif
27 #include "single_instance.h"
28 
29 namespace OHOS {
30 namespace DistributedSchedule {
31 class MMIAdapter {
32 public:
33     DECLARE_SINGLE_INSTANCE_BASE(MMIAdapter);
34 public:
35     MMIAdapter() = default;
36     virtual ~MMIAdapter() = default;
37 
38     void Init();
39     void UnInit();
40     int32_t AddMMIListener();
41     void RemoveMMIListener(int32_t monitorId);
42 #ifdef SUPPORT_MULTIMODALINPUT_SERVICE
43     class MMIEventCallback : public MMI::IInputEventConsumer {
44         void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
45         void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
46         void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
47     };
48 
49 private:
50     void StartEvent();
51     void PostRawMMIEvent();
52     void PostUnfreezeMMIEvent();
53     void HandleRawMMIEvent();
54     void HandleUnfreezeMMIEvent();
55 
56     std::thread eventThread_;
57     std::condition_variable eventCon_;
58     std::mutex eventMutex_;
59     std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
60     std::shared_ptr<MMI::IInputEventConsumer> mmiCallback_;
61     bool isMMIFreezed_ = false;
62 #endif
63 };
64 }  // namespace DistributedSchedule
65 }  // namespace OHOS
66 #endif  // OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
67