Program Listing for File node_thread.hpp

Return to documentation for file (include/psdk_wrapper/utils/node_thread.hpp)

// Copyright (c) 2019 Intel Corporation
//
// 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 PSDK_WRAPPER_INCLUDE_PSDK_WRAPPER_UTILS_NODE_THREAD_HPP_
#define PSDK_WRAPPER_INCLUDE_PSDK_WRAPPER_UTILS_NODE_THREAD_HPP_

#include <memory>

#include "rclcpp/rclcpp.hpp"

namespace utils
{

class NodeThread
{
 public:
  explicit NodeThread(
      rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base);

  explicit NodeThread(
      rclcpp::executors::SingleThreadedExecutor::SharedPtr executor);

  template <typename NodeT>
  explicit NodeThread(NodeT node) : NodeThread(node->get_node_base_interface())
  {
  }

  ~NodeThread();

 protected:
  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_;
  std::unique_ptr<std::thread> thread_;
  rclcpp::Executor::SharedPtr executor_;
};

}  // namespace utils

#endif  // PSDK_WRAPPER_INCLUDE_PSDK_WRAPPER_UTILS_NODE_THREAD_HPP_