From c1a5fff98cab4adf04210ba8120459b8e87a8fa3 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 15 Oct 2023 16:17:28 +0800 Subject: fix: solve some issues on linux .desktop file --- src/core/thread/FileReadTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 73954d28..1cbc1a53 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -43,7 +43,7 @@ FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { } void FileReadTask::Run() { - SetFinishAfterRun(false); + HoldOnLifeCycle(true); if (is_regular_file(read_file_path_)) { SPDLOG_DEBUG("read open file: {}", read_file_path_.u8string()); -- cgit v1.2.3 From 95997d27106daf91336847f50efaaa32279b7fc7 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 16 Oct 2023 17:54:05 +0800 Subject: fix: check and update copyright at files --- src/core/thread/FileReadTask.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 1cbc1a53..e0ef2f16 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Saturneric + * Copyright (C) 2021 Saturneric * * This file is part of GpgFrontend. * @@ -19,8 +19,10 @@ * The initial version of the source code is inherited from * the gpg4usb project, which is under GPL-3.0-or-later. * - * The source code version of this software was modified and released - * by Saturneric starting on May 12, 2021. + * All the source code of GpgFrontend was modified and released by + * Saturneric starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later * */ -- cgit v1.2.3 From 70196cf01757824a578e4d9c49a210bf136de266 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 18 Oct 2023 22:45:33 +0800 Subject: feat: using pool for concurrent executions, not stable yet --- src/core/thread/FileReadTask.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index e0ef2f16..52ec9db9 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -31,6 +31,7 @@ namespace GpgFrontend::UI { FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { + HoldOnLifeCycle(true); connect(this, &FileReadTask::SignalFileBytesReadNext, this, &FileReadTask::read_bytes); @@ -45,8 +46,6 @@ FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { } void FileReadTask::Run() { - HoldOnLifeCycle(true); - if (is_regular_file(read_file_path_)) { SPDLOG_DEBUG("read open file: {}", read_file_path_.u8string()); @@ -76,7 +75,7 @@ void FileReadTask::read_bytes() { SPDLOG_DEBUG("read bytes end"); emit SignalFileBytesReadEnd(); // announce finish task - emit SignalTaskRunnableEnd(0); + emit SignalTaskShouldEnd(0); } } -- cgit v1.2.3 From 3c40fa27823e70215261d3845275360f85e59623 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 5 Jan 2024 16:11:24 +0800 Subject: fix: slove some known issues --- src/core/thread/FileReadTask.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 52ec9db9..906ea188 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -30,6 +30,8 @@ namespace GpgFrontend::UI { +constexpr size_t kBufferSize = 8192; + FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { HoldOnLifeCycle(true); connect(this, &FileReadTask::SignalFileBytesReadNext, this, @@ -68,11 +70,11 @@ void FileReadTask::Run() { void FileReadTask::read_bytes() { QByteArray read_buffer; if (!target_file_.atEnd() && - (read_buffer = target_file_.read(buffer_size_)).size() > 0) { - SPDLOG_DEBUG("read bytes: {}", read_buffer.size()); + (read_buffer = target_file_.read(kBufferSize)).size() > 0) { + SPDLOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); } else { - SPDLOG_DEBUG("read bytes end"); + SPDLOG_DEBUG("io read bytes end"); emit SignalFileBytesReadEnd(); // announce finish task emit SignalTaskShouldEnd(0); -- cgit v1.2.3 From 644aa4397b03dbef73f8bfedc13925b51cad836b Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 5 Jan 2024 20:55:15 +0800 Subject: feat: integrate logging api to core --- src/core/thread/FileReadTask.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 906ea188..98dbf718 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -49,18 +49,18 @@ FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { void FileReadTask::Run() { if (is_regular_file(read_file_path_)) { - SPDLOG_DEBUG("read open file: {}", read_file_path_.u8string()); + GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_.u8string()); target_file_.setFileName( QString::fromStdString(read_file_path_.u8string())); target_file_.open(QIODevice::ReadOnly); if (!(target_file_.isOpen() && target_file_.isReadable())) { - SPDLOG_ERROR("file not open or not readable"); + GF_CORE_LOG_ERROR("file not open or not readable"); if (target_file_.isOpen()) target_file_.close(); return; } - SPDLOG_DEBUG("started reading: {}", read_file_path_.u8string()); + GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_.u8string()); read_bytes(); } else { emit SignalFileBytesReadEnd(); @@ -71,10 +71,10 @@ void FileReadTask::read_bytes() { QByteArray read_buffer; if (!target_file_.atEnd() && (read_buffer = target_file_.read(kBufferSize)).size() > 0) { - SPDLOG_DEBUG("io thread read bytes: {}", read_buffer.size()); + GF_CORE_LOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); } else { - SPDLOG_DEBUG("io read bytes end"); + GF_CORE_LOG_DEBUG("io read bytes end"); emit SignalFileBytesReadEnd(); // announce finish task emit SignalTaskShouldEnd(0); @@ -82,7 +82,7 @@ void FileReadTask::read_bytes() { } FileReadTask::~FileReadTask() { - SPDLOG_DEBUG("close file: {}", read_file_path_.u8string()); + GF_CORE_LOG_DEBUG("close file: {}", read_file_path_.u8string()); if (target_file_.isOpen()) target_file_.close(); } -- cgit v1.2.3 From bf538056b24a68b8fd235b1c50991ee8eb46a776 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 12 Jan 2024 14:02:37 +0800 Subject: refactor: use QString instead of std::string and improve threading system --- src/core/thread/FileReadTask.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 98dbf718..38a0ab37 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -32,27 +32,18 @@ namespace GpgFrontend::UI { constexpr size_t kBufferSize = 8192; -FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { +FileReadTask::FileReadTask(QString path) : Task("file_read_task") { HoldOnLifeCycle(true); connect(this, &FileReadTask::SignalFileBytesReadNext, this, &FileReadTask::read_bytes); - -#ifdef WINDOWS - std::filesystem::path read_file_path( - QString::fromStdString(path).toStdU16String()); -#else - std::filesystem::path read_file_path( - QString::fromStdString(path).toStdString()); -#endif - read_file_path_ = read_file_path; + read_file_path_ = path; } void FileReadTask::Run() { - if (is_regular_file(read_file_path_)) { - GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_.u8string()); + if (QFileInfo(read_file_path_).isFile()) { + GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_); - target_file_.setFileName( - QString::fromStdString(read_file_path_.u8string())); + target_file_.setFileName(read_file_path_); target_file_.open(QIODevice::ReadOnly); if (!(target_file_.isOpen() && target_file_.isReadable())) { @@ -60,7 +51,7 @@ void FileReadTask::Run() { if (target_file_.isOpen()) target_file_.close(); return; } - GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_.u8string()); + GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_); read_bytes(); } else { emit SignalFileBytesReadEnd(); @@ -82,7 +73,7 @@ void FileReadTask::read_bytes() { } FileReadTask::~FileReadTask() { - GF_CORE_LOG_DEBUG("close file: {}", read_file_path_.u8string()); + GF_CORE_LOG_DEBUG("close file: {}", read_file_path_); if (target_file_.isOpen()) target_file_.close(); } -- cgit v1.2.3 From 4994f4eaa1211d402b791660ad6221154a4c2405 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 16 Jan 2024 11:49:50 +0800 Subject: fix: make task and threading system safer --- src/core/thread/FileReadTask.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 38a0ab37..c757d4c0 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -32,14 +32,14 @@ namespace GpgFrontend::UI { constexpr size_t kBufferSize = 8192; -FileReadTask::FileReadTask(QString path) : Task("file_read_task") { +FileReadTask::FileReadTask(QString path) + : Task("file_read_task"), read_file_path_(std::move(path)) { HoldOnLifeCycle(true); connect(this, &FileReadTask::SignalFileBytesReadNext, this, - &FileReadTask::read_bytes); - read_file_path_ = path; + &FileReadTask::slot_read_bytes); } -void FileReadTask::Run() { +auto FileReadTask::Run() -> int { if (QFileInfo(read_file_path_).isFile()) { GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_); @@ -49,23 +49,24 @@ void FileReadTask::Run() { if (!(target_file_.isOpen() && target_file_.isReadable())) { GF_CORE_LOG_ERROR("file not open or not readable"); if (target_file_.isOpen()) target_file_.close(); - return; + return -1; } GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_); - read_bytes(); + slot_read_bytes(); } else { emit SignalFileBytesReadEnd(); } + return 0; } -void FileReadTask::read_bytes() { +void FileReadTask::slot_read_bytes() { QByteArray read_buffer; if (!target_file_.atEnd() && (read_buffer = target_file_.read(kBufferSize)).size() > 0) { GF_CORE_LOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); } else { - GF_CORE_LOG_DEBUG("io read bytes end"); + GF_CORE_LOG_DEBUG("io thread read bytes end"); emit SignalFileBytesReadEnd(); // announce finish task emit SignalTaskShouldEnd(0); -- cgit v1.2.3 From 37848811b6c8ca6c2a707431ec077c8098918afe Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 18 Jan 2024 00:14:13 +0800 Subject: fix: improve code quality, docs and ci files --- src/core/thread/FileReadTask.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/thread/FileReadTask.cpp') diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index c757d4c0..49a3f540 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -61,7 +61,8 @@ auto FileReadTask::Run() -> int { void FileReadTask::slot_read_bytes() { QByteArray read_buffer; - if (!target_file_.atEnd() && + if (QByteArray read_buffer; + !target_file_.atEnd() && (read_buffer = target_file_.read(kBufferSize)).size() > 0) { GF_CORE_LOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); -- cgit v1.2.3