• 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 #include <vector>
16 
17 #include "devicestatus_common.h"
18 #include "devicestatus_define.h"
19 #include "devicestatus_errors.h"
20 #include "preview_style_packer.h"
21 
22 namespace OHOS {
23 namespace Msdp {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "PreviewStylePacker" };
26 } // namespace
27 
28 namespace DeviceStatus {
29 
Marshalling(const PreviewStyle & previewStyle,Parcel & data)30 int32_t PreviewStylePacker::Marshalling(const PreviewStyle &previewStyle, Parcel &data)
31 {
32     std::vector<int32_t> types;
33     for (const auto &elem : previewStyle.types) {
34         types.push_back(static_cast<int32_t>(elem));
35     }
36     WRITEINT32VECTOR(data, types, ERR_INVALID_VALUE);
37     WRITEUINT32(data, previewStyle.foregroundColor, ERR_INVALID_VALUE);
38     WRITEINT32(data, previewStyle.opacity, ERR_INVALID_VALUE);
39     WRITEFLOAT(data, previewStyle.radius, ERR_INVALID_VALUE);
40     WRITEFLOAT(data, previewStyle.scale, ERR_INVALID_VALUE);
41     return RET_OK;
42 }
43 
UnMarshalling(Parcel & data,PreviewStyle & previewStyle)44 int32_t PreviewStylePacker::UnMarshalling(Parcel &data, PreviewStyle &previewStyle)
45 {
46     std::vector<int32_t> types;
47     READINT32VECTOR(data, types, ERR_INVALID_VALUE);
48     for (const auto &elem : types) {
49         previewStyle.types.push_back(static_cast<PreviewType>(elem));
50     }
51     READUINT32(data, previewStyle.foregroundColor, ERR_INVALID_VALUE);
52     READINT32(data, previewStyle.opacity, ERR_INVALID_VALUE);
53     READFLOAT(data, previewStyle.radius, ERR_INVALID_VALUE);
54     READFLOAT(data, previewStyle.scale, ERR_INVALID_VALUE);
55     return RET_OK;
56 }
57 
Marshalling(const PreviewAnimation & previewAnimation,Parcel & data)58 int32_t PreviewAnimationPacker::Marshalling(const PreviewAnimation &previewAnimation, Parcel &data)
59 {
60     WRITEINT32(data, previewAnimation.duration, ERR_INVALID_VALUE);
61     WRITESTRING(data, previewAnimation.curveName, ERR_INVALID_VALUE);
62     WRITEFLOATVECTOR(data, previewAnimation.curve, ERR_INVALID_VALUE);
63     return RET_OK;
64 }
65 
UnMarshalling(Parcel & data,PreviewAnimation & previewAnimation)66 int32_t PreviewAnimationPacker::UnMarshalling(Parcel &data, PreviewAnimation &previewAnimation)
67 {
68     READINT32(data, previewAnimation.duration, ERR_INVALID_VALUE);
69     if (previewAnimation.duration <= 0) {
70         FI_HILOGE("Invalid paramater duration:%{public}d", previewAnimation.duration);
71         return ERR_INVALID_VALUE;
72     }
73     if (previewAnimation.duration > MAX_ANIMATION_DURATION_MS) {
74         FI_HILOGW("Duration:%{public}d too long, use default value", previewAnimation.duration);
75         previewAnimation.duration = MAX_ANIMATION_DURATION_MS;
76     }
77     READSTRING(data, previewAnimation.curveName, ERR_INVALID_VALUE);
78     READFLOATVECTOR(data, previewAnimation.curve, ERR_INVALID_VALUE);
79     return RET_OK;
80 }
81 
82 } // namespace DeviceStatus
83 } // namespace Msdp
84 } // namespace OHOS