From 9e69ad91f5ab9867120c7f334df02d143500995a Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 4 Dec 2024 16:43:02 +0800 Subject: [PATCH] fix: wrong pipeline_override internal type --- source/MaaFramework/API/MaaContext.cpp | 24 ++++++++++++++++++++---- source/MaaFramework/API/MaaTasker.cpp | 6 +++++- source/MaaFramework/API/MaaTypes.h | 10 +++++----- source/MaaFramework/Task/Context.cpp | 15 +++++---------- source/MaaFramework/Task/Context.h | 8 ++++---- source/MaaFramework/Task/TaskBase.cpp | 2 +- source/MaaFramework/Task/TaskBase.h | 2 +- source/MaaFramework/Tasker/Tasker.cpp | 4 ++-- source/MaaFramework/Tasker/Tasker.h | 4 ++-- 9 files changed, 45 insertions(+), 30 deletions(-) diff --git a/source/MaaFramework/API/MaaContext.cpp b/source/MaaFramework/API/MaaContext.cpp index 0a052428f..309dc4c4b 100644 --- a/source/MaaFramework/API/MaaContext.cpp +++ b/source/MaaFramework/API/MaaContext.cpp @@ -19,8 +19,12 @@ MaaTaskId MaaContextRunPipeline(MaaContext* context, const char* entry, const ch LogError << "failed to parse" << VAR(pipeline_override); return MaaInvalidId; } + if (!ov_opt->is_object()) { + LogError << "json is not object" << VAR(pipeline_override); + return MaaInvalidId; + } - return context->run_pipeline(entry, *ov_opt); + return context->run_pipeline(entry, ov_opt->as_object()); } MaaRecoId MaaContextRunRecognition(MaaContext* context, const char* entry, const char* pipeline_override, const MaaImageBuffer* image) @@ -37,6 +41,10 @@ MaaRecoId MaaContextRunRecognition(MaaContext* context, const char* entry, const LogError << "failed to parse" << VAR(pipeline_override); return MaaInvalidId; } + if (!ov_opt->is_object()) { + LogError << "json is not object" << VAR(pipeline_override); + return MaaInvalidId; + } const auto& mat = image->get(); if (mat.empty()) { @@ -44,7 +52,7 @@ MaaRecoId MaaContextRunRecognition(MaaContext* context, const char* entry, const return MaaInvalidId; } - return context->run_recognition(entry, *ov_opt, mat); + return context->run_recognition(entry, ov_opt->as_object(), mat); } MaaNodeId @@ -62,6 +70,10 @@ MaaNodeId LogError << "failed to parse" << VAR(pipeline_override); return MaaInvalidId; } + if (!ov_opt->is_object()) { + LogError << "json is not object" << VAR(pipeline_override); + return MaaInvalidId; + } cv::Rect cvbox {}; if (box) { @@ -70,7 +82,7 @@ MaaNodeId cvbox.width = box->width; cvbox.height = box->height; } - return context->run_action(entry, *ov_opt, cvbox, reco_detail); + return context->run_action(entry, ov_opt->as_object(), cvbox, reco_detail); } MaaBool MaaContextOverridePipeline(MaaContext* context, const char* pipeline_override) @@ -86,8 +98,12 @@ MaaBool MaaContextOverridePipeline(MaaContext* context, const char* pipeline_ove LogError << "failed to parse" << VAR(pipeline_override); return false; } + if (!ov_opt->is_object()) { + LogError << "json is not object" << VAR(pipeline_override); + return MaaInvalidId; + } - return context->override_pipeline(*ov_opt); + return context->override_pipeline(ov_opt->as_object()); } MaaBool MaaContextOverrideNext(MaaContext* context, const char* name, const MaaStringListBuffer* next_list) diff --git a/source/MaaFramework/API/MaaTasker.cpp b/source/MaaFramework/API/MaaTasker.cpp index 6da6be393..155cadaea 100644 --- a/source/MaaFramework/API/MaaTasker.cpp +++ b/source/MaaFramework/API/MaaTasker.cpp @@ -84,8 +84,12 @@ MaaTaskId MaaTaskerPostPipeline(MaaTasker* tasker, const char* entry, const char LogError << "failed to parse" << VAR(pipeline_override); return MaaInvalidId; } + if (!ov_opt->is_object()) { + LogError << "json is not object" << VAR(pipeline_override); + return MaaInvalidId; + } - return tasker->post_pipeline(entry, *ov_opt); + return tasker->post_pipeline(entry, ov_opt->as_object()); } MaaStatus MaaTaskerStatus(const MaaTasker* tasker, MaaTaskId id) diff --git a/source/MaaFramework/API/MaaTypes.h b/source/MaaFramework/API/MaaTypes.h index 6f245699b..4c009916d 100644 --- a/source/MaaFramework/API/MaaTypes.h +++ b/source/MaaFramework/API/MaaTypes.h @@ -77,7 +77,7 @@ struct MaaTasker virtual bool set_option(MaaTaskerOption key, MaaOptionValue value, MaaOptionValueSize val_size) = 0; - virtual MaaTaskId post_pipeline(const std::string& entry, const json::value& pipeline_override) = 0; + virtual MaaTaskId post_pipeline(const std::string& entry, const json::object& pipeline_override) = 0; virtual MaaStatus status(MaaTaskId task_id) const = 0; virtual MaaStatus wait(MaaTaskId task_id) const = 0; @@ -100,11 +100,11 @@ struct MaaContext public: virtual ~MaaContext() = default; - virtual MaaTaskId run_pipeline(const std::string& entry, const json::value& pipeline_override) = 0; - virtual MaaRecoId run_recognition(const std::string& entry, const json::value& pipeline_override, const cv::Mat& image) = 0; + virtual MaaTaskId run_pipeline(const std::string& entry, const json::object& pipeline_override) = 0; + virtual MaaRecoId run_recognition(const std::string& entry, const json::object& pipeline_override, const cv::Mat& image) = 0; virtual MaaNodeId - run_action(const std::string& entry, const json::value& pipeline_override, const cv::Rect& box, const std::string& reco_detail) = 0; - virtual bool override_pipeline(const json::value& pipeline_override) = 0; + run_action(const std::string& entry, const json::object& pipeline_override, const cv::Rect& box, const std::string& reco_detail) = 0; + virtual bool override_pipeline(const json::object& pipeline_override) = 0; virtual bool override_next(const std::string& name, const std::vector& next) = 0; virtual MaaContext* clone() const = 0; diff --git a/source/MaaFramework/Task/Context.cpp b/source/MaaFramework/Task/Context.cpp index 01392dc3e..a4e1b0070 100644 --- a/source/MaaFramework/Task/Context.cpp +++ b/source/MaaFramework/Task/Context.cpp @@ -44,7 +44,7 @@ Context::Context(const Context& other) LogDebug << VAR(other.getptr()); } -MaaTaskId Context::run_pipeline(const std::string& entry, const json::value& pipeline_override) +MaaTaskId Context::run_pipeline(const std::string& entry, const json::object& pipeline_override) { LogFunc << VAR(getptr()) << VAR(entry) << VAR(pipeline_override); @@ -79,7 +79,7 @@ MaaTaskId Context::run_pipeline(const std::string& entry, const json::value& pip return subtask.task_id(); } -MaaRecoId Context::run_recognition(const std::string& entry, const json::value& pipeline_override, const cv::Mat& image) +MaaRecoId Context::run_recognition(const std::string& entry, const json::object& pipeline_override, const cv::Mat& image) { LogFunc << VAR(getptr()) << VAR(entry) << VAR(pipeline_override); @@ -93,7 +93,7 @@ MaaRecoId Context::run_recognition(const std::string& entry, const json::value& } MaaNodeId - Context::run_action(const std::string& entry, const json::value& pipeline_override, const cv::Rect& box, const std::string& reco_detail) + Context::run_action(const std::string& entry, const json::object& pipeline_override, const cv::Rect& box, const std::string& reco_detail) { LogFunc << VAR(getptr()) << VAR(entry) << VAR(pipeline_override) << VAR(box) << VAR(reco_detail); @@ -107,15 +107,10 @@ MaaNodeId return subtask.run_with_param(box, j_detail); } -bool Context::override_pipeline(const json::value& pipeline_override) +bool Context::override_pipeline(const json::object& pipeline_override) { LogFunc << VAR(getptr()) << VAR(pipeline_override); - if (!pipeline_override.is_object()) { - LogError << "json is not object"; - return false; - } - if (!tasker_) { LogError << "tasker is null"; return false; @@ -127,7 +122,7 @@ bool Context::override_pipeline(const json::value& pipeline_override) } auto& default_mgr = resource->default_pipeline(); - for (const auto& [key, value] : pipeline_override.as_object()) { + for (const auto& [key, value] : pipeline_override) { PipelineData result; auto default_result = get_pipeline_data(key).value_or(default_mgr.get_pipeline()); bool ret = MAA_RES_NS::PipelineResMgr::parse_task(key, value, result, default_result, default_mgr); diff --git a/source/MaaFramework/Task/Context.h b/source/MaaFramework/Task/Context.h index 801df79f0..9599b030a 100644 --- a/source/MaaFramework/Task/Context.h +++ b/source/MaaFramework/Task/Context.h @@ -35,12 +35,12 @@ class Context virtual ~Context() override = default; public: // from MaaContextAPI - virtual MaaTaskId run_pipeline(const std::string& entry, const json::value& pipeline_override) override; - virtual MaaRecoId run_recognition(const std::string& entry, const json::value& pipeline_override, const cv::Mat& image) override; + virtual MaaTaskId run_pipeline(const std::string& entry, const json::object& pipeline_override) override; + virtual MaaRecoId run_recognition(const std::string& entry, const json::object& pipeline_override, const cv::Mat& image) override; virtual MaaNodeId - run_action(const std::string& entry, const json::value& pipeline_override, const cv::Rect& box, const std::string& reco_detail) + run_action(const std::string& entry, const json::object& pipeline_override, const cv::Rect& box, const std::string& reco_detail) override; - virtual bool override_pipeline(const json::value& pipeline_override) override; + virtual bool override_pipeline(const json::object& pipeline_override) override; virtual bool override_next(const std::string& name, const std::vector& next) override; virtual Context* clone() const override; diff --git a/source/MaaFramework/Task/TaskBase.cpp b/source/MaaFramework/Task/TaskBase.cpp index 0115b3896..fcd43b741 100644 --- a/source/MaaFramework/Task/TaskBase.cpp +++ b/source/MaaFramework/Task/TaskBase.cpp @@ -27,7 +27,7 @@ TaskBase::TaskBase(std::string entry, Tasker* tasker, std::shared_ptr c { } -bool TaskBase::override_pipeline(const json::value& pipeline_override) +bool TaskBase::override_pipeline(const json::object& pipeline_override) { return context_ && context_->override_pipeline(pipeline_override); } diff --git a/source/MaaFramework/Task/TaskBase.h b/source/MaaFramework/Task/TaskBase.h index e63af1be3..c6688d90f 100644 --- a/source/MaaFramework/Task/TaskBase.h +++ b/source/MaaFramework/Task/TaskBase.h @@ -30,7 +30,7 @@ class TaskBase virtual void post_stop() = 0; public: - bool override_pipeline(const json::value& pipeline_override); + bool override_pipeline(const json::object& pipeline_override); public: Tasker* tasker() const; diff --git a/source/MaaFramework/Tasker/Tasker.cpp b/source/MaaFramework/Tasker/Tasker.cpp index df9114a8f..3114422e5 100644 --- a/source/MaaFramework/Tasker/Tasker.cpp +++ b/source/MaaFramework/Tasker/Tasker.cpp @@ -69,7 +69,7 @@ bool Tasker::set_option(MaaTaskerOption key, MaaOptionValue value, MaaOptionValu return false; } -MaaTaskId Tasker::post_pipeline(const std::string& entry, const json::value& pipeline_override) +MaaTaskId Tasker::post_pipeline(const std::string& entry, const json::object& pipeline_override) { LogInfo << VAR(entry) << VAR(pipeline_override); @@ -188,7 +188,7 @@ void Tasker::notify(std::string_view msg, const json::value& detail) notifier.notify(msg, detail); } -MaaTaskId Tasker::post_task(TaskPtr task_ptr, const json::value& pipeline_override) +MaaTaskId Tasker::post_task(TaskPtr task_ptr, const json::object& pipeline_override) { #ifndef MAA_DEBUG if (!inited()) { diff --git a/source/MaaFramework/Tasker/Tasker.h b/source/MaaFramework/Tasker/Tasker.h index 5211a700f..33b950fc4 100644 --- a/source/MaaFramework/Tasker/Tasker.h +++ b/source/MaaFramework/Tasker/Tasker.h @@ -30,7 +30,7 @@ class Tasker : public MaaTasker virtual bool set_option(MaaTaskerOption key, MaaOptionValue value, MaaOptionValueSize val_size) override; - virtual MaaTaskId post_pipeline(const std::string& entry, const json::value& pipeline_override) override; + virtual MaaTaskId post_pipeline(const std::string& entry, const json::object& pipeline_override) override; virtual MaaStatus status(MaaTaskId task_id) const override; virtual MaaStatus wait(MaaTaskId task_id) const override; @@ -56,7 +56,7 @@ class Tasker : public MaaTasker using TaskPtr = std::shared_ptr; using RunnerId = AsyncRunner::Id; - MaaTaskId post_task(TaskPtr task_ptr, const json::value& pipeline_override); + MaaTaskId post_task(TaskPtr task_ptr, const json::object& pipeline_override); bool run_task(RunnerId id, TaskPtr task_ptr); bool check_stop();