• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 <cinttypes>
17 
18 #include "download_info.h"
19 #include "log.h"
20 #include "constant.h"
21 
22 namespace OHOS::Request::Download {
DownloadInfo()23 DownloadInfo::DownloadInfo()
24     : description_(""), downloadedBytes_(0), downloadId_(0), failedReason_(ERROR_UNKNOWN), fileName_(""),
25       filePath_(""), pausedReason_(PAUSED_UNKNOWN), status_(SESSION_UNKNOWN), targetURI_(""), downloadTitle_(""),
26       taskType_("download"), downloadTotalBytes_(0) {
27 }
28 
SetDescription(const std::string & description)29 void DownloadInfo::SetDescription(const std::string &description)
30 {
31     description_ = description;
32 }
33 
SetDownloadedBytes(int64_t downloadedBytes)34 void DownloadInfo::SetDownloadedBytes(int64_t downloadedBytes)
35 {
36     downloadedBytes_ = downloadedBytes;
37 }
38 
SetDownloadId(uint32_t downloadId)39 void DownloadInfo::SetDownloadId(uint32_t downloadId)
40 {
41     downloadId_ = downloadId;
42 }
43 
SetFailedReason(ErrorCode failedReason)44 void DownloadInfo::SetFailedReason(ErrorCode failedReason)
45 {
46     failedReason_ = failedReason;
47 }
48 
SetFileName(const std::string & fileName)49 void DownloadInfo::SetFileName(const std::string &fileName)
50 {
51     fileName_ = fileName;
52 }
53 
SetFilePath(const std::string & filePath)54 void DownloadInfo::SetFilePath(const std::string &filePath)
55 {
56     filePath_ = filePath;
57 }
58 
SetPausedReason(PausedReason pausedReason)59 void DownloadInfo::SetPausedReason(PausedReason pausedReason)
60 {
61     pausedReason_ = pausedReason;
62 }
63 
SetStatus(DownloadStatus status)64 void DownloadInfo::SetStatus(DownloadStatus status)
65 {
66     status_ = status;
67 }
68 
SetTargetURI(const std::string & targetURI)69 void DownloadInfo::SetTargetURI(const std::string &targetURI)
70 {
71     targetURI_ = targetURI;
72 }
73 
SetDownloadTitle(const std::string & downloadTitle)74 void DownloadInfo::SetDownloadTitle(const std::string &downloadTitle)
75 {
76     downloadTitle_ = downloadTitle;
77 }
78 
SetDownloadTotalBytes(int64_t downloadTotalBytes)79 void DownloadInfo::SetDownloadTotalBytes(int64_t downloadTotalBytes)
80 {
81     downloadTotalBytes_ = downloadTotalBytes;
82 }
83 
SetNetworkType(uint32_t networkType)84 void DownloadInfo::SetNetworkType(uint32_t networkType)
85 {
86     networkType_ = networkType;
87 }
88 
SetMetered(bool enableMetered)89 void DownloadInfo::SetMetered(bool enableMetered)
90 {
91     enableMetered_ = enableMetered;
92 }
93 
SetRoaming(bool enableRoaming)94 void DownloadInfo::SetRoaming(bool enableRoaming)
95 {
96     enableRoaming_ = enableRoaming;
97 }
98 
GetDescription() const99 const std::string &DownloadInfo::GetDescription() const
100 {
101     return description_;
102 }
103 
GetDownloadedBytes() const104 int64_t DownloadInfo::GetDownloadedBytes() const
105 {
106     return downloadedBytes_;
107 }
108 
GetDownloadId() const109 uint32_t DownloadInfo::GetDownloadId() const
110 {
111     return downloadId_;
112 }
113 
GetFailedReason() const114 ErrorCode DownloadInfo::GetFailedReason() const
115 {
116     return failedReason_;
117 }
118 
GetFileName() const119 const std::string &DownloadInfo::GetFileName() const
120 {
121     return fileName_;
122 }
123 
GetFilePath() const124 const std::string &DownloadInfo::GetFilePath() const
125 {
126     return filePath_;
127 }
128 
GetPausedReason() const129 PausedReason DownloadInfo::GetPausedReason() const
130 {
131     return pausedReason_;
132 }
133 
GetStatus() const134 DownloadStatus DownloadInfo::GetStatus() const
135 {
136     return status_;
137 }
138 
GetTargetURI() const139 const std::string &DownloadInfo::GetTargetURI() const
140 {
141     return targetURI_;
142 }
143 
GetDownloadTitle() const144 const std::string &DownloadInfo::GetDownloadTitle() const
145 {
146     return downloadTitle_;
147 }
148 
GetTaskType() const149 std::string DownloadInfo::GetTaskType() const
150 {
151     return taskType_;
152 }
153 
GetDownloadTotalBytes() const154 int64_t DownloadInfo::GetDownloadTotalBytes() const
155 {
156     return downloadTotalBytes_;
157 }
158 
GetNetworkType() const159 uint32_t DownloadInfo::GetNetworkType() const
160 {
161     return networkType_;
162 }
163 
GetMetered() const164 bool DownloadInfo::GetMetered() const
165 {
166     return enableMetered_;
167 }
168 
GetRoaming() const169 bool DownloadInfo::GetRoaming() const
170 {
171     return enableRoaming_;
172 }
173 
Dump()174 void DownloadInfo::Dump()
175 {
176     DOWNLOAD_HILOGD("description: %{public}s", description_.c_str());
177     DOWNLOAD_HILOGD("downloadedBytes: %{public}" PRId64, downloadedBytes_);
178     DOWNLOAD_HILOGD("downloadId: %{public}d", downloadId_);
179     DOWNLOAD_HILOGD("failedReason: %{public}d", failedReason_);
180     DOWNLOAD_HILOGD("fileName: %{public}s", fileName_.c_str());
181     DOWNLOAD_HILOGD("filePath: %{public}s", filePath_.c_str());
182     DOWNLOAD_HILOGD("pausedReason: %{public}d", pausedReason_);
183     DOWNLOAD_HILOGD("status: %{public}d", status_);
184     DOWNLOAD_HILOGD("targetURI: %{public}s", targetURI_.c_str());
185     DOWNLOAD_HILOGD("downloadTitle: %{public}s", downloadTitle_.c_str());
186     DOWNLOAD_HILOGD("downloadTotalBytes: %{public}" PRId64, downloadTotalBytes_);
187 }
188 } // namespace OHOS::Request::Download