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)
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 }
35 
operator =(const ScanProgress &right)36 ScanProgress &ScanProgress::operator=(const ScanProgress &right)
37 {
38     if (this != &right) {
39         progress = right.progress;
40         fd = right.fd;
41         isFinal = right.isFinal;
42         pictureId = right.pictureId;
43         timePoint = right.timePoint;
44         taskCode = right.taskCode;
45     }
46     return *this;
47 }
48 
~ScanProgress()49 ScanProgress::~ScanProgress()
50 {}
51 
SetScanProgress(const int32_t progress)52 void ScanProgress::SetScanProgress(const int32_t progress)
53 {
54     this->progress = progress;
55 }
56 
SetScanPictureFd(const int32_t fd)57 void ScanProgress::SetScanPictureFd(const int32_t fd)
58 {
59     this->fd = fd;
60 }
61 
SetIsFinal(const bool isFinal)62 void ScanProgress::SetIsFinal(const bool isFinal)
63 {
64     this->isFinal = isFinal;
65 }
66 
SetPictureId(const int32_t pictureId)67 void ScanProgress::SetPictureId(const int32_t pictureId)
68 {
69     this->pictureId = pictureId;
70 }
71 
SetScanTime(SteadyTimePoint nowTime)72 void ScanProgress::SetScanTime(SteadyTimePoint nowTime)
73 {
74     this->timePoint = nowTime;
75 }
76 
SetTaskCode(ScanErrorCode taskCode)77 void ScanProgress::SetTaskCode(ScanErrorCode taskCode)
78 {
79     this->taskCode = taskCode;
80 }
81 
GetScanProgress() const82 int32_t ScanProgress::GetScanProgress() const
83 {
84     return progress;
85 }
86 
GetScanPictureFd() const87 int32_t ScanProgress::GetScanPictureFd() const
88 {
89     return fd;
90 }
91 
GetIsFinal() const92 bool ScanProgress::GetIsFinal() const
93 {
94     return isFinal;
95 }
96 
GetPictureId() const97 int32_t ScanProgress::GetPictureId() const
98 {
99     return pictureId;
100 }
101 
GetScanTime() const102 SteadyTimePoint ScanProgress::GetScanTime() const
103 {
104     return timePoint;
105 }
106 
GetTaskCode() const107 ScanErrorCode ScanProgress::GetTaskCode() const
108 {
109     return taskCode;
110 }
111 
ReadFromParcel(Parcel &parcel)112 void ScanProgress::ReadFromParcel(Parcel &parcel)
113 {
114     auto mesgParcel = static_cast<MessageParcel*>(&parcel);
115     SetScanProgress(parcel.ReadInt32());
116     SetScanPictureFd(mesgParcel->ReadFileDescriptor());
117     SetIsFinal(parcel.ReadBool());
118 }
119 
Marshalling(Parcel &parcel) const120 bool ScanProgress::Marshalling(Parcel &parcel) const
121 {
122     auto mesgParcel = static_cast<MessageParcel*>(&parcel);
123     parcel.WriteInt32(progress);
124     mesgParcel->WriteFileDescriptor(fd);
125     parcel.WriteBool(isFinal);
126     return true;
127 }
128 
Unmarshalling(Parcel &parcel)129 std::shared_ptr<ScanProgress> ScanProgress::Unmarshalling(Parcel &parcel)
130 {
131     auto nativeObj = std::make_shared<ScanProgress>();
132     nativeObj->ReadFromParcel(parcel);
133     return nativeObj;
134 }
135 
Dump() const136 void ScanProgress::Dump() const
137 {
138     SCAN_HILOGI("ScanProgress Dump");
139     SCAN_HILOGI("ScanProgress: progress = %{public}d", progress);
140     SCAN_HILOGI("ScanProgress: fd = %{public}d", fd);
141     SCAN_HILOGI("ScanProgress: isFinal = %{public}d", isFinal);
142     SCAN_HILOGI("ScanProgress: pictureId = %{public}d", pictureId);
143     SCAN_HILOGI("ScanProgress: taskCode = %{public}d", taskCode);
144 }
145 
146 } // namespace OHOS::Scan
147