• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 INPUT_HANDLER_MANAGER_H
17 #define INPUT_HANDLER_MANAGER_H
18 
19 #include <limits>
20 #include <map>
21 #include <mutex>
22 #include "input_handler_type.h"
23 #include "i_input_event_consumer.h"
24 #include "pointer_event.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 class InputHandlerManager : public Singleton<OHOS::MMI::InputHandlerManager> {
30 public:
31     int32_t AddHandler(InputHandlerType handlerType, std::shared_ptr<IInputEventConsumer> consumer);
32     void RemoveHandler(int32_t handlerId, InputHandlerType handlerType);
33     void MarkConsumed(int32_t monitorId, int32_t eventId);
34     void OnInputEvent(int32_t handlerId, std::shared_ptr<KeyEvent> keyEvent);
35     void OnInputEvent(int32_t handlerId, std::shared_ptr<PointerEvent> pointerEvent);
36     void OnConnected();
37 
38 private:
39     struct Handler {
40         int32_t handlerId_;
41         InputHandlerType handlerType_;
42         std::shared_ptr<IInputEventConsumer> consumer_;
43     };
44 
45 private:
46     int32_t GetNextId();
47     int32_t AddLocal(int32_t handlerId, InputHandlerType handlerType, std::shared_ptr<IInputEventConsumer> monitor);
48     void AddToServer(int32_t handlerId, InputHandlerType handlerType);
49     int32_t RemoveLocal(int32_t handlerId, InputHandlerType handlerType);
50     void RemoveFromServer(int32_t handlerId, InputHandlerType handlerType);
51     std::shared_ptr<IInputEventConsumer> FindHandler(int32_t handlerId);
52 
53 private:
54     std::mutex lockHandlers_;
55     std::map<int32_t, Handler> inputHandlers_;
56     int32_t nextId_ { 1 };
57 };
58 } // namespace MMI
59 } // namespace OHOS
60 
61 #endif // INPUT_HANDLER_MANAGER_H