• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2025 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 INPUTMETHOD_MESSAGE_HANDLER_H
17 #define INPUTMETHOD_MESSAGE_HANDLER_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <queue>
22 
23 #include "global.h"
24 #include "message.h"
25 #include "message_parcel.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 namespace MessageID {
30 enum {
31     MSG_ID_USER_START = 0,  //  a user started
32     MSG_ID_USER_REMOVED,    // a user removed
33     MSG_ID_PACKAGE_REMOVED, // a package is removed
34     MSG_ID_BUNDLE_SCAN_FINISHED, // bundle scan finished
35     MSG_ID_DATA_SHARE_READY, // datashare ready, ready to create data share helper
36     MSG_ID_PACKAGE_ADDED,
37     MSG_ID_PACKAGE_CHANGED,
38     MSG_ID_SYS_LANGUAGE_CHANGED,
39     MSG_ID_SYS_MEMORY_CHANGED,
40     MSG_ID_OS_ACCOUNT_STARTED,
41     MSG_ID_BOOT_COMPLETED,
42     MSG_ID_SCREEN_UNLOCK,
43     MSG_ID_SCREEN_LOCK,
44     MSG_ID_SELECT_BY_RANGE,
45     MSG_ID_SELECT_BY_MOVEMENT,
46     MSG_ID_HANDLE_EXTEND_ACTION,
47     MSG_ID_USER_STOP,
48     MSG_ID_REGULAR_UPDATE_IME_INFO,
49 
50     MSG_ID_HIDE_KEYBOARD_SELF, // hide the current keyboard
51 
52     // the request from IMSA to IMC
53     MSG_ID_INSERT_CHAR,
54     MSG_ID_DELETE_FORWARD,
55     MSG_ID_DELETE_BACKWARD,
56     MSG_ID_ON_INPUT_STOP,
57     MSG_ID_SEND_KEYBOARD_STATUS,
58     MSG_ID_SEND_FUNCTION_KEY,
59     MSG_ID_MOVE_CURSOR,
60     MSG_ID_ON_SWITCH_INPUT,
61     MSG_ID_GET_TEXT_INDEX_AT_CURSOR,
62     MSG_ID_GET_TEXT_BEFORE_CURSOR,
63     MSG_ID_GET_TEXT_AFTER_CURSOR,
64     MSG_ID_ON_PANEL_STATUS_CHANGE,
65 
66     // the request from IMSA to IMA
67     MSG_ID_INIT_INPUT_CONTROL_CHANNEL,
68     MSG_ID_SET_SUBTYPE,
69 
70     // the request from IMC to IMA
71     MSG_ID_ON_CURSOR_UPDATE,
72     MSG_ID_ON_SELECTION_CHANGE,
73     MSG_ID_ON_CONFIGURATION_CHANGE,
74     MSG_ID_ON_ATTRIBUTE_CHANGE,
75     MSG_ID_QUIT_WORKER_THREAD,
76     MSG_ID_SET_COREANDANGENT,
77 
78     MSG_ID_UPDATE_LARGE_MEMORY_STATE,
79 };
80 }
81 
82 class MessageHandler {
83 public:
84     MessageHandler();
85     ~MessageHandler();
86     void SendMessage(Message *msg);
87     Message *GetMessage();
88     static MessageHandler *Instance();
89     static std::mutex handlerMutex_;
90 
91 private:
92     std::mutex mMutex;            // a mutex to guard message queue
93     std::condition_variable mCV;  // condition variable to work with mMutex
94     std::queue<Message *> mQueue; // Message queue, guarded by mMutex;
95 
96     MessageHandler(const MessageHandler &);
97     MessageHandler &operator=(const MessageHandler &);
98     MessageHandler(const MessageHandler &&);
99     MessageHandler &operator=(const MessageHandler &&);
100 };
101 } // namespace MiscServices
102 } // namespace OHOS
103 #endif // INPUTMETHOD_MESSAGE_HANDLER_H
104