From 69ed42a302dfd1723b1f53b4f1c95b798eb49a38 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Wed, 13 Apr 2022 14:17:15 +0800 Subject: [PATCH 1/3] modify postTask Signed-off-by: changzheng6 --- tools/zip/BUILD.gn | 2 +- tools/zip/include/zip_utils.h | 3 --- tools/zip/src/zip.cpp | 32 ++++++++++++++++++-------------- tools/zip/src/zip_utils.cpp | 19 ------------------- tools/zip/test/BUILD.gn | 2 +- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/tools/zip/BUILD.gn b/tools/zip/BUILD.gn index b9d7a33754..424907df09 100644 --- a/tools/zip/BUILD.gn +++ b/tools/zip/BUILD.gn @@ -56,8 +56,8 @@ ohos_shared_library("zlib") { ] external_deps = [ - "ability_base:task_dispatcher", "bundle_framework:appexecfwk_base", + "eventhandler:libeventhandler", "hilog_native:libhilog_base", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", diff --git a/tools/zip/include/zip_utils.h b/tools/zip/include/zip_utils.h index df38f1f8cf..62f1fae440 100644 --- a/tools/zip/include/zip_utils.h +++ b/tools/zip/include/zip_utils.h @@ -21,13 +21,11 @@ #include #include #include -#include "runnable.h" namespace OHOS { namespace AAFwk { namespace LIBZIP { -using Runnable = OHOS::AppExecFwk::Runnable; using CALLBACK = std::function; #if !defined(DISALLOW_ASSIGN) @@ -131,7 +129,6 @@ constexpr PlatformFile kInvalidPlatformFile = -1; struct tm *GetCurrentSystemTime(void); bool StartsWith(const std::string &str, const std::string &searchFor); bool EndsWith(const std::string &str, const std::string &searchFor); -void PostTask(const std::shared_ptr &runnable); bool FilePathCheckValid(const std::string &str); } // namespace LIBZIP } // namespace AAFwk diff --git a/tools/zip/src/zip.cpp b/tools/zip/src/zip.cpp index 8ac9b006f4..fa8859cdfb 100644 --- a/tools/zip/src/zip.cpp +++ b/tools/zip/src/zip.cpp @@ -23,8 +23,8 @@ #include "app_log_wrapper.h" #include "directory_ex.h" +#include "event_handler.h" #include "file_path.h" -#include "runnable.h" #include "zip_internal.h" #include "zip_reader.h" #include "zip_writer.h" @@ -287,16 +287,18 @@ bool Unzip(const FilePath &srcFile, const FilePath &destDir, const OPTIONS &opti srcFileDir.Value().c_str(), destDirTemp.Value().c_str()); - std::shared_ptr innerTask = std::make_shared([srcFile, destDir, options, callback]() { + auto innerTask = [srcFile, destDir, options, callback]() { UnzipParam unzipParam { .callback = callback, .filterCB = ExcludeNoFilesFilter, .logSkippedFiles = true }; UnzipWithFilterCallback(srcFile, destDir, options, unzipParam); - }); + }; - PostTask(innerTask); + auto runner = EventRunner::Create(true); + std::shared_ptr handler = std::make_shared(runner); + handler->PostTask(innerTask); return true; } @@ -332,16 +334,18 @@ bool Zip(const FilePath &srcDir, const FilePath &destFile, const OPTIONS &option FilePath srcdir = srcDir; - std::shared_ptr innerTask = - std::make_shared([srcDir, destFile, includeHiddenFiles, callback]() { - OPTIONS options; - if (includeHiddenFiles) { - ZipWithFilterCallback(srcDir, destFile, options, callback, ExcludeNoFilesFilter); - } else { - ZipWithFilterCallback(srcDir, destFile, options, callback, ExcludeHiddenFilesFilter); - } - }); - PostTask(innerTask); + auto innerTask = [srcDir, destFile, includeHiddenFiles, callback]() { + OPTIONS options; + if (includeHiddenFiles) { + ZipWithFilterCallback(srcDir, destFile, options, callback, ExcludeNoFilesFilter); + } else { + ZipWithFilterCallback(srcDir, destFile, options, callback, ExcludeHiddenFilesFilter); + } + }; + + auto runner = EventRunner::Create(true); + std::shared_ptr handler = std::make_shared(runner); + handler->PostTask(innerTask); return true; } diff --git a/tools/zip/src/zip_utils.cpp b/tools/zip/src/zip_utils.cpp index 2032f40e08..e2e7e1d3d9 100644 --- a/tools/zip/src/zip_utils.cpp +++ b/tools/zip/src/zip_utils.cpp @@ -16,10 +16,6 @@ #include -#include "parallel_task_dispatcher.h" -#include "runnable.h" -#include "task_dispatcher_context.h" - namespace OHOS { namespace AAFwk { namespace LIBZIP { @@ -27,21 +23,6 @@ namespace { const std::string SEPARATOR = "/"; const std::regex FILE_PATH_REGEX("([0-9A-Za-z/+_=\\-,.])+"); } // namespace -using namespace OHOS::AppExecFwk; - -std::shared_ptr g_TaskDispatcher = nullptr; -void PostTask(const std::shared_ptr &runnable) -{ - static TaskDispatcherContext taskContext; - - if (g_TaskDispatcher == nullptr) { - g_TaskDispatcher = taskContext.CreateParallelDispatcher(std::string("toolszip"), TaskPriority::DEFAULT); - } - - if (g_TaskDispatcher != nullptr) { - g_TaskDispatcher->AsyncDispatch(runnable); - } -} struct tm *GetCurrentSystemTime(void) { diff --git a/tools/zip/test/BUILD.gn b/tools/zip/test/BUILD.gn index 0451d4907d..b96553d6cd 100644 --- a/tools/zip/test/BUILD.gn +++ b/tools/zip/test/BUILD.gn @@ -51,8 +51,8 @@ ohos_unittest("zip_test") { ] external_deps = [ - "ability_base:task_dispatcher", "bundle_framework:appexecfwk_base", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "utils_base:utils", -- Gitee From e7d4d0390ffa93e4622af3e2a551f10222a555ca Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Wed, 13 Apr 2022 14:21:59 +0800 Subject: [PATCH 2/3] modify postTask Signed-off-by: changzheng6 --- tools/zip/src/zip.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/zip/src/zip.cpp b/tools/zip/src/zip.cpp index fa8859cdfb..984a523c1f 100644 --- a/tools/zip/src/zip.cpp +++ b/tools/zip/src/zip.cpp @@ -296,8 +296,7 @@ bool Unzip(const FilePath &srcFile, const FilePath &destDir, const OPTIONS &opti UnzipWithFilterCallback(srcFile, destDir, options, unzipParam); }; - auto runner = EventRunner::Create(true); - std::shared_ptr handler = std::make_shared(runner); + std::shared_ptr handler = std::make_shared(EventRunner::Create(true)); handler->PostTask(innerTask); return true; } @@ -343,8 +342,7 @@ bool Zip(const FilePath &srcDir, const FilePath &destFile, const OPTIONS &option } }; - auto runner = EventRunner::Create(true); - std::shared_ptr handler = std::make_shared(runner); + std::shared_ptr handler = std::make_shared(EventRunner::Create(true)); handler->PostTask(innerTask); return true; -- Gitee From 07d53b9652cb4a327a561b8c5177a1ba82c379f6 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Wed, 13 Apr 2022 19:43:26 +0800 Subject: [PATCH 3/3] modify postTask Signed-off-by: changzheng6 --- tools/zip/include/zip_utils.h | 3 +++ tools/zip/src/zip.cpp | 7 ++----- tools/zip/src/zip_utils.cpp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/zip/include/zip_utils.h b/tools/zip/include/zip_utils.h index 62f1fae440..3ef7c358be 100644 --- a/tools/zip/include/zip_utils.h +++ b/tools/zip/include/zip_utils.h @@ -22,6 +22,8 @@ #include #include +#include "event_handler.h" + namespace OHOS { namespace AAFwk { namespace LIBZIP { @@ -129,6 +131,7 @@ constexpr PlatformFile kInvalidPlatformFile = -1; struct tm *GetCurrentSystemTime(void); bool StartsWith(const std::string &str, const std::string &searchFor); bool EndsWith(const std::string &str, const std::string &searchFor); +void PostTask(const OHOS::AppExecFwk::InnerEvent::Callback &callback); bool FilePathCheckValid(const std::string &str); } // namespace LIBZIP } // namespace AAFwk diff --git a/tools/zip/src/zip.cpp b/tools/zip/src/zip.cpp index 984a523c1f..690818e5fa 100644 --- a/tools/zip/src/zip.cpp +++ b/tools/zip/src/zip.cpp @@ -296,8 +296,7 @@ bool Unzip(const FilePath &srcFile, const FilePath &destDir, const OPTIONS &opti UnzipWithFilterCallback(srcFile, destDir, options, unzipParam); }; - std::shared_ptr handler = std::make_shared(EventRunner::Create(true)); - handler->PostTask(innerTask); + PostTask(innerTask); return true; } @@ -342,9 +341,7 @@ bool Zip(const FilePath &srcDir, const FilePath &destFile, const OPTIONS &option } }; - std::shared_ptr handler = std::make_shared(EventRunner::Create(true)); - handler->PostTask(innerTask); - + PostTask(innerTask); return true; } } // namespace LIBZIP diff --git a/tools/zip/src/zip_utils.cpp b/tools/zip/src/zip_utils.cpp index e2e7e1d3d9..0f9b3dc78f 100644 --- a/tools/zip/src/zip_utils.cpp +++ b/tools/zip/src/zip_utils.cpp @@ -16,6 +16,8 @@ #include +#include "event_handler.h" + namespace OHOS { namespace AAFwk { namespace LIBZIP { @@ -23,6 +25,20 @@ namespace { const std::string SEPARATOR = "/"; const std::regex FILE_PATH_REGEX("([0-9A-Za-z/+_=\\-,.])+"); } // namespace +using namespace OHOS::AppExecFwk; + +std::shared_ptr g_handler = nullptr; +void PostTask(const InnerEvent::Callback &callback) +{ + if (g_handler == nullptr) { + auto runner = EventRunner::Create(true); + g_handler = std::make_shared(runner); + } + + if (g_handler != nullptr) { + g_handler->PostTask(callback); + } +} struct tm *GetCurrentSystemTime(void) { -- Gitee