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
|
@ -0,0 +1,119 @@
|
|||
// 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 RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|
||||
#define RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "composition_interfaces/srv/load_node.hpp"
|
||||
#include "composition_interfaces/srv/unload_node.hpp"
|
||||
#include "composition_interfaces/srv/list_nodes.hpp"
|
||||
|
||||
#include "rclcpp/executor.hpp"
|
||||
#include "rclcpp/node_options.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "rclcpp_components/node_factory.hpp"
|
||||
#include "rclcpp_components/visibility_control.hpp"
|
||||
|
||||
namespace class_loader
|
||||
{
|
||||
class ClassLoader;
|
||||
} // namespace class_loader
|
||||
|
||||
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>;
|
||||
|
||||
RCLCPP_COMPONENTS_PUBLIC
|
||||
ComponentManager(
|
||||
std::weak_ptr<rclcpp::executor::Executor> executor,
|
||||
std::string node_name = "ComponentManager",
|
||||
const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions());
|
||||
|
||||
RCLCPP_COMPONENTS_PUBLIC
|
||||
virtual ~ComponentManager();
|
||||
|
||||
/// Return a list of valid loadable components in a given package.
|
||||
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>
|
||||
create_component_factory(const ComponentResource & resource);
|
||||
|
||||
protected:
|
||||
RCLCPP_COMPONENTS_PUBLIC
|
||||
virtual 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);
|
||||
|
||||
RCLCPP_COMPONENTS_PUBLIC
|
||||
virtual 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);
|
||||
|
||||
RCLCPP_COMPONENTS_PUBLIC
|
||||
virtual 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 // RCLCPP_COMPONENTS__COMPONENT_MANAGER_HPP__
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2020 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.
|
||||
|
||||
/* This header must be included by all rclcpp headers which declare symbols
|
||||
* which are defined in the rclcpp library. When not building the rclcpp
|
||||
* library, i.e. when using the headers in other package's code, the contents
|
||||
* of this header change the visibility of certain symbols which the rclcpp
|
||||
* library cannot have, but the consuming code must have inorder to link.
|
||||
*/
|
||||
|
||||
#ifndef RCLCPP_COMPONENTS__VISIBILITY_CONTROL_HPP_
|
||||
#define RCLCPP_COMPONENTS__VISIBILITY_CONTROL_HPP_
|
||||
|
||||
// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
|
||||
// https://gcc.gnu.org/wiki/Visibility
|
||||
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
#ifdef __GNUC__
|
||||
#define RCLCPP_COMPONENTS_EXPORT __attribute__ ((dllexport))
|
||||
#define RCLCPP_COMPONENTS_IMPORT __attribute__ ((dllimport))
|
||||
#else
|
||||
#define RCLCPP_COMPONENTS_EXPORT __declspec(dllexport)
|
||||
#define RCLCPP_COMPONENTS_IMPORT __declspec(dllimport)
|
||||
#endif
|
||||
#ifdef RCLCPP_COMPONENTS_BUILDING_LIBRARY
|
||||
#define RCLCPP_COMPONENTS_PUBLIC RCLCPP_COMPONENTS_EXPORT
|
||||
#else
|
||||
#define RCLCPP_COMPONENTS_PUBLIC RCLCPP_COMPONENTS_IMPORT
|
||||
#endif
|
||||
#define RCLCPP_COMPONENTS_PUBLIC_TYPE RCLCPP_COMPONENTS_PUBLIC
|
||||
#define RCLCPP_COMPONENTS_LOCAL
|
||||
#else
|
||||
#define RCLCPP_COMPONENTS_EXPORT __attribute__ ((visibility("default")))
|
||||
#define RCLCPP_COMPONENTS_IMPORT
|
||||
#if __GNUC__ >= 4
|
||||
#define RCLCPP_COMPONENTS_PUBLIC __attribute__ ((visibility("default")))
|
||||
#define RCLCPP_COMPONENTS_LOCAL __attribute__ ((visibility("hidden")))
|
||||
#else
|
||||
#define RCLCPP_COMPONENTS_PUBLIC
|
||||
#define RCLCPP_COMPONENTS_LOCAL
|
||||
#endif
|
||||
#define RCLCPP_COMPONENTS_PUBLIC_TYPE
|
||||
#endif
|
||||
|
||||
#endif // RCLCPP_COMPONENTS__VISIBILITY_CONTROL_HPP_
|
Loading…
Add table
Add a link
Reference in a new issue