1 /*
2  * Copyright (c) 2021-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 #ifndef MULTIMODAL_EVENT_HANDLER_H
16 #define MULTIMODAL_EVENT_HANDLER_H
17 
18 #include "nocopyable.h"
19 #include "singleton.h"
20 
21 #include "if_mmi_client.h"
22 #include "key_event_input_subscribe_manager.h"
23 #include "pointer_event.h"
24 #include "proto.h"
25 #include "switch_event_input_subscribe_manager.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 enum RES_STATUS : uint8_t {
30     REG_STATUS_NOT_SYNC = 0,
31     REG_STATUS_SYNCED = 1
32 };
33 
34 class MultimodalEventHandler final {
35     DECLARE_SINGLETON(MultimodalEventHandler);
36 
37 public:
38     DISALLOW_MOVE(MultimodalEventHandler);
39 
40     MMIClientPtr GetMMIClient();
41     bool InitClient(EventHandlerPtr eventHandler = nullptr);
42 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
43     int32_t SubscribeKeyEvent(const KeyEventInputSubscribeManager::SubscribeKeyEventInfo& subscribeInfo);
44     int32_t UnsubscribeKeyEvent(int32_t subscribeId);
45     int32_t SubscribeHotkey(const KeyEventInputSubscribeManager::SubscribeKeyEventInfo &subscribeInfo);
46     int32_t UnsubscribeHotkey(int32_t subscribeId);
47     int32_t InjectEvent(const std::shared_ptr<KeyEvent> keyEvent, bool isNativeInject);
48 #endif // OHOS_BUILD_ENABLE_KEYBOARD
49 #ifdef OHOS_BUILD_ENABLE_SWITCH
50     int32_t SubscribeSwitchEvent(int32_t subscribeId, int32_t switchType);
51     int32_t UnsubscribeSwitchEvent(int32_t subscribeId);
52 #endif // OHOS_BUILD_ENABLE_SWITCH
53 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
54     int32_t InjectPointerEvent(std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject);
55 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
56 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
57     int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY);
58 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
59     int32_t Authorize(bool isAuthorize);
60     int32_t CancelInjection();
61 
62 private:
63     int32_t SetClientInfo(int32_t pid, uint64_t readThreadId);
64     MMIClientPtr client_ { nullptr };
65 };
66 
67 #define MMIEventHdl ::OHOS::Singleton<MultimodalEventHandler>::GetInstance()
68 } // namespace MMI
69 } // namespace OHOS
70 #endif // MULTIMODAL_EVENT_HANDLER_H