Skip to content

Commit

Permalink
refactor: ProjectInterface Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Feb 5, 2024
1 parent 8e4d867 commit 2ef2fc9
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 204 deletions.
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (WITH_DBG_CONTROLLER)
endif()

add_subdirectory(LibraryHolder)
add_subdirectory(TaskAgent)
add_subdirectory(ProjectInterface)
add_subdirectory(MaaFramework)
add_subdirectory(MaaToolkit)

Expand Down
13 changes: 13 additions & 0 deletions source/ProjectInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
file(GLOB_RECURSE project_interface_src *.h *.hpp *.cpp)
file(GLOB_RECURSE project_interface_header ../include/ProjectInterface/*)

add_library(ProjectInterface STATIC ${project_interface_src} ${project_interface_header})

target_include_directories(ProjectInterface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include ${CMAKE_CURRENT_SOURCE_DIR}/../../include)

target_link_libraries(ProjectInterface MaaUtils HeaderOnlyLibraries Boost::system)

add_dependencies(ProjectInterface MaaUtils)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${project_interface_src})
27 changes: 27 additions & 0 deletions source/ProjectInterface/Parser/Parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "ProjectInterface/Parser.h"

#include "Utils/Logger.h"

MAA_PROJECT_INTERFACE_NS_BEGIN

std::optional<InterfaceData> Parser::parse(const std::filesystem::path& path)
{
LogFunc << VAR(path);

auto root_opt = json::open(path);
if (!root_opt) {
LogError << "failed to parse" << path;
return std::nullopt;
}
const json::value& root = *root_opt;

std::string error_key;
if (!InterfaceData().check_json(root, error_key)) {
LogError << "json is not an InterfaceData" << VAR(error_key) << VAR(root);
return std::nullopt;
}

return root.as<InterfaceData>();
}

MAA_PROJECT_INTERFACE_NS_END
13 changes: 0 additions & 13 deletions source/TaskAgent/CMakeLists.txt

This file was deleted.

151 changes: 0 additions & 151 deletions source/TaskAgent/TaskAgentParser.cpp

This file was deleted.

8 changes: 4 additions & 4 deletions source/include/Conf/Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@
{
#define MAA_TOOLKIT_NS_END }

#define MAA_TASKAGENT_NS MAA_NS::TaskAgentNS
#define MAA_TASKAGENT_NS_BEGIN \
namespace MAA_TASKAGENT_NS \
#define MAA_PROJECT_INTERFACE_NS MAA_NS::ProjectInterfaceNS
#define MAA_PROJECT_INTERFACE_NS_BEGIN \
namespace MAA_PROJECT_INTERFACE_NS \
{
#define MAA_TASKAGENT_NS_END }
#define MAA_PROJECT_INTERFACE_NS_END }

#define MAA_RPC_NS MAA_NS::RpcNS
#define MAA_RPC_NS_BEGIN \
Expand Down
18 changes: 18 additions & 0 deletions source/include/ProjectInterface/Parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <filesystem>
#include <optional>
#include <unordered_map>
#include <utility>

#include "Types.h"

MAA_PROJECT_INTERFACE_NS_BEGIN

class Parser
{
public:
static std::optional<InterfaceData> parse(const std::filesystem::path& path);
};

MAA_PROJECT_INTERFACE_NS_END
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

#include "Conf/Conf.h"

MAA_TASKAGENT_NS_BEGIN
MAA_PROJECT_INTERFACE_NS_BEGIN

struct Resource
{
std::string name;
std::vector<std::string> path;

MEO_JSONIZATION(name, path);
};

struct Option
Expand All @@ -21,11 +23,15 @@ struct Option
{
std::string name;
json::value param;

MEO_JSONIZATION(name, param);
};

std::string name;
std::vector<Case> cases;
std::string default_case; // case.name

MEO_JSONIZATION(name, cases, MEO_OPT default_case);
};

struct Entry
Expand All @@ -34,27 +40,34 @@ struct Entry
std::string task;
json::value param;
std::vector<Option> options;

MEO_JSONIZATION(name, task, MEO_OPT param, MEO_OPT options);
};

struct Executor
{
enum class Type
{
Action,
Recognizer,
};
// enum class Type
//{
// Action,
// Recognizer,
// };
// Type type = Type::Action;

Type type = Type::Action;
std::string type;
std::string name;
std::string exec_path;
std::vector<std::string> exec_param;

MEO_JSONIZATION(type, name, exec_path, MEO_OPT exec_param);
};

struct AgentData
struct InterfaceData
{
std::vector<Resource> resource;
std::vector<Entry> entry;
std::vector<Executor> executor;

MEO_JSONIZATION(resource, entry, MEO_OPT executor);
};

MAA_TASKAGENT_NS_END
MAA_PROJECT_INTERFACE_NS_END
26 changes: 0 additions & 26 deletions source/include/TaskAgent/TaskAgentParser.h

This file was deleted.

0 comments on commit 2ef2fc9

Please sign in to comment.