1 /*
2 * Copyright (c) 2025 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 "sane_option_descriptor.h"
17 #include "scan_log.h"
18 #include "message_parcel.h"
19
20 namespace OHOS::Scan {
SaneOptionDescriptor()21 SaneOptionDescriptor::SaneOptionDescriptor() : optionType_(0), optionUnit_(0), optionSize_(0),
22 optionCap_(0), optionConstraintType_(0), minValue_(0), maxValue_(0), quantValue_(0) {}
Marshalling(Parcel & parcel) const23 bool SaneOptionDescriptor::Marshalling(Parcel &parcel) const
24 {
25 bool status = true;
26 status &= parcel.WriteString(optionName_);
27 status &= parcel.WriteString(optionTitle_);
28 status &= parcel.WriteString(optionDesc_);
29 status &= parcel.WriteInt32(optionType_);
30 status &= parcel.WriteInt32(optionUnit_);
31 status &= parcel.WriteInt32(optionSize_);
32 status &= parcel.WriteInt32(optionCap_);
33 status &= parcel.WriteInt32(optionConstraintType_);
34 status &= parcel.WriteStringVector(optionConstraintString_);
35 status &= parcel.WriteInt32Vector(optionConstraintNumber_);
36 status &= parcel.WriteInt32(minValue_);
37 status &= parcel.WriteInt32(maxValue_);
38 status &= parcel.WriteInt32(quantValue_);
39 return status;
40 }
41
Unmarshalling(Parcel & parcel)42 SaneOptionDescriptor* SaneOptionDescriptor::Unmarshalling(Parcel &parcel)
43 {
44 SaneOptionDescriptor* obj = new (std::nothrow) SaneOptionDescriptor();
45 if (obj == nullptr) {
46 SCAN_HILOGE("obj is a nullptr.");
47 return nullptr;
48 }
49 obj->optionName_ = parcel.ReadString();
50 obj->optionTitle_ = parcel.ReadString();
51 obj->optionDesc_ = parcel.ReadString();
52 obj->optionType_ = parcel.ReadInt32();
53 obj->optionUnit_ = parcel.ReadInt32();
54 obj->optionSize_ = parcel.ReadInt32();
55 obj->optionCap_ = parcel.ReadInt32();
56 obj->optionConstraintType_ = parcel.ReadInt32();
57 parcel.ReadStringVector(&(obj->optionConstraintString_));
58 parcel.ReadInt32Vector(&(obj->optionConstraintNumber_));
59 obj->minValue_ = parcel.ReadInt32();
60 obj->maxValue_ = parcel.ReadInt32();
61 obj->quantValue_ = parcel.ReadInt32();
62 return obj;
63 }
64
Dump()65 void SaneOptionDescriptor::Dump()
66 {
67 SCAN_HILOGD("optionName_ = %{public}s", optionName_.c_str());
68 SCAN_HILOGD("optionTitle_ = %{public}s", optionTitle_.c_str());
69 SCAN_HILOGD("optionDesc_ = %{public}s", optionDesc_.c_str());
70 SCAN_HILOGD("optionType_ = %{public}d", optionType_);
71 SCAN_HILOGD("optionUnit_ = %{public}d", optionUnit_);
72 SCAN_HILOGD("optionSize_ = %{public}d", optionSize_);
73 SCAN_HILOGD("optionCap_ = %{public}d", optionCap_);
74 SCAN_HILOGD("optionConstraintType_ = %{public}d", optionConstraintType_);
75 for (const auto& str : optionConstraintString_) {
76 SCAN_HILOGD("optionConstraintString_ = %{public}s", str.c_str());
77 }
78 for (const auto& number : optionConstraintNumber_) {
79 SCAN_HILOGD("optionConstraintNumber_ = %{public}d", number);
80 }
81 SCAN_HILOGD("minValue_ = %{public}d", minValue_);
82 SCAN_HILOGD("maxValue_ = %{public}d", maxValue_);
83 SCAN_HILOGD("quantValue_ = %{public}d", quantValue_);
84 }
85 } // namespace OHOS::Scan