330 if (search_identity.empty()) {
331 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
332 "Cannot create behavior resource with empty identity.");
335 std::set<std::string> search_packages;
336 if (!search_identity.package_name.empty()) {
337 search_packages.insert(search_identity.package_name);
343 size_t matching_count = 0;
344 for (
const auto & p : search_packages) {
346 std::string base_path;
347 if (ament_index_cpp::get_resource(
348 _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_TYPE_NAME__BEHAVIOR, p, content, &base_path)) {
349 for (
const auto & line :
352 line, _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_MARKER_FILE_FIELD_PER_LINE_SEP,
false);
353 if (parts.size() != 6) {
354 throw auto_apms_util::exceptions::ResourceError(
355 "Invalid behavior tree resource file (Package: '" + p +
"'). Invalid line: " + line +
".");
359 std::string found_category = parts[0];
360 std::string found_alias = parts[1];
361 if (search_identity.category_name.empty()) {
363 if (found_alias != search_identity.behavior_alias) {
366 }
else if (found_category != search_identity.category_name || found_alias != search_identity.behavior_alias) {
377 unique_identity_.category_name = found_category;
380 unique_identity_.behavior_alias = found_alias;
383 unique_identity_.package_name = p;
386 default_build_handler_ = parts[2];
389 build_request_file_path_ = base_path +
"/" + parts[3];
390 if (std::filesystem::is_regular_file(build_request_file_path_)) {
391 std::ifstream file(build_request_file_path_);
393 throw auto_apms_util::exceptions::ResourceError(
394 "Failed to open behavior resource file '" + build_request_file_path_ +
"'");
396 build_request_ = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
398 build_request_file_path_ =
"";
399 build_request_ = parts[3];
403 entry_point_ = parts[4];
406 std::vector<std::string> node_manifest_paths;
408 node_manifest_paths.push_back(std::filesystem::path(path).is_absolute() ? path : (base_path +
"/" + path));
415 if (matching_count == 0) {
416 throw auto_apms_util::exceptions::ResourceError(
417 "No behavior resource with identity '" + search_identity.str() +
"' was registered.");
419 if (matching_count > 1) {
420 throw auto_apms_util::exceptions::ResourceError(
421 "Behavior resource identity '" + search_identity.str() +
"' is ambiguous. You must be more precise.");