Skip to content

Commit

Permalink
fix: wrong pipeline_override internal type
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Dec 4, 2024
1 parent 4f567eb commit 9e69ad9
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 30 deletions.
24 changes: 20 additions & 4 deletions source/MaaFramework/API/MaaContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,14 +41,18 @@ 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()) {
LogError << "empty image";
return MaaInvalidId;
}

return context->run_recognition(entry, *ov_opt, mat);
return context->run_recognition(entry, ov_opt->as_object(), mat);
}

MaaNodeId
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion source/MaaFramework/API/MaaTasker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions source/MaaFramework/API/MaaTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<std::string>& next) = 0;

virtual MaaContext* clone() const = 0;
Expand Down
15 changes: 5 additions & 10 deletions source/MaaFramework/Task/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions source/MaaFramework/Task/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& next) override;

virtual Context* clone() const override;
Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Task/TaskBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TaskBase::TaskBase(std::string entry, Tasker* tasker, std::shared_ptr<Context> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Task/TaskBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/Tasker/Tasker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/Tasker/Tasker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,7 +56,7 @@ class Tasker : public MaaTasker
using TaskPtr = std::shared_ptr<MAA_TASK_NS::TaskBase>;
using RunnerId = AsyncRunner<TaskPtr>::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();
Expand Down

0 comments on commit 9e69ad9

Please sign in to comment.