• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 /*! \file MessageHandler.h */
17 #ifndef SERVICES_INCLUDE_MESSAGE_HANDLER_H
18 #define SERVICES_INCLUDE_MESSAGE_HANDLER_H
19 
20 #include <condition_variable>
21 #include <mutex>
22 #include <queue>
23 
24 #include "global.h"
25 #include "message.h"
26 #include "message_parcel.h"
27 
28 namespace OHOS {
29 namespace MiscServices {
30 namespace MessageID {
31 enum {
32     MSG_ID_USER_START = 0,       //  a user started
33     MSG_ID_USER_REMOVED,     // a user removed
34     MSG_ID_PACKAGE_REMOVED,  // a package is removed
35     MSG_ID_SELECT_BY_RANGE,
36     MSG_ID_SELECT_BY_MOVEMENT,
37     MSG_ID_HANDLE_EXTEND_ACTION,
38 
39     MSG_ID_HIDE_KEYBOARD_SELF, // hide the current keyboard
40     MSG_ID_START_INPUT_SERVICE,
41 
42     // the request from IMSA to IMC
43     MSG_ID_INSERT_CHAR,
44     MSG_ID_DELETE_FORWARD,
45     MSG_ID_DELETE_BACKWARD,
46     MSG_ID_ON_INPUT_STOP,
47     MSG_ID_SEND_KEYBOARD_STATUS,
48     MSG_ID_SEND_FUNCTION_KEY,
49     MSG_ID_MOVE_CURSOR,
50     MSG_ID_ON_SWITCH_INPUT,
51     MSG_ID_GET_TEXT_INDEX_AT_CURSOR,
52     MSG_ID_GET_TEXT_BEFORE_CURSOR,
53     MSG_ID_GET_TEXT_AFTER_CURSOR,
54     MSG_ID_ON_PANEL_STATUS_CHANGE,
55 
56     // the request from IMSA to IMA
57     MSG_ID_STOP_INPUT_SERVICE,
58     MSG_ID_INIT_INPUT_CONTROL_CHANNEL,
59     MSG_ID_SET_SUBTYPE,
60 
61     // the request from IMC to IMA
62     MSG_ID_ON_CURSOR_UPDATE,
63     MSG_ID_ON_SELECTION_CHANGE,
64     MSG_ID_ON_CONFIGURATION_CHANGE,
65     MSG_ID_QUIT_WORKER_THREAD,
66 };
67 }
68 
69 class MessageHandler {
70 public:
71     MessageHandler();
72     ~MessageHandler();
73     void SendMessage(Message *msg);
74     Message *GetMessage();
75     static MessageHandler *Instance();
76 
77 private:
78     std::mutex mMutex;            // a mutex to guard message queue
79     std::condition_variable mCV;  // condition variable to work with mMutex
80     std::queue<Message *> mQueue; // Message queue, guarded by mMutex;
81 
82     MessageHandler(const MessageHandler &);
83     MessageHandler &operator=(const MessageHandler &);
84     MessageHandler(const MessageHandler &&);
85     MessageHandler &operator=(const MessageHandler &&);
86 };
87 } // namespace MiscServices
88 } // namespace OHOS
89 #endif // SERVICES_INCLUDE_MESSAGE_HANDLER_H
90