• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 INPUT_DEVICE_CONSUMER_HANDLER_H
17 #define INPUT_DEVICE_CONSUMER_HANDLER_H
18 
19 #include <map>
20 
21 #include <singleton.h>
22 
23 #include "gesture_monitor_handler.h"
24 #include "i_input_event_collection_handler.h"
25 #include "i_input_event_handler.h"
26 #include "nap_process.h"
27 
28 namespace OHOS {
29 namespace MMI {
30 class InputDeviceConsumerHandler {
31 
32 public:
33 
34     int32_t SetDeviceConsumerHandler(const std::vector<std::string>& deviceName, SessionPtr sess);
35     void OnSessionLost(int32_t fd);
36     int32_t ClearDeviceConsumerHandler(const std::vector<std::string>& deviceNames, SessionPtr sess);
37 
38     void HandleDeviceConsumerEvent(std::string name, const std::shared_ptr<PointerEvent> pointerEvent);
39 private:
40 
41     class SessionHandler {
42     public:
43 
SessionHandler(SessionPtr session)44         SessionHandler(SessionPtr session) : session_(session)
45         {
46         }
47 
SessionHandler(const SessionHandler & other)48         SessionHandler(const SessionHandler& other)
49         {
50             session_ = other.session_;
51         }
52 
53         void SendToClient(std::shared_ptr<PointerEvent> pointerEvent, NetPacket &pkt) const;
operator()54         void operator()(const SessionHandler& other)
55         {
56             session_ = other.session_;
57         }
58         bool operator<(const SessionHandler& other) const
59         {
60             return (session_ < other.session_);
61         }
62         std::string deviceName_ {""};
63         SessionPtr session_ { nullptr };
64     };
65     class DeviceHandler {
66     public:
67         void HandleEvent(std::string name, std::shared_ptr<PointerEvent> pointerEvent);
68         int32_t RemoveDeviceHandler(const std::vector<std::string>& deviceNames, SessionPtr sess);
69 
70         std::unordered_map<std::string, std::set<SessionHandler>> deviceHandler_;
71     };
72     DeviceHandler deviceConsumerHandler_;
73 };
74 
75 #define DEVICEHANDLER ::OHOS::DelayedSingleton<InputDeviceConsumerHandler>::GetInstance()
76 } // namespace MMI
77 } // namespace OHOS
78 #endif // INPUT_DEVICE_CONSUMER_HANDLER_H
79