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 #ifndef DUMP_TASK_INFO_H 17 #define DUMP_TASK_INFO_H 18 19 #include <vector> 20 #include <string> 21 #include <iosfwd> 22 #include "i_dumper.h" 23 24 namespace OHOS::Request::Download { 25 class DownloadInfo; 26 class DumpTaskInfo : public IDumper { 27 public: 28 DumpTaskInfo() = default; ~DumpTaskInfo()29 ~DumpTaskInfo() override {}; 30 31 bool Dump(int fd, const std::vector<std::string> &args) override; 32 private: 33 void DumpAllTaskTile(int fd) const; 34 bool DumpAllTask(int fd) const; 35 void DumpTaskDetailInfoTile(int fd) const; 36 bool DumpTaskDetailInfo(int fd, uint32_t taskId) const; 37 void FormatSummaryTitle(std::ostringstream &buffer) const; 38 void FormatDetailTitle(std::ostringstream &buffer) const; 39 void FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const; 40 void FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const; 41 private: 42 std::string DumpTaskID(const DownloadInfo &taskInfo) const; 43 std::string DumpTaskType(const DownloadInfo &taskInfo) const; 44 std::string DumpTaskStatus(const DownloadInfo &taskInfo) const; 45 std::string DumpFileName(const DownloadInfo &taskInfo) const; 46 std::string DumpRoaming(const DownloadInfo &taskInfo) const; 47 std::string DumpNetworkType(const DownloadInfo &taskInfo) const; 48 std::string DumpMetered(const DownloadInfo &taskInfo) const; 49 std::string DumpFileSize(const DownloadInfo &taskInfo) const; 50 std::string DumpTransferredSize(const DownloadInfo &taskInfo) const; 51 private: 52 const int32_t columnWidthInt = 12; 53 const int32_t columnWidthShort = 8; 54 const int32_t columnWidthFileName = 256; 55 56 using ColumnDumpFunc = std::string (DumpTaskInfo::*)(const DownloadInfo &taskInfo) const; 57 std::vector<std::pair<int32_t, std::string>> summaryColumnTitle_ = { 58 {columnWidthInt, "id"}, 59 {columnWidthInt, "type"}, 60 {columnWidthInt, "status"}, 61 }; 62 63 std::vector<std::pair<int32_t, ColumnDumpFunc>> dumpSummaryCfg_ = { 64 {columnWidthInt, &DumpTaskInfo::DumpTaskID}, 65 {columnWidthInt, &DumpTaskInfo::DumpTaskType}, 66 {columnWidthInt, &DumpTaskInfo::DumpTaskStatus}, 67 }; 68 69 std::vector<std::pair<int32_t, std::string>> detailColumnTitle_ = { 70 {columnWidthShort, "roaming"}, 71 {columnWidthShort, "network"}, 72 {columnWidthShort, "meter"}, 73 {columnWidthInt, "file_size"}, 74 {columnWidthInt, "tran_size "}, 75 {columnWidthFileName, "file_name"}, 76 }; 77 78 std::vector<std::pair<int32_t, ColumnDumpFunc>> dumpDetailCfg_ = { 79 {columnWidthShort, &DumpTaskInfo::DumpRoaming}, 80 {columnWidthShort, &DumpTaskInfo::DumpNetworkType}, 81 {columnWidthShort, &DumpTaskInfo::DumpMetered}, 82 {columnWidthInt, &DumpTaskInfo::DumpFileSize}, 83 {columnWidthInt, &DumpTaskInfo::DumpTransferredSize}, 84 {columnWidthFileName, &DumpTaskInfo::DumpFileName}, 85 }; 86 }; 87 } 88 #endif // DUMP_TASK_INFO_H 89