14 #ifndef DS3D_COMMON_HPP_YAML_CONFIG_HPP
15 #define DS3D_COMMON_HPP_YAML_CONFIG_HPP
17 #include <ds3d/common/common.h>
18 #include <ds3d/common/idatatype.h>
19 #include <ds3d/common/type_trait.h>
20 #include <ds3d/common/config.h>
21 #include <yaml-cpp/yaml.h>
26 namespace ds3d {
namespace config {
39 template <class F, typename... Args>
44 DS3D_TRY { code = f(std::forward<Args>(args)...); }
53 parseComponentConfig(const std::
string& yamlComp, const std::
string& path, ComponentConfig& config)
55 config.filePath = path;
57 YAML::Node node = YAML::Load(yamlComp);
58 config.name = node[
"name"].as<std::string>();
60 std::string type = node[
"type"].as<std::string>();
65 auto inCapsNode = node[
"in_caps"];
67 config.gstInCaps = inCapsNode.as<std::string>();
69 auto outCapsNode = node[
"out_caps"];
71 config.gstOutCaps = outCapsNode.as<std::string>();
73 auto linkToNode = node[
"link_to"];
75 config.linkTo = linkToNode.as<std::string>();
77 auto linkFromNode = node[
"link_from"];
79 config.linkFrom = linkFromNode.as<std::string>();
82 auto withQueueNode = node[
"with_queue"];
84 config.withQueue = withQueueNode.as<std::string>();
87 if (node[
"custom_lib_path"]) {
88 config.customLibPath = node[
"custom_lib_path"].as<std::string>();
90 !config.customLibPath.empty(),
ErrCode::kConfig,
"custom_lib_path not found in config");
92 if (node[
"custom_create_function"]) {
93 config.customCreateFunction = node[
"custom_create_function"].as<std::string>();
96 "custom_create_function not found in config");
99 auto bodyNode = node[
"config_body"];
102 if (!bodyNode[
"config_path"] && !path.empty()) {
103 bodyNode[
"config_path"] = path;
109 "config_body error in config, yaml error: " + body.GetLastError());
110 config.configBody = body.c_str();
113 YAML::Emitter yRawContent;
115 config.rawContent = yRawContent.c_str();
121 const std::string& yamlDoc,
const std::string& path, std::vector<ComponentConfig>& all)
123 auto nodes = YAML::LoadAll(yamlDoc);
124 for (
const auto& doc : nodes) {
128 YAML::Emitter content;
132 "component error in config, yaml error: " + content.GetLastError());
133 ComponentConfig config;
136 "parsing a component failed in config");
137 all.push_back(config);
144 #endif // DS3D_COMMON_HPP_YAML_CONFIG_HPP