2019-04-04 11:16:32 -05:00
|
|
|
// 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.
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
#ifndef RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|
|
|
|
#define RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|
2019-04-04 11:16:32 -05:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
#include "composition_interfaces/srv/load_node.hpp"
|
|
|
|
#include "composition_interfaces/srv/unload_node.hpp"
|
|
|
|
#include "composition_interfaces/srv/list_nodes.hpp"
|
2019-04-04 11:16:32 -05:00
|
|
|
|
|
|
|
#include "rclcpp/executor.hpp"
|
|
|
|
#include "rclcpp/node_options.hpp"
|
|
|
|
#include "rclcpp/rclcpp.hpp"
|
|
|
|
|
|
|
|
#include "rclcpp_components/node_factory.hpp"
|
2020-04-15 19:08:04 -07:00
|
|
|
#include "rclcpp_components/visibility_control.hpp"
|
|
|
|
|
|
|
|
namespace class_loader
|
|
|
|
{
|
|
|
|
class ClassLoader;
|
|
|
|
} // namespace class_loader
|
2019-04-04 11:16:32 -05:00
|
|
|
|
|
|
|
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>;
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
2019-04-04 11:16:32 -05:00
|
|
|
ComponentManager(
|
2020-04-23 15:28:45 -07:00
|
|
|
std::weak_ptr<rclcpp::Executor> executor,
|
2020-04-15 19:08:04 -07:00
|
|
|
std::string node_name = "ComponentManager",
|
|
|
|
const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions());
|
2019-04-04 11:16:32 -05:00
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual ~ComponentManager();
|
2019-04-04 11:16:32 -05:00
|
|
|
|
|
|
|
/// Return a list of valid loadable components in a given package.
|
2020-04-15 19:08:04 -07:00
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual std::vector<ComponentResource>
|
|
|
|
get_component_resources(
|
|
|
|
const std::string & package_name,
|
|
|
|
const std::string & resource_index = "rclcpp_components") const;
|
|
|
|
|
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual std::shared_ptr<rclcpp_components::NodeFactory>
|
2019-04-04 11:16:32 -05:00
|
|
|
create_component_factory(const ComponentResource & resource);
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
protected:
|
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual void
|
2019-04-04 11:16:32 -05:00
|
|
|
OnLoadNode(
|
|
|
|
const std::shared_ptr<rmw_request_id_t> request_header,
|
|
|
|
const std::shared_ptr<LoadNode::Request> request,
|
|
|
|
std::shared_ptr<LoadNode::Response> response);
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual void
|
2019-04-04 11:16:32 -05:00
|
|
|
OnUnloadNode(
|
|
|
|
const std::shared_ptr<rmw_request_id_t> request_header,
|
|
|
|
const std::shared_ptr<UnloadNode::Request> request,
|
|
|
|
std::shared_ptr<UnloadNode::Response> response);
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
RCLCPP_COMPONENTS_PUBLIC
|
|
|
|
virtual void
|
2019-04-04 11:16:32 -05:00
|
|
|
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:
|
2020-04-23 15:28:45 -07:00
|
|
|
std::weak_ptr<rclcpp::Executor> executor_;
|
2019-04-04 11:16:32 -05:00
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
uint64_t unique_id_ {1};
|
2019-04-04 11:16:32 -05:00
|
|
|
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
|
|
|
|
|
2020-04-15 19:08:04 -07:00
|
|
|
#endif // RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|