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 HeartBeatMarshalling(NetPacket &pkt); 38 static int32_t Marshalling(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt, 39 int64_t interceptorTime); 40 static int32_t Unmarshalling(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event, 41 int64_t &interceptorTime); 42 #ifdef OHOS_BUILD_ENABLE_SECURITY_PART 43 static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 44 static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 45 static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::KeyEvent> event, NetPacket &pkt); 46 static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> event); 47 #endif // OHOS_BUILD_ENABLE_SECURITY_PART 48 private: 49 static int32_t SerializeInputEvent(std::shared_ptr<MMI::InputEvent> event, NetPacket &pkt); 50 static int32_t DeserializeInputEvent(NetPacket &pkt, std::shared_ptr<MMI::InputEvent> event); 51 static int32_t SerializeBaseInfo(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 52 static int32_t DeserializeBaseInfo(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 53 static int32_t SerializeAxes(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 54 static int32_t DeserializeAxes(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 55 static int32_t SerializePressedButtons(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 56 static int32_t DeserializePressedButtons(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 57 static int32_t SerializePointerItem(NetPacket &pkt, MMI::PointerEvent::PointerItem &item); 58 static int32_t DeserializePointerItem(NetPacket &pkt, MMI::PointerEvent::PointerItem &item); 59 static int32_t SerializePointers(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 60 static int32_t DeserializePointers(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 61 static int32_t SerializePressedKeys(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 62 static int32_t DeserializePressedKeys(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 63 static int32_t SerializeBuffer(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt); 64 static int32_t DeserializeBuffer(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event); 65 static int32_t SerializeInterceptorTime(int64_t interceptorTime, NetPacket &pkt); 66 static int32_t DeserializeInterceptorTime(NetPacket &pkt, int64_t &interceptorTime); 67 static void ReadFunctionKeys(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> key); 68 69 #ifdef OHOS_BUILD_ENABLE_SECURITY_PART 70 static constexpr uint32_t MAX_HMAC_SIZE = 64; 71 struct SecCompPointEvent { 72 double touchX; 73 double touchY; 74 uint64_t timeStamp; 75 }; 76 #endif // OHOS_BUILD_ENABLE_SECURITY_PART 77 }; 78 } // namespace Cooperate 79 } // namespace DeviceStatus 80 } // namespace Msdp 81 } // namespace OHOS 82 #endif // INPUT_EVENT_SERIALIZATION_H 83