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 "print_preview_attribute.h" 17 #include "message_parcel.h" 18 #include "print_constant.h" 19 #include "print_log.h" 20 21 namespace OHOS::Print { PrintPreviewAttribute()22PrintPreviewAttribute::PrintPreviewAttribute() : hasResult_(false), result_(PRINT_INVALID_ID) { 23 } 24 PrintPreviewAttribute(const PrintPreviewAttribute & right)25PrintPreviewAttribute::PrintPreviewAttribute(const PrintPreviewAttribute &right) 26 { 27 hasResult_ = right.hasResult_; 28 result_ = right.result_; 29 previewRange_ = right.previewRange_; 30 } 31 operator =(const PrintPreviewAttribute & right)32PrintPreviewAttribute &PrintPreviewAttribute::operator=(const PrintPreviewAttribute &right) 33 { 34 if (this != &right) { 35 hasResult_ = right.hasResult_; 36 result_ = right.result_; 37 previewRange_ = right.previewRange_; 38 } 39 return *this; 40 } 41 ~PrintPreviewAttribute()42PrintPreviewAttribute::~PrintPreviewAttribute() 43 { 44 } 45 Reset()46void PrintPreviewAttribute::Reset() 47 { 48 hasResult_ = false; 49 result_ = PRINT_INVALID_ID; 50 previewRange_.Reset(); 51 } 52 SetResult(uint32_t result)53void PrintPreviewAttribute::SetResult(uint32_t result) 54 { 55 hasResult_ = true; 56 result_ = result; 57 } 58 SetPreviewRange(const PrintRange & previewRange)59void PrintPreviewAttribute::SetPreviewRange(const PrintRange &previewRange) 60 { 61 previewRange_ = previewRange; 62 } 63 HasResult() const64bool PrintPreviewAttribute::HasResult() const 65 { 66 return hasResult_; 67 } 68 GetResult() const69uint32_t PrintPreviewAttribute::GetResult() const 70 { 71 return result_; 72 } 73 GetPreviewRange(PrintRange & previewRange) const74void PrintPreviewAttribute::GetPreviewRange(PrintRange &previewRange) const 75 { 76 previewRange = previewRange_; 77 } 78 ReadFromParcel(Parcel & parcel)79void PrintPreviewAttribute::ReadFromParcel(Parcel &parcel) 80 { 81 hasResult_ = parcel.ReadBool(); 82 auto msgParcel = static_cast<MessageParcel*>(&parcel); 83 if (hasResult_ && msgParcel != nullptr) { 84 SetResult(msgParcel->ReadFileDescriptor()); 85 } 86 auto rangePtr = PrintRange::Unmarshalling(parcel); 87 if (rangePtr != nullptr) { 88 SetPreviewRange(*rangePtr); 89 } 90 } 91 Marshalling(Parcel & parcel) const92bool PrintPreviewAttribute::Marshalling(Parcel &parcel) const 93 { 94 bool result = false; 95 auto msgParcel = static_cast<MessageParcel*>(&parcel); 96 if (msgParcel != nullptr) { 97 msgParcel->WriteBool(hasResult_); 98 if (hasResult_) { 99 msgParcel->WriteFileDescriptor(GetResult()); 100 } 101 result = previewRange_.Marshalling(parcel); 102 } 103 return result; 104 } 105 Unmarshalling(Parcel & parcel)106std::shared_ptr<PrintPreviewAttribute> PrintPreviewAttribute::Unmarshalling(Parcel &parcel) 107 { 108 auto nativeObj = std::make_shared<PrintPreviewAttribute>(); 109 if (nativeObj != nullptr) { 110 nativeObj->ReadFromParcel(parcel); 111 } 112 return nativeObj; 113 } 114 Dump()115void PrintPreviewAttribute::Dump() 116 { 117 if (hasResult_) { 118 PRINT_HILOGD("result_: %{public}d", result_); 119 } 120 previewRange_.Dump(); 121 } 122 } // namespace OHOS::Print 123