1 /*
2 * Copyright (C) 2022 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 #include "accessibility_gesture_inject_path_parcel.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityGestureInjectPathParcel(const AccessibilityGestureInjectPath & gesturePath)22 AccessibilityGestureInjectPathParcel::AccessibilityGestureInjectPathParcel(
23 const AccessibilityGestureInjectPath &gesturePath)
24 {
25 HILOG_DEBUG();
26 AccessibilityGestureInjectPath *self = this;
27 *self = gesturePath;
28 }
29
ReadFromParcel(Parcel & parcel)30 bool AccessibilityGestureInjectPathParcel::ReadFromParcel(Parcel &parcel)
31 {
32 HILOG_DEBUG();
33
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
35 int32_t positionSize = 0;
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, positionSize);
37 for (auto i = 0; i < positionSize; i++) {
38 AccessibilityGesturePosition position;
39 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionX_);
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionY_);
41 AddPosition(position);
42 }
43 return true;
44 }
45
Marshalling(Parcel & parcel) const46 bool AccessibilityGestureInjectPathParcel::Marshalling(Parcel &parcel) const
47 {
48 HILOG_DEBUG();
49
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
51 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, positions_.size());
52 for (auto &position : positions_) {
53 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionX_);
54 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionY_);
55 }
56
57 return true;
58 }
59
Unmarshalling(Parcel & parcel)60 sptr<AccessibilityGestureInjectPathParcel> AccessibilityGestureInjectPathParcel::Unmarshalling(Parcel &parcel)
61 {
62 HILOG_DEBUG();
63 sptr<AccessibilityGestureInjectPathParcel> path = new(std::nothrow) AccessibilityGestureInjectPathParcel();
64 if (!path) {
65 HILOG_ERROR("Failed to create path.");
66 return nullptr;
67 }
68 if (!path->ReadFromParcel(parcel)) {
69 HILOG_ERROR("ReadFromParcel AccessibilityGestureInjectPathParcel failed.");
70 path = nullptr;
71 return nullptr;
72 }
73 return path;
74 }
75 } // namespace Accessibility
76 } // namespace OHOS
77