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