• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_SERIALIZATION_H
17 #define INPUT_EVENT_SERIALIZATION_H
18 
19 #include "key_event.h"
20 #include "net_packet.h"
21 #include "pointer_event.h"
22 #include "switch_event.h"
23 
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 namespace Cooperate {
28 class InputEventSerialization {
29     InputEventSerialization() = delete;
30     DISALLOW_COPY_AND_MOVE(InputEventSerialization);
31 
32 public:
33     static int32_t KeyEventToNetPacket(const std::shared_ptr<MMI::KeyEvent> key, NetPacket &pkt);
34     static int32_t NetPacketToKeyEvent(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> key);
35     static int32_t SwitchEventToNetPacket(const std::shared_ptr<MMI::SwitchEvent> key, NetPacket &pkt);
36     static int32_t NetPacketToSwitchEvent(NetPacket &pkt, std::shared_ptr<MMI::SwitchEvent> key);
37     static int32_t Marshalling(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
38     static int32_t Unmarshalling(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
39 #ifdef OHOS_BUILD_ENABLE_SECURITY_PART
40     static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
41     static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
42     static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::KeyEvent> event, NetPacket &pkt);
43     static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> event);
44 #endif // OHOS_BUILD_ENABLE_SECURITY_PART
45 private:
46     static int32_t SerializeInputEvent(std::shared_ptr<MMI::InputEvent> event, NetPacket &pkt);
47     static int32_t DeserializeInputEvent(NetPacket &pkt, std::shared_ptr<MMI::InputEvent> event);
48     static int32_t SerializeBaseInfo(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
49     static int32_t DeserializeBaseInfo(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
50     static int32_t SerializeAxes(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
51     static int32_t DeserializeAxes(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
52     static int32_t SerializePressedButtons(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
53     static int32_t DeserializePressedButtons(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
54     static int32_t SerializePointerItem(NetPacket &pkt, MMI::PointerEvent::PointerItem &item);
55     static int32_t DeserializePointerItem(NetPacket &pkt, MMI::PointerEvent::PointerItem &item);
56     static int32_t SerializePointers(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
57     static int32_t DeserializePointers(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
58     static int32_t SerializePressedKeys(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
59     static int32_t DeserializePressedKeys(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
60     static int32_t SerializeBuffer(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
61     static int32_t DeserializeBuffer(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
62     static void ReadFunctionKeys(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> key);
63 
64 #ifdef OHOS_BUILD_ENABLE_SECURITY_PART
65     static constexpr uint32_t MAX_HMAC_SIZE = 160;
66     struct SecCompPointEvent {
67         double touchX;
68         double touchY;
69         uint64_t timeStamp;
70     };
71 #endif // OHOS_BUILD_ENABLE_SECURITY_PART
72 };
73 } // namespace Cooperate
74 } // namespace DeviceStatus
75 } // namespace Msdp
76 } // namespace OHOS
77 #endif // INPUT_EVENT_SERIALIZATION_H
78