1 /*
2  * Copyright (c) 2024 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 "scan_progress.h"
17 #include "scan_log.h"
18 #include "message_parcel.h"
19 
20 namespace OHOS::Scan {
21 using SteadyTimePoint = std::chrono::steady_clock::time_point;
ScanProgress()22 ScanProgress::ScanProgress() : progress(0),
23     fd(0), isFinal(true), pictureId(0), taskCode(E_SCAN_GOOD), imageRealPath("")
24 {}
25 
ScanProgress(const ScanProgress & right)26 ScanProgress::ScanProgress(const ScanProgress &right)
27 {
28     progress = right.progress;
29     fd = right.fd;
30     isFinal = right.isFinal;
31     pictureId = right.pictureId;
32     timePoint = right.timePoint;
33     taskCode = right.taskCode;
34     imageRealPath = right.imageRealPath;
35 }
36 
operator =(const ScanProgress & right)37 ScanProgress &ScanProgress::operator=(const ScanProgress &right)
38 {
39     if (this != &right) {
40         progress = right.progress;
41         fd = right.fd;
42         isFinal = right.isFinal;
43         pictureId = right.pictureId;
44         timePoint = right.timePoint;
45         taskCode = right.taskCode;
46         imageRealPath = right.imageRealPath;
47     }
48     return *this;
49 }
50 
~ScanProgress()51 ScanProgress::~ScanProgress()
52 {}
53 
SetScanProgress(const int32_t progress)54 void ScanProgress::SetScanProgress(const int32_t progress)
55 {
56     this->progress = progress;
57 }
58 
SetScanPictureFd(const int32_t fd)59 void ScanProgress::SetScanPictureFd(const int32_t fd)
60 {
61     this->fd = fd;
62 }
63 
SetIsFinal(const bool isFinal)64 void ScanProgress::SetIsFinal(const bool isFinal)
65 {
66     this->isFinal = isFinal;
67 }
68 
SetPictureId(const int32_t pictureId)69 void ScanProgress::SetPictureId(const int32_t pictureId)
70 {
71     this->pictureId = pictureId;
72 }
73 
SetScanTime(SteadyTimePoint nowTime)74 void ScanProgress::SetScanTime(SteadyTimePoint nowTime)
75 {
76     this->timePoint = nowTime;
77 }
78 
SetTaskCode(ScanErrorCode taskCode)79 void ScanProgress::SetTaskCode(ScanErrorCode taskCode)
80 {
81     this->taskCode = taskCode;
82 }
83 
SetImageRealPath(const std::string & imageRealPath)84 void ScanProgress::SetImageRealPath(const std::string& imageRealPath)
85 {
86     this->imageRealPath = imageRealPath;
87 }
88 
89 
GetScanProgress() const90 int32_t ScanProgress::GetScanProgress() const
91 {
92     return progress;
93 }
94 
GetScanPictureFd() const95 int32_t ScanProgress::GetScanPictureFd() const
96 {
97     return fd;
98 }
99 
GetIsFinal() const100 bool ScanProgress::GetIsFinal() const
101 {
102     return isFinal;
103 }
104 
GetPictureId() const105 int32_t ScanProgress::GetPictureId() const
106 {
107     return pictureId;
108 }
109 
GetScanTime() const110 SteadyTimePoint ScanProgress::GetScanTime() const
111 {
112     return timePoint;
113 }
114 
GetTaskCode() const115 ScanErrorCode ScanProgress::GetTaskCode() const
116 {
117     return taskCode;
118 }
119 
GetImageRealPath() const120 std::string ScanProgress::GetImageRealPath() const
121 {
122     return imageRealPath;
123 }
124 
ReadFromParcel(Parcel & parcel)125 void ScanProgress::ReadFromParcel(Parcel &parcel)
126 {
127     auto mesgParcel = static_cast<MessageParcel*>(&parcel);
128     SetScanProgress(parcel.ReadInt32());
129     SetScanPictureFd(mesgParcel->ReadFileDescriptor());
130     SetIsFinal(parcel.ReadBool());
131 }
132 
Marshalling(Parcel & parcel) const133 bool ScanProgress::Marshalling(Parcel &parcel) const
134 {
135     auto mesgParcel = static_cast<MessageParcel*>(&parcel);
136     parcel.WriteInt32(progress);
137     mesgParcel->WriteFileDescriptor(fd);
138     parcel.WriteBool(isFinal);
139     return true;
140 }
141 
Unmarshalling(Parcel & parcel)142 std::shared_ptr<ScanProgress> ScanProgress::Unmarshalling(Parcel &parcel)
143 {
144     auto nativeObj = std::make_shared<ScanProgress>();
145     nativeObj->ReadFromParcel(parcel);
146     return nativeObj;
147 }
148 
Dump() const149 void ScanProgress::Dump() const
150 {
151     SCAN_HILOGD("ScanProgress Dump");
152     SCAN_HILOGD("ScanProgress: progress = %{public}d", progress);
153     SCAN_HILOGD("ScanProgress: fd = %{public}d", fd);
154     SCAN_HILOGD("ScanProgress: isFinal = %{public}d", isFinal);
155     SCAN_HILOGD("ScanProgress: pictureId = %{public}d", pictureId);
156     SCAN_HILOGD("ScanProgress: taskCode = %{public}d", taskCode);
157 }
158 
159 } // namespace OHOS::Scan
160