1 /*
2  * Copyright (C) 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 FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H
17 #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H
18 #include <map>
19 #include <set>
20 #include <memory>
21 #include "ime_event_listener.h"
22 #include "visibility.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 class ImeEventMonitorManager {
27 public:
28     /**
29      * @brief Get the instance of ImeEventMonitorManager.
30      *
31      * This function is used to get the instance of ImeEventMonitorManager.
32      *
33      * @return The instance of ImeEventMonitorManager.
34      * @since 12
35     */
36     IMF_API static ImeEventMonitorManager &GetInstance();
37 
38     /**
39      * @brief Register Ime Event Listener.
40      *
41      * This function is used to Register Ime Event Listener, only IME_SHOW and IME_HIDE supported at present
42      *
43      * @param eventFlag Indicates the flag of the ime event to be registered
44      * @param listener Indicates the the listener to be registered.
45      * @return Returns 0 for success, others for failure.
46      * @since 12
47     */
48     IMF_API int32_t RegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr<ImeEventListener> &listener);
49 
50     /**
51      * @brief UnRegister Ime Event Listener.
52      *
53      * This function is used to UnRegister Ime Event Listener, only IME_SHOW and IME_HIDE supported at present
54      *
55      * @param types Indicates the flag of the ime event to be unRegistered
56      * @param listener Indicates the the listener to be unregistered.
57      * @return Returns 0 for success, others for failure.
58      * @since 12
59     */
60     IMF_API int32_t UnRegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr<ImeEventListener> &listener);
61 
62 private:
63     static constexpr uint32_t ALL_EVENT_MASK = EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK;
64     ImeEventMonitorManager();
65     ~ImeEventMonitorManager();
66     bool IsParamValid(uint32_t eventFlag, const std::shared_ptr<ImeEventListener> &listener);
67 };
68 } // namespace MiscServices
69 } // namespace OHOS
70 #endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_IME_EVENT_MONITOR_MANAGER_H