Program Listing for File ros_gz_bridge.hpp

Return to documentation for file (include/ros_gz_bridge/ros_gz_bridge.hpp)

// Copyright 2022 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 ROS_GZ_BRIDGE__ROS_GZ_BRIDGE_HPP_
#define ROS_GZ_BRIDGE__ROS_GZ_BRIDGE_HPP_

#include <memory>
#include <string>
#include <vector>

#include <gz/msgs/config.hh>
#include <gz/transport/Node.hh>
#include <rclcpp/node.hpp>
#include "ros_gz_bridge/bridge_config.hpp"

namespace ros_gz_bridge
{
class BridgeHandle;

class RosGzBridge : public rclcpp::Node
{
public:
  explicit RosGzBridge(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

  void add_bridge(const BridgeConfig & config);

  void add_service_bridge(
    const std::string & ros_type_name,
    const std::string & gz_req_type_name,
    const std::string & gz_rep_type_name,
    const std::string & service_name);

protected:
  void spin();

protected:
  std::shared_ptr<gz::transport::Node> gz_node_;

  std::vector<std::shared_ptr<ros_gz_bridge::BridgeHandle>> handles_;

  std::vector<rclcpp::ServiceBase::SharedPtr> services_;

  rclcpp::TimerBase::SharedPtr heartbeat_timer_;
};
}  // namespace ros_gz_bridge

#endif  // ROS_GZ_BRIDGE__ROS_GZ_BRIDGE_HPP_