• 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 FM_IMMS_PROJECT_MESSAGEHANDLER_H
18 #define FM_IMMS_PROJECT_MESSAGEHANDLER_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_LOCK, // a user locked
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_START_INPUT, // start input
45         MSG_ID_STOP_INPUT, // stop input
46         MSG_ID_RELEASE_INPUT, // release input
47         MSG_ID_SET_CORE_AND_AGENT,
48         MSG_HIDE_CURRENT_INPUT,
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_ADVANCE_TO_NEXT, // switch to next
58         MSG_ID_SET_DISPLAY_MODE, // set display mode
59 
60         MSG_ID_SHELL_COMMAND, // shell command
61         MSG_ID_EXIT_SERVICE, // exit service
62 
63         // the request from IMSA to IMC
64         MSG_ID_INSERT_CHAR,
65         MSG_ID_DELETE_FORWARD,
66         MSG_ID_DELETE_BACKWARD,
67         MSG_ID_CLOSE,
68         MSG_ID_ON_INPUT_READY,
69         MSG_ID_SEND_KEYBOARD_STATUS,
70         MSG_ID_SEND_FUNCTION_KEY,
71         MSG_ID_MOVE_CURSOR,
72 
73         // the request from IMSA to IMA
74         MSG_ID_SET_CLIENT_STATE,
75         MSG_ID_SHOW_KEYBOARD,
76         MSG_ID_INITIALIZE_INPUT,
77         MSG_ID_HIDE_KEYBOARD,
78         MSG_ID_SET_KEYBOARD_TYPE,
79         MSG_ID_START_INPUT_SERVICE,
80         MSG_ID_STOP_INPUT_SERVICE,
81         MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT,
82         MSG_ID_INIT_INPUT_CONTROL_CHANNEL,
83 
84         // the request from IMC to IMA
85         MSG_ID_ON_CURSOR_UPDATE,
86         MSG_ID_ON_SELECTION_CHANGE,
87     };
88 }
89 
90     class MessageHandler {
91     public:
92         MessageHandler();
93         ~MessageHandler();
94         void SendMessage(Message *msg);
95         Message *GetMessage();
96         static MessageHandler *Instance();
97 
98     private:
99         std::mutex mMutex; // a mutex to guard message queue
100         std::condition_variable mCV; // condition variable to work with mMutex
101         std::queue<Message*> mQueue; // Message queue, guarded by mMutex;
102 
103         MessageHandler(const MessageHandler&);
104         MessageHandler& operator =(const MessageHandler&);
105         MessageHandler(const MessageHandler&&);
106         MessageHandler& operator =(const MessageHandler&&);
107     };
108 }
109 }
110 #endif // FM_IMMS_PROJECT_MESSAGEHANDLER_H
111