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