• 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 <queue>
21 #include <mutex>
22 #include <condition_variable>
23 #include "global.h"
24 #include "message_parcel.h"
25 #include "message.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 namespace MessageID {
30     enum {
31         // for system broadcast
32         MSG_ID_SYSTEM_START = 0, // system started
33         MSG_ID_SYSTEM_STOP, // system stopped
34         MSG_ID_USER_START, //  a user started
35         MSG_ID_USER_STOP, // a user stopped
36         MSG_ID_USER_UNLOCK, // a user unlocked
37         MSG_ID_USER_REMOVED,     // a user removed
38         MSG_ID_PACKAGE_ADDED, // a package is installed
39         MSG_ID_PACKAGE_REMOVED, // a package is removed
40         MSG_ID_SETTING_CHANGED, // input method setting is changed
41 
42         // the request from client
43         MSG_ID_PREPARE_INPUT, // prepare input
44         MSG_ID_RELEASE_INPUT, // release input
45         MSG_ID_SET_CORE_AND_AGENT,
46         MSG_HIDE_CURRENT_INPUT,
47         MSG_SHOW_CURRENT_INPUT,
48         MSG_ID_SWITCH_INPUT_METHOD, // switch input method
49 
50         // the request to handle the condition that the remote object died
51         MSG_ID_CLIENT_DIED, // input client died
52         MSG_ID_IMS_DIED, // input method service died
53         MSG_ID_DISABLE_IMS, // disable input method service
54         MSG_ID_RESTART_IMS, // restart input method service
55         MSG_ID_HIDE_KEYBOARD_SELF, // hide the current keyboard
56         MSG_ID_DISPLAY_OPTIONAL_INPUT_METHOD,
57         MSG_ID_START_INPUT_SERVICE,
58 
59         MSG_ID_SHELL_COMMAND, // shell command
60         MSG_ID_EXIT_SERVICE, // exit service
61 
62         // the request from IMSA to IMC
63         MSG_ID_INSERT_CHAR,
64         MSG_ID_DELETE_FORWARD,
65         MSG_ID_DELETE_BACKWARD,
66         MSG_ID_CLOSE,
67         MSG_ID_ON_INPUT_READY,
68         MSG_ID_SEND_KEYBOARD_STATUS,
69         MSG_ID_SEND_FUNCTION_KEY,
70         MSG_ID_MOVE_CURSOR,
71         MSG_ID_ON_SWITCH_INPUT,
72         MSG_ID_HANDLE_SET_SELECTION,
73         MSG_ID_HANDLE_EXTEND_ACTION,
74         MSG_ID_HANDLE_SELECT,
75         MSG_ID_GET_TEXT_BEFORE_CURSOR,
76         MSG_ID_GET_TEXT_AFTER_CURSOR,
77 
78         // the request from IMSA to IMA
79         MSG_ID_SHOW_KEYBOARD,
80         MSG_ID_HIDE_KEYBOARD,
81         MSG_ID_STOP_INPUT_SERVICE,
82         MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT,
83         MSG_ID_INIT_INPUT_CONTROL_CHANNEL,
84         MSG_ID_SET_SUBTYPE,
85 
86         // the request from IMC to IMA
87         MSG_ID_ON_CURSOR_UPDATE,
88         MSG_ID_ON_SELECTION_CHANGE,
89 
90         MSG_ID_QUIT_WORKER_THREAD,
91     };
92 }
93 
94     class MessageHandler {
95     public:
96         MessageHandler();
97         ~MessageHandler();
98         void SendMessage(Message *msg);
99         Message *GetMessage();
100         static MessageHandler *Instance();
101 
102     private:
103         std::mutex mMutex; // a mutex to guard message queue
104         std::condition_variable mCV; // condition variable to work with mMutex
105         std::queue<Message*> mQueue; // Message queue, guarded by mMutex;
106 
107         MessageHandler(const MessageHandler&);
108         MessageHandler& operator =(const MessageHandler&);
109         MessageHandler(const MessageHandler&&);
110         MessageHandler& operator =(const MessageHandler&&);
111     };
112 } // namespace MiscServices
113 } // namespace OHOS
114 #endif // SERVICES_INCLUDE_MESSAGE_HANDLER_H
115