mirror of
https://github.com/openharmony/miscservices_request.git
synced 2026-07-01 04:46:07 -04:00
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -44,7 +43,7 @@ DumpServiceImpl &DumpServiceImpl::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
DumperType DumpServiceImpl::GetDumperType(const std::string &cmd)
|
||||
DumperType DumpServiceImpl::GetDumperType(const std::string &cmd) const
|
||||
{
|
||||
if (cmd == "-h") {
|
||||
return HELP_DUMPER;
|
||||
@@ -68,7 +67,7 @@ int DumpServiceImpl::Dump(int fd, const std::vector<std::string> &args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
DumperFactoryMap::iterator it = dumperFactoryMap_.find(dumperType);
|
||||
DumperFactoryMap::const_iterator it = dumperFactoryMap_.find(dumperType);
|
||||
if (it == dumperFactoryMap_.end()) {
|
||||
dprintf(fd, "invalid arg\n");
|
||||
return 0;
|
||||
@@ -82,7 +81,7 @@ int DumpServiceImpl::Dump(int fd, const std::vector<std::string> &args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DumpServiceImpl::DumpHelp(int fd)
|
||||
void DumpServiceImpl::DumpHelp(int fd) const
|
||||
{
|
||||
constexpr const char *DEFAULT_HELPER =
|
||||
"usage:\n"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -39,8 +39,8 @@ private:
|
||||
DumpServiceImpl &operator=(DumpServiceImpl &&) = delete;
|
||||
|
||||
void InitDumperFactoryMap();
|
||||
void DumpHelp(int fd);
|
||||
DumperType GetDumperType(const std::string &cmd);
|
||||
void DumpHelp(int fd) const;
|
||||
DumperType GetDumperType(const std::string &cmd) const;
|
||||
private:
|
||||
using DumperFactoryMap = std::map<DumperType, std::shared_ptr<DumperFactory>>;
|
||||
DumperFactoryMap dumperFactoryMap_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace OHOS::Request::Download {
|
||||
bool DumpTaskInfo::Dump(int fd, const std::vector<std::string> &args)
|
||||
{
|
||||
int32_t argsNum = args.size();
|
||||
uint32_t argsNum = args.size();
|
||||
if (argsNum > 1) {
|
||||
dprintf(fd, "too many args, -t accept no arg or one arg \n");
|
||||
return false;
|
||||
@@ -35,7 +35,7 @@ bool DumpTaskInfo::Dump(int fd, const std::vector<std::string> &args)
|
||||
return true;
|
||||
}
|
||||
|
||||
void DumpTaskInfo::DumpAllTaskTile(int fd)
|
||||
void DumpTaskInfo::DumpAllTaskTile(int fd) const
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
buffer << std::left;
|
||||
@@ -43,21 +43,21 @@ void DumpTaskInfo::DumpAllTaskTile(int fd)
|
||||
dprintf(fd, "%s\n", buffer.str().c_str());
|
||||
}
|
||||
|
||||
void DumpTaskInfo::FormatSummaryTitle(std::ostringstream &buffer)
|
||||
void DumpTaskInfo::FormatSummaryTitle(std::ostringstream &buffer) const
|
||||
{
|
||||
for (const auto &it: summaryColumnTitle_) {
|
||||
buffer << std::setw(it.first) << it.second;
|
||||
}
|
||||
}
|
||||
|
||||
void DumpTaskInfo::FormatDetailTitle(std::ostringstream &buffer)
|
||||
void DumpTaskInfo::FormatDetailTitle(std::ostringstream &buffer) const
|
||||
{
|
||||
for (const auto &it: detailColumnTitle_) {
|
||||
buffer << std::setw(it.first) << it.second;
|
||||
}
|
||||
}
|
||||
|
||||
void DumpTaskInfo::DumpTaskDetailInfoTile(int fd)
|
||||
void DumpTaskInfo::DumpTaskDetailInfoTile(int fd) const
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
buffer << std::left;
|
||||
@@ -66,7 +66,7 @@ void DumpTaskInfo::DumpTaskDetailInfoTile(int fd)
|
||||
dprintf(fd, "%s\n", buffer.str().c_str());
|
||||
}
|
||||
|
||||
void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer)
|
||||
void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const
|
||||
{
|
||||
for (const auto &it: dumpSummaryCfg_) {
|
||||
auto columnFormatFun = it.second;
|
||||
@@ -74,7 +74,7 @@ void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostri
|
||||
}
|
||||
}
|
||||
|
||||
void DumpTaskInfo::FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer)
|
||||
void DumpTaskInfo::FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const
|
||||
{
|
||||
for (const auto &it: dumpDetailCfg_) {
|
||||
auto columnFormatFun = it.second;
|
||||
@@ -127,7 +127,7 @@ std::string DumpTaskInfo::DumpTaskID(const DownloadInfo &taskInfo) const
|
||||
|
||||
std::string DumpTaskInfo::DumpTaskType(const DownloadInfo &taskInfo) const
|
||||
{
|
||||
return "download";
|
||||
return taskInfo.GetTaskType();
|
||||
}
|
||||
|
||||
std::string DumpTaskInfo::DumpTaskStatus(const DownloadInfo &taskInfo) const
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -31,14 +31,14 @@ public:
|
||||
|
||||
bool Dump(int fd, const std::vector<std::string> &args) override;
|
||||
private:
|
||||
void DumpAllTaskTile(int fd);
|
||||
void DumpAllTaskTile(int fd) const;
|
||||
bool DumpAllTask(int fd);
|
||||
void DumpTaskDetailInfoTile(int fd);
|
||||
void DumpTaskDetailInfoTile(int fd) const;
|
||||
bool DumpTaskDetailInfo(int fd, uint32_t taskId);
|
||||
void FormatSummaryTitle(std::ostringstream &buffer);
|
||||
void FormatDetailTitle(std::ostringstream &buffer);
|
||||
void FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer);
|
||||
void FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer);
|
||||
void FormatSummaryTitle(std::ostringstream &buffer) const;
|
||||
void FormatDetailTitle(std::ostringstream &buffer) const;
|
||||
void FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const;
|
||||
void FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const;
|
||||
private:
|
||||
std::string DumpTaskID(const DownloadInfo &taskInfo) const;
|
||||
std::string DumpTaskType(const DownloadInfo &taskInfo) const;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -28,24 +28,22 @@ TaskStatistics &TaskStatistics::GetInstance()
|
||||
|
||||
void TaskStatistics::ReportTasksSize(uint64_t totalSize)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
DayTasksSize_ += totalSize;
|
||||
dayTasksSize_ += totalSize;
|
||||
}
|
||||
|
||||
void TaskStatistics::ReportTasksNumber()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
DayTasksNumber_ ++;
|
||||
dayTasksNumber_ ++;
|
||||
}
|
||||
|
||||
uint64_t TaskStatistics::GetDayTasksSize() const
|
||||
{
|
||||
return DayTasksSize_;
|
||||
return dayTasksSize_;
|
||||
}
|
||||
|
||||
uint32_t TaskStatistics::GetDayTasksNumber() const
|
||||
{
|
||||
return DayTasksNumber_;
|
||||
return dayTasksNumber_;
|
||||
}
|
||||
|
||||
int32_t TaskStatistics::GetNextReportInterval() const
|
||||
@@ -70,8 +68,8 @@ void TaskStatistics::ReportStatistics() const
|
||||
OHOS::HiviewDFX::HiSysEvent::Write(OHOS::HiviewDFX::HiSysEvent::Domain::REQUEST,
|
||||
REQUEST_TASK_INFO_STATISTICS,
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
|
||||
TASKS_SIZE, DayTasksSize_,
|
||||
TASKS_NUMBER, DayTasksNumber_);
|
||||
TASKS_SIZE, &dayTasksSize_,
|
||||
TASKS_NUMBER, &dayTasksNumber_);
|
||||
}
|
||||
|
||||
void TaskStatistics::StartTimerThread()
|
||||
@@ -90,8 +88,8 @@ void TaskStatistics::StartTimerThread()
|
||||
DOWNLOAD_HILOGD("taskRun next interval: %{public}d", nextReportInterval);
|
||||
sleep(nextReportInterval);
|
||||
ReportStatistics();
|
||||
this->DayTasksNumber_ = 0;
|
||||
this->DayTasksSize_ = 0;
|
||||
this->dayTasksNumber_ = 0;
|
||||
this->dayTasksSize_ = 0;
|
||||
}
|
||||
};
|
||||
std::thread th = std::thread(fun);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -16,7 +16,6 @@
|
||||
#ifndef TASK_STATISTICS_H
|
||||
#define TASK_STATISTICS_H
|
||||
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
namespace OHOS::Request::Download {
|
||||
@@ -42,13 +41,12 @@ private:
|
||||
static constexpr const char *REQUEST_TASK_INFO_STATISTICS = "REQUEST_TASK_INFO_STATISTICS";
|
||||
static constexpr const char *TASKS_SIZE = "TASKS_SIZE";
|
||||
static constexpr const char *TASKS_NUMBER = "TASKS_NUMBER";
|
||||
static constexpr const int32_t ONE_DAY_SEC = 24 * 3600;
|
||||
static constexpr const int32_t ONE_HOUR_SEC = 3600;
|
||||
static constexpr const int32_t ONE_MINUTE_SEC = 60;
|
||||
static constexpr int32_t ONE_DAY_SEC = 24 * 3600;
|
||||
static constexpr int32_t ONE_HOUR_SEC = 3600;
|
||||
static constexpr int32_t ONE_MINUTE_SEC = 60;
|
||||
|
||||
std::mutex mutex_;
|
||||
int64_t DayTasksSize_ {0};
|
||||
int32_t DayTasksNumber_ {0};
|
||||
std::atomic<uint32_t> dayTasksNumber_ {0};
|
||||
std::atomic<uint64_t> dayTasksSize_ {0};
|
||||
bool running_ { false };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
[[nodiscard]] uint32_t GetNetworkType() const;
|
||||
[[nodiscard]] bool GetMetered() const;
|
||||
[[nodiscard]] bool GetRoaming() const;
|
||||
[[nodiscard]] std::string GetTaskType() const;
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
@@ -98,12 +99,14 @@ private:
|
||||
std::string targetURI_;
|
||||
|
||||
std::string downloadTitle_;
|
||||
|
||||
std::string taskType_;
|
||||
|
||||
uint32_t downloadTotalBytes_;
|
||||
|
||||
bool enableMetered_;
|
||||
bool enableRoaming_;
|
||||
uint32_t networkType_;
|
||||
bool enableMetered_ {false};
|
||||
bool enableRoaming_ {false};
|
||||
uint32_t networkType_ {0};
|
||||
};
|
||||
} // namespace OHOS::Request::Download
|
||||
#endif /* DOWNLOAD_INFO_H */
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OHOS::Request::Download {
|
||||
DownloadInfo::DownloadInfo()
|
||||
: description_(""), downloadedBytes_(0), downloadId_(0), failedReason_(ERROR_UNKNOWN), fileName_(""),
|
||||
filePath_(""), pausedReason_(PAUSED_UNKNOWN), status_(SESSION_UNKNOWN), targetURI_(""), downloadTitle_(""),
|
||||
downloadTotalBytes_(0) {
|
||||
taskType_("download"), downloadTotalBytes_(0) {
|
||||
}
|
||||
|
||||
void DownloadInfo::SetDescription(const std::string &description)
|
||||
@@ -144,6 +144,11 @@ const std::string &DownloadInfo::GetDownloadTitle() const
|
||||
return downloadTitle_;
|
||||
}
|
||||
|
||||
std::string DownloadInfo::GetTaskType() const
|
||||
{
|
||||
return taskType_;
|
||||
}
|
||||
|
||||
uint32_t DownloadInfo::GetDownloadTotalBytes() const
|
||||
{
|
||||
return downloadTotalBytes_;
|
||||
|
||||
+5
-5
@@ -46,13 +46,13 @@ REQUEST_SERVICE_START_FAULT:
|
||||
REQUEST_TASK_FAULT:
|
||||
__BASE: {type: FAULT, level: MINOR, desc: The request task fail }
|
||||
TASK_TYPE: {type: STRING, desc: Task type}
|
||||
TOTAL_FILE_NUM: {type: INT32, desc: Total number of documents }
|
||||
FAIL_FILE_NUM: {type: INT32, desc: Number of failed files }
|
||||
SUCCESS_FILE_NUM: {type: INT32, desc: Number of successful files }
|
||||
TOTAL_FILE_NUM: {type: UINT32, desc: Total number of documents }
|
||||
FAIL_FILE_NUM: {type: UINT32, desc: Number of failed files }
|
||||
SUCCESS_FILE_NUM: {type: UINT32, desc: Number of successful files }
|
||||
ERROR_INFO: {type: INT32, desc: Error code }
|
||||
|
||||
REQUEST_TASK_INFO_STATISTICS:
|
||||
__BASE: {type: STATISTIC, level: MINOR, desc: Statistics of download tasks }
|
||||
TASKS_SIZE: {type: INT64, desc: Download tasks size}
|
||||
TASKS_NUMBER: {type: INT32, desc: Download tasks number}
|
||||
TASKS_SIZE: {type: UINT64, desc: Download tasks size}
|
||||
TASKS_NUMBER: {type: UINT32, desc: Download tasks number}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ enum Type {
|
||||
};
|
||||
|
||||
struct TaskResult {
|
||||
int32_t successCount {0};
|
||||
int32_t failCount {0};
|
||||
uint32_t successCount {0};
|
||||
uint32_t failCount {0};
|
||||
int32_t errorCode {0};
|
||||
};
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ uint32_t ObtainFile::GetDataAbilityFile(FILE **file, std::string &fileUri,
|
||||
{
|
||||
uint32_t ret = UPLOAD_ERRORCODE_NO_ERROR;
|
||||
FILE *filePtr = nullptr;
|
||||
int32_t fileLength = 0;
|
||||
uint32_t fileLength = 0;
|
||||
|
||||
do {
|
||||
int32_t fd = fileAdapter_->DataAbilityOpenFile(fileUri, context);
|
||||
uint32_t fd = fileAdapter_->DataAbilityOpenFile(fileUri, context);
|
||||
if (fd == -1) {
|
||||
UPLOAD_HILOGE(UPLOAD_MODULE_FRAMEWORK, "ObtainFile::GetDataAbilityFile, open file error.");
|
||||
ret = UPLOAD_ERRORCODE_GET_FILE_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user