• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NONE), 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