AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
resources.cpp
Go to the documentation of this file.
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17#include "ament_index_cpp/get_resources.hpp"
18#include "ament_index_cpp/get_resource.hpp"
21
22namespace auto_apms_core
23{
24
25std::set<std::string> getAllPackagesWithResource(const std::string& resource_type)
26{
27 std::set<std::string> all_packages;
28 for (const auto& [package_name, _] : ament_index_cpp::get_resources(resource_type))
29 {
30 all_packages.insert(package_name);
31 }
32 if (all_packages.empty())
33 {
34 throw exceptions::ResourceNotFoundError("No resources of type '" + resource_type +
35 "' were found in the installed packages.");
36 }
37 return all_packages;
38}
39
40std::vector<std::string> collectPluginXMLPaths(const std::string& resource_type,
41 const std::set<std::string>& search_packages)
42{
43 std::vector<std::string> xml_paths;
44 for (const auto& name : search_packages.empty() ? getAllPackagesWithResource(resource_type) : search_packages)
45 {
46 std::string content;
47 std::string base_path;
48 if (ament_index_cpp::get_resource(resource_type, name, content, &base_path))
49 {
50 std::vector<std::string> paths = util::splitString(content, "\n", false);
51 if (paths.size() != 1)
52 {
53 throw exceptions::ResourceNotFoundError("Invalid resource marker file installed by package: '" + name +
54 "' for resource type '" + resource_type +
55 "'. Must contain a single line with a path to the plugins.xml "
56 "manifest file relative to the package's install prefix.");
57 }
58 xml_paths.push_back(base_path + '/' + paths[0]);
59 }
60 else
61 {
62 throw exceptions::ResourceNotFoundError("Cannot find any resources for type '" + resource_type +
63 "' in install directory of package '" + name + "'.");
64 }
65 }
66 return xml_paths;
67}
68
69} // namespace auto_apms_core
std::vector< std::string > collectPluginXMLPaths(const std::string &resource_type, const std::set< std::string > &search_packages={})
Collect the paths of plugin.xml manifest files used for initializing pluginlib::ClassLoader objects.
Definition resources.cpp:40
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool preserve_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
Definition string.cpp:24
std::set< std::string > getAllPackagesWithResource(const std::string &resource_type)
Collect all package names that register a certain type of ament_index resources.
Definition resources.cpp:25