• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_EVENT_BUILDER_H
17 #define INPUT_EVENT_BUILDER_H
18 
19 #include "display_manager.h"
20 #include "key_event.h"
21 #include "nocopyable.h"
22 #include "pointer_event.h"
23 
24 #include "cooperate_events.h"
25 #include "i_context.h"
26 #include "i_dsoftbus_adapter.h"
27 #include "net_packet.h"
28 
29 namespace OHOS {
30 namespace Msdp {
31 namespace DeviceStatus {
32 namespace Cooperate {
33 class Context;
34 
35 class InputEventBuilder final {
36     class DSoftbusObserver final : public IDSoftbusObserver {
37     public:
DSoftbusObserver(InputEventBuilder & parent)38         DSoftbusObserver(InputEventBuilder &parent) : parent_(parent) {}
39         ~DSoftbusObserver() = default;
40 
OnBind(const std::string & networkId)41         void OnBind(const std::string &networkId) override {}
OnShutdown(const std::string & networkId)42         void OnShutdown(const std::string &networkId) override {}
OnConnected(const std::string & networkId)43         void OnConnected(const std::string &networkId) override {}
44 
OnPacket(const std::string & networkId,Msdp::NetPacket & packet)45         bool OnPacket(const std::string &networkId, Msdp::NetPacket &packet) override
46         {
47             return parent_.OnPacket(networkId, packet);
48         }
49 
OnRawData(const std::string & networkId,const void * data,uint32_t dataLen)50         bool OnRawData(const std::string &networkId, const void *data, uint32_t dataLen) override
51         {
52             return false;
53         }
54 
55     private:
56         InputEventBuilder &parent_;
57     };
58 
59     struct CursorPosition {
60         Rosen::DisplayId displayId { Rosen::DISPLAY_ID_INVALID };
61         Coordinate pos {};
62     };
63 
64 public:
65     InputEventBuilder(IContext *env);
66     ~InputEventBuilder();
67     DISALLOW_COPY_AND_MOVE(InputEventBuilder);
68 
69     void Enable(Context &context);
70     void Disable();
71     void Update(Context &context);
72     void Freeze();
73     void Thaw();
74 
75     static bool IsLocalEvent(const InputPointerEvent &event);
76 
77 private:
78     bool OnPacket(const std::string &networkId, Msdp::NetPacket &packet);
79     void OnPointerEvent(Msdp::NetPacket &packet);
80     void OnKeyEvent(Msdp::NetPacket &packet);
81     bool UpdatePointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
82     bool IsActive(std::shared_ptr<MMI::PointerEvent> pointerEvent);
83     void ResetPressedEvents();
84 
85     IContext *env_ { nullptr };
86     bool enable_ { false };
87     bool freezing_ { false };
88     int32_t xDir_ { 0 };
89     int32_t movement_ { 0 };
90     size_t nDropped_ { 0 };
91     std::string remoteNetworkId_;
92     std::shared_ptr<DSoftbusObserver> observer_;
93     std::shared_ptr<MMI::PointerEvent> pointerEvent_;
94     std::shared_ptr<MMI::KeyEvent> keyEvent_;
95     void TagRemoteEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
96 };
97 
IsLocalEvent(const InputPointerEvent & event)98 inline bool InputEventBuilder::IsLocalEvent(const InputPointerEvent &event)
99 {
100     return (event.deviceId >= 0);
101 }
102 } // namespace Cooperate
103 } // namespace DeviceStatus
104 } // namespace Msdp
105 } // namespace OHOS
106 #endif // INPUT_EVENT_BUILDER_H
107