• 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 #include "drag_params.h"
17 
18 #include "devicestatus_define.h"
19 #include "drag_data_packer.h"
20 #include "preview_style_packer.h"
21 
22 namespace OHOS {
23 namespace Msdp {
24 namespace DeviceStatus {
25 
StartDragParam(DragData & dragData)26 StartDragParam::StartDragParam(DragData &dragData)
27 {
28     dragDataPtr_ = &dragData;
29 }
30 
StartDragParam(const DragData & dragData)31 StartDragParam::StartDragParam(const DragData &dragData)
32 {
33     cDragDataPtr_ = &dragData;
34 }
35 
Marshalling(MessageParcel & parcel) const36 bool StartDragParam::Marshalling(MessageParcel &parcel) const
37 {
38     return (
39         (cDragDataPtr_ != nullptr) &&
40         (DragDataPacker::Marshalling(*cDragDataPtr_, parcel) == RET_OK)
41     );
42 }
43 
Unmarshalling(MessageParcel & parcel)44 bool StartDragParam::Unmarshalling(MessageParcel &parcel)
45 {
46     return (
47         (dragDataPtr_ != nullptr) &&
48         (DragDataPacker::UnMarshalling(parcel, *dragDataPtr_) == RET_OK)
49     );
50 }
51 
StopDragParam(const DragDropResult & dropResult)52 StopDragParam::StopDragParam(const DragDropResult &dropResult)
53     : dropResult_(dropResult)
54 {}
55 
Marshalling(MessageParcel & parcel) const56 bool StopDragParam::Marshalling(MessageParcel &parcel) const
57 {
58     return (
59         parcel.WriteInt32(static_cast<int32_t>(dropResult_.result)) &&
60         parcel.WriteInt32(dropResult_.windowId) &&
61         parcel.WriteBool(dropResult_.hasCustomAnimation)
62     );
63 }
64 
Unmarshalling(MessageParcel & parcel)65 bool StopDragParam::Unmarshalling(MessageParcel &parcel)
66 {
67     int32_t result { -1 };
68     if (!parcel.ReadInt32(result) ||
69         (result < static_cast<int32_t>(DragResult::DRAG_SUCCESS)) ||
70         (result > static_cast<int32_t>(DragResult::DRAG_EXCEPTION))) {
71         return false;
72     }
73     dropResult_.result = static_cast<DragResult>(result);
74     return (
75         parcel.ReadInt32(dropResult_.windowId) &&
76         parcel.ReadBool(dropResult_.hasCustomAnimation)
77     );
78 }
79 
SetDragWindowVisibleParam(bool visible)80 SetDragWindowVisibleParam::SetDragWindowVisibleParam(bool visible)
81     : visible_(visible)
82 {}
83 
Marshalling(MessageParcel & parcel) const84 bool SetDragWindowVisibleParam::Marshalling(MessageParcel &parcel) const
85 {
86     return parcel.WriteBool(visible_);
87 }
88 
Unmarshalling(MessageParcel & parcel)89 bool SetDragWindowVisibleParam::Unmarshalling(MessageParcel &parcel)
90 {
91     return parcel.ReadBool(visible_);
92 }
93 
UpdateDragStyleParam(DragCursorStyle style)94 UpdateDragStyleParam::UpdateDragStyleParam(DragCursorStyle style)
95     : cursorStyle_(style)
96 {}
97 
Marshalling(MessageParcel & parcel) const98 bool UpdateDragStyleParam::Marshalling(MessageParcel &parcel) const
99 {
100     return parcel.WriteInt32(static_cast<int32_t>(cursorStyle_));
101 }
102 
Unmarshalling(MessageParcel & parcel)103 bool UpdateDragStyleParam::Unmarshalling(MessageParcel &parcel)
104 {
105     int32_t style { -1 };
106     if (!parcel.ReadInt32(style) ||
107         (style < static_cast<int32_t>(DragCursorStyle::DEFAULT)) ||
108         (style > static_cast<int32_t>(DragCursorStyle::MOVE))) {
109         return false;
110     }
111     cursorStyle_ = static_cast<DragCursorStyle>(style);
112     return true;
113 }
114 
UpdateShadowPicParam(const ShadowInfo & shadowInfo)115 UpdateShadowPicParam::UpdateShadowPicParam(const ShadowInfo &shadowInfo)
116     : shadowInfo_(shadowInfo)
117 {}
118 
Marshalling(MessageParcel & parcel) const119 bool UpdateShadowPicParam::Marshalling(MessageParcel &parcel) const
120 {
121     return (
122         (shadowInfo_.pixelMap != nullptr) &&
123         shadowInfo_.pixelMap->Marshalling(parcel) &&
124         parcel.WriteInt32(shadowInfo_.x) &&
125         parcel.WriteInt32(shadowInfo_.y)
126     );
127 }
128 
Unmarshalling(MessageParcel & parcel)129 bool UpdateShadowPicParam::Unmarshalling(MessageParcel &parcel)
130 {
131     shadowInfo_.pixelMap = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
132     return (
133         (shadowInfo_.pixelMap != nullptr) &&
134         parcel.ReadInt32(shadowInfo_.x) &&
135         parcel.ReadInt32(shadowInfo_.y)
136     );
137 }
138 
GetDragTargetPidReply(int32_t pid)139 GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid)
140     : targetPid_(pid)
141 {}
142 
Marshalling(MessageParcel & parcel) const143 bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const
144 {
145     return parcel.WriteInt32(targetPid_);
146 }
147 
Unmarshalling(MessageParcel & parcel)148 bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel)
149 {
150     return parcel.ReadInt32(targetPid_);
151 }
152 
GetUdKeyReply(std::string && udKey)153 GetUdKeyReply::GetUdKeyReply(std::string &&udKey)
154     : udKey_(std::move(udKey))
155 {}
156 
Marshalling(MessageParcel & parcel) const157 bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const
158 {
159     return parcel.WriteString(udKey_);
160 }
161 
Unmarshalling(MessageParcel & parcel)162 bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel)
163 {
164     return parcel.ReadString(udKey_);
165 }
166 
GetShadowOffsetReply(int32_t offsetX,int32_t offsetY,int32_t width,int32_t height)167 GetShadowOffsetReply::GetShadowOffsetReply(int32_t offsetX, int32_t offsetY, int32_t width, int32_t height)
168     : offsetX_(offsetX), offsetY_(offsetY), width_(width), height_(height)
169 {}
170 
Marshalling(MessageParcel & parcel) const171 bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const
172 {
173     return (
174         parcel.WriteInt32(offsetX_) &&
175         parcel.WriteInt32(offsetY_) &&
176         parcel.WriteInt32(width_) &&
177         parcel.WriteInt32(height_)
178     );
179 }
180 
Unmarshalling(MessageParcel & parcel)181 bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel)
182 {
183     return (
184         parcel.ReadInt32(offsetX_) &&
185         parcel.ReadInt32(offsetY_) &&
186         parcel.ReadInt32(width_) &&
187         parcel.ReadInt32(height_)
188     );
189 }
190 
UpdatePreviewStyleParam(const PreviewStyle & previewStyle)191 UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle)
192     : previewStyle_(previewStyle)
193 {}
194 
Marshalling(MessageParcel & parcel) const195 bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const
196 {
197     return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK);
198 }
199 
Unmarshalling(MessageParcel & parcel)200 bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel)
201 {
202     return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK);
203 }
204 
UpdatePreviewAnimationParam(const PreviewStyle & previewStyle,const PreviewAnimation & animation)205 UpdatePreviewAnimationParam::UpdatePreviewAnimationParam(
206     const PreviewStyle &previewStyle, const PreviewAnimation &animation)
207     : previewStyle_(previewStyle), previewAnimation_(animation)
208 {}
209 
Marshalling(MessageParcel & parcel) const210 bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const
211 {
212     return (
213         (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) &&
214         (PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK)
215     );
216 }
217 
Unmarshalling(MessageParcel & parcel)218 bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel)
219 {
220     return (
221         (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) &&
222         (PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK)
223     );
224 }
225 
GetDragSummaryReply(std::map<std::string,int64_t> && summaries)226 GetDragSummaryReply::GetDragSummaryReply(std::map<std::string, int64_t> &&summaries)
227     : summaries_(std::move(summaries))
228 {}
229 
Marshalling(MessageParcel & parcel) const230 bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const
231 {
232     return (SummaryPacker::Marshalling(summaries_, parcel) == RET_OK);
233 }
234 
Unmarshalling(MessageParcel & parcel)235 bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
236 {
237     return (SummaryPacker::UnMarshalling(parcel, summaries_) == RET_OK);
238 }
239 
GetDragStateReply(DragState dragState)240 GetDragStateReply::GetDragStateReply(DragState dragState)
241     : dragState_(dragState)
242 {}
243 
Marshalling(MessageParcel & parcel) const244 bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
245 {
246     return parcel.WriteInt32(static_cast<int32_t>(dragState_));
247 }
248 
Unmarshalling(MessageParcel & parcel)249 bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
250 {
251     int32_t dragState { -1 };
252     if (!parcel.ReadInt32(dragState) ||
253         (dragState < static_cast<int32_t>(DragState::ERROR)) ||
254         (dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
255         return false;
256     }
257     dragState_ = static_cast<DragState>(dragState);
258     return true;
259 }
260 
EnterTextEditorAreaParam(bool enable)261 EnterTextEditorAreaParam::EnterTextEditorAreaParam(bool enable)
262     : enable_(enable)
263 {}
264 
Marshalling(MessageParcel & parcel) const265 bool EnterTextEditorAreaParam::Marshalling(MessageParcel &parcel) const
266 {
267     return parcel.WriteBool(enable_);
268 }
269 
Unmarshalling(MessageParcel & parcel)270 bool EnterTextEditorAreaParam::Unmarshalling(MessageParcel &parcel)
271 {
272     return parcel.ReadBool(enable_);
273 }
274 
GetDragActionReply(DragAction dragAction)275 GetDragActionReply::GetDragActionReply(DragAction dragAction)
276     : dragAction_(dragAction)
277 {}
278 
Marshalling(MessageParcel & parcel) const279 bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
280 {
281     return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
282 }
283 
Unmarshalling(MessageParcel & parcel)284 bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
285 {
286     int32_t dragAction { -1 };
287     if (!parcel.ReadInt32(dragAction) ||
288         (dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
289         (dragAction > static_cast<int32_t>(DragAction::COPY))) {
290         return false;
291     }
292     dragAction_ = static_cast<DragAction>(dragAction);
293     return true;
294 }
295 
GetExtraInfoReply(std::string && extraInfo)296 GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
297     : extraInfo_(std::move(extraInfo))
298 {}
299 
Marshalling(MessageParcel & parcel) const300 bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
301 {
302     return parcel.WriteString(extraInfo_);
303 }
304 
Unmarshalling(MessageParcel & parcel)305 bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
306 {
307     return parcel.ReadString(extraInfo_);
308 }
309 } // namespace DeviceStatus
310 } // namespace Msdp
311 } // namespace OHOS