Make Component Manager public (#1065)
* make functions public & virtual Signed-off-by: Karsten Knese <karsten@openrobotics.org> * flexible resource index for cmake macros Signed-off-by: Karsten Knese <karsten@openrobotics.org> * review comments Signed-off-by: Karsten Knese <karsten@openrobotics.org> * remove superfluous include Signed-off-by: Karsten Knese <karsten@openrobotics.org> * remove wrong dllexort Signed-off-by: Karsten Knese <karsten@openrobotics.org> * check for empty plugin & executable args Signed-off-by: Karsten Knese <karsten@openrobotics.org> * remove commented lines Signed-off-by: Karsten Knese <karsten@openrobotics.org> * fix typo Signed-off-by: Karsten Knese <karsten@openrobotics.org> * relax macro constraints Signed-off-by: Karsten Knese <karsten@openrobotics.org>
This commit is contained in:
parent
44fa4fe019
commit
50d500e84e
11 changed files with 146 additions and 40 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "component_manager.hpp"
|
||||
#include "rclcpp_components/component_manager.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "component_manager.hpp"
|
||||
#include "rclcpp_components/component_manager.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
|
|
|
@ -12,14 +12,16 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "component_manager.hpp"
|
||||
#include "rclcpp_components/component_manager.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "ament_index_cpp/get_resource.hpp"
|
||||
#include "class_loader/class_loader.hpp"
|
||||
#include "rcpputils/filesystem_helper.hpp"
|
||||
#include "rcpputils/split.hpp"
|
||||
|
||||
|
@ -29,8 +31,10 @@ namespace rclcpp_components
|
|||
{
|
||||
|
||||
ComponentManager::ComponentManager(
|
||||
std::weak_ptr<rclcpp::executor::Executor> executor)
|
||||
: Node("ComponentManager"),
|
||||
std::weak_ptr<rclcpp::executor::Executor> executor,
|
||||
std::string node_name,
|
||||
const rclcpp::NodeOptions & node_options)
|
||||
: Node(std::move(node_name), node_options),
|
||||
executor_(executor)
|
||||
{
|
||||
loadNode_srv_ = create_service<LoadNode>(
|
||||
|
@ -57,13 +61,14 @@ ComponentManager::~ComponentManager()
|
|||
}
|
||||
|
||||
std::vector<ComponentManager::ComponentResource>
|
||||
ComponentManager::get_component_resources(const std::string & package_name) const
|
||||
ComponentManager::get_component_resources(
|
||||
const std::string & package_name, const std::string & resource_index) const
|
||||
{
|
||||
std::string content;
|
||||
std::string base_path;
|
||||
if (
|
||||
!ament_index_cpp::get_resource(
|
||||
"rclcpp_components", package_name, content, &base_path))
|
||||
resource_index, package_name, content, &base_path))
|
||||
{
|
||||
throw ComponentManagerException("Could not find requested resource in ament index");
|
||||
}
|
||||
|
@ -176,7 +181,7 @@ ComponentManager::OnLoadNode(
|
|||
}
|
||||
}
|
||||
|
||||
auto node_id = unique_id++;
|
||||
auto node_id = unique_id_++;
|
||||
|
||||
if (0 == node_id) {
|
||||
// This puts a technical limit on the number of times you can add a component.
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
// Copyright 2019 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef COMPONENT_MANAGER_HPP__
|
||||
#define COMPONENT_MANAGER_HPP__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "class_loader/class_loader.hpp"
|
||||
|
||||
#include "rclcpp/executor.hpp"
|
||||
#include "rclcpp/node_options.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "composition_interfaces/srv/load_node.hpp"
|
||||
#include "composition_interfaces/srv/unload_node.hpp"
|
||||
#include "composition_interfaces/srv/list_nodes.hpp"
|
||||
|
||||
#include "rclcpp_components/node_factory.hpp"
|
||||
|
||||
namespace rclcpp_components
|
||||
{
|
||||
|
||||
class ComponentManagerException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit ComponentManagerException(const std::string & error_desc)
|
||||
: std::runtime_error(error_desc) {}
|
||||
};
|
||||
|
||||
class ComponentManager : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
using LoadNode = composition_interfaces::srv::LoadNode;
|
||||
using UnloadNode = composition_interfaces::srv::UnloadNode;
|
||||
using ListNodes = composition_interfaces::srv::ListNodes;
|
||||
|
||||
/// Represents a component resource.
|
||||
/**
|
||||
* Is a pair of class name (for class loader) and library path (absolute)
|
||||
*/
|
||||
using ComponentResource = std::pair<std::string, std::string>;
|
||||
|
||||
ComponentManager(
|
||||
std::weak_ptr<rclcpp::executor::Executor> executor);
|
||||
|
||||
~ComponentManager();
|
||||
|
||||
/// Return a list of valid loadable components in a given package.
|
||||
std::vector<ComponentResource>
|
||||
get_component_resources(const std::string & package_name) const;
|
||||
|
||||
std::shared_ptr<rclcpp_components::NodeFactory>
|
||||
create_component_factory(const ComponentResource & resource);
|
||||
|
||||
private:
|
||||
void
|
||||
OnLoadNode(
|
||||
const std::shared_ptr<rmw_request_id_t> request_header,
|
||||
const std::shared_ptr<LoadNode::Request> request,
|
||||
std::shared_ptr<LoadNode::Response> response);
|
||||
|
||||
void
|
||||
OnUnloadNode(
|
||||
const std::shared_ptr<rmw_request_id_t> request_header,
|
||||
const std::shared_ptr<UnloadNode::Request> request,
|
||||
std::shared_ptr<UnloadNode::Response> response);
|
||||
|
||||
void
|
||||
OnListNodes(
|
||||
const std::shared_ptr<rmw_request_id_t> request_header,
|
||||
const std::shared_ptr<ListNodes::Request> request,
|
||||
std::shared_ptr<ListNodes::Response> response);
|
||||
|
||||
private:
|
||||
std::weak_ptr<rclcpp::executor::Executor> executor_;
|
||||
|
||||
uint64_t unique_id {1};
|
||||
std::map<std::string, std::unique_ptr<class_loader::ClassLoader>> loaders_;
|
||||
std::map<uint64_t, rclcpp_components::NodeInstanceWrapper> node_wrappers_;
|
||||
|
||||
rclcpp::Service<LoadNode>::SharedPtr loadNode_srv_;
|
||||
rclcpp::Service<UnloadNode>::SharedPtr unloadNode_srv_;
|
||||
rclcpp::Service<ListNodes>::SharedPtr listNodes_srv_;
|
||||
};
|
||||
|
||||
} // namespace rclcpp_components
|
||||
|
||||
#endif // COMPONENT_MANAGER_HPP__
|
Loading…
Add table
Add a link
Reference in a new issue