1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#ifndef OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
17686862fbSopenharmony_ci#define OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
18686862fbSopenharmony_ci
19686862fbSopenharmony_ci#include <thread>
20686862fbSopenharmony_ci
21686862fbSopenharmony_ci#include "event_handler.h"
22686862fbSopenharmony_ci
23686862fbSopenharmony_ci#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
24686862fbSopenharmony_ci#include "i_input_event_consumer.h"
25686862fbSopenharmony_ci#include "input_manager.h"
26686862fbSopenharmony_ci#endif
27686862fbSopenharmony_ci#include "single_instance.h"
28686862fbSopenharmony_ci
29686862fbSopenharmony_cinamespace OHOS {
30686862fbSopenharmony_cinamespace DistributedSchedule {
31686862fbSopenharmony_ciclass MMIAdapter {
32686862fbSopenharmony_cipublic:
33686862fbSopenharmony_ci    DECLARE_SINGLE_INSTANCE_BASE(MMIAdapter);
34686862fbSopenharmony_cipublic:
35686862fbSopenharmony_ci    MMIAdapter() = default;
36686862fbSopenharmony_ci    virtual ~MMIAdapter() = default;
37686862fbSopenharmony_ci
38686862fbSopenharmony_ci    void Init();
39686862fbSopenharmony_ci    void UnInit();
40686862fbSopenharmony_ci    int32_t AddMMIListener();
41686862fbSopenharmony_ci    void RemoveMMIListener(int32_t monitorId);
42686862fbSopenharmony_ci#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
43686862fbSopenharmony_ci    class MMIEventCallback : public MMI::IInputEventConsumer {
44686862fbSopenharmony_ci        void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
45686862fbSopenharmony_ci        void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
46686862fbSopenharmony_ci        void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
47686862fbSopenharmony_ci    };
48686862fbSopenharmony_ci
49686862fbSopenharmony_ciprivate:
50686862fbSopenharmony_ci    void StartEvent();
51686862fbSopenharmony_ci    void PostRawMMIEvent();
52686862fbSopenharmony_ci    void PostUnfreezeMMIEvent();
53686862fbSopenharmony_ci    void HandleRawMMIEvent();
54686862fbSopenharmony_ci    void HandleUnfreezeMMIEvent();
55686862fbSopenharmony_ci
56686862fbSopenharmony_ci    std::thread eventThread_;
57686862fbSopenharmony_ci    std::condition_variable eventCon_;
58686862fbSopenharmony_ci    std::mutex eventMutex_;
59686862fbSopenharmony_ci    std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
60686862fbSopenharmony_ci    std::shared_ptr<MMI::IInputEventConsumer> mmiCallback_;
61686862fbSopenharmony_ci    bool isMMIFreezed_ = false;
62686862fbSopenharmony_ci#endif
63686862fbSopenharmony_ci};
64686862fbSopenharmony_ci}  // namespace DistributedSchedule
65686862fbSopenharmony_ci}  // namespace OHOS
66686862fbSopenharmony_ci#endif  // OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
67