Program Listing for File Dispatcher.hpp

Return to documentation for file (include/rmf_task_ros2/Dispatcher.hpp)

/*
 * Copyright (C) 2020 Open Source Robotics Foundation
 *
 * 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 RMF_TASK_ROS2__DISPATCHER_HPP
#define RMF_TASK_ROS2__DISPATCHER_HPP

#include <rclcpp/node.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rmf_utils/impl_ptr.hpp>
#include <rmf_utils/optional.hpp>

#include <rmf_task_ros2/bidding/Auctioneer.hpp>
#include <rmf_task_ros2/DispatchState.hpp>

// Deprecated message definition
#include <rmf_task_msgs/msg/task_description.hpp>

namespace rmf_task_ros2 {

//==============================================================================
class Dispatcher : public std::enable_shared_from_this<Dispatcher>
{
public:
  using DispatchStates = std::unordered_map<TaskID, DispatchStatePtr>;

  static std::shared_ptr<Dispatcher> init_and_make_node(
    const std::string dispatcher_node_name);

  static std::shared_ptr<Dispatcher> make_node(
    const std::string dispatcher_node_name);

  static std::shared_ptr<Dispatcher> make(
    const std::shared_ptr<rclcpp::Node>& node);

  [[deprecated]]
  std::optional<TaskID> submit_task(
    const rmf_task_msgs::msg::TaskDescription& task_description);

  bool cancel_task(const TaskID& task_id);

  std::optional<DispatchState> get_dispatch_state(
    const TaskID& task_id) const;

  const DispatchStates& active_dispatches() const;

  const DispatchStates& finished_dispatches() const;

  using DispatchStateCallback =
    std::function<void(const DispatchState& status)>;

  void on_change(DispatchStateCallback on_change_fn);

  void evaluator(bidding::Auctioneer::ConstEvaluatorPtr evaluator);

  std::shared_ptr<rclcpp::Node> node();

  void spin();

  class Implementation;

private:
  Dispatcher();
  rmf_utils::unique_impl_ptr<Implementation> _pimpl;
};

} // namespace rmf_task_ros2

#endif // RMF_TASK_ROS2__DISPATCHER_HPP