<commit_before>#include "NodeContainer.h"

namespace ros2_components {


NodeContainer::NodeContainer(rclcpp::node::Node::SharedPtr _ros_node, int64_t _node_id, std::string _name):
    ros_node(_ros_node), node_id(_node_id), node_name(_name)
{

}

NodeContainer::~NodeContainer()
{
    abort = true;
    if(spinThread)
        spinThread->join();
}

void NodeContainer::Spin(std::chrono::nanoseconds timeout)
{
    if(isSpinning)
        throw AlreadySpinningException();
    isSpinning = true;
    if(timeout == std::chrono::nanoseconds(-1))
        rclcpp::spin_some(ros_node);
    else
    {
        executor.add_node(ros_node);
        executor.spin_once(timeout);
        executor.remove_node(ros_node);

    }
    isSpinning = false;
}

void NodeContainer::SpinAsync()
{
    if(isSpinning)
        throw AlreadySpinningException();
    auto async_spin = [&]()
    {
        isSpinning = true;
        rclcpp::WallRate loopRate(this->loop_rate);
        while(!abort && rclcpp::ok())
        {
            rclcpp::spin_some(ros_node);
            loopRate.sleep();

        }
        isSpinning = false;
        isSpinningAsync = false;
    };

    spinThread = std::make_shared<std::thread>(async_spin);
    this->isSpinningAsync = true;
}

rclcpp::node::Node::SharedPtr NodeContainer::GetRosNode()
{
    return ros_node;
}

bool NodeContainer::GetIsSpinning() const
{
    return isSpinning;
}

bool NodeContainer::GetIsSpinningAsync() const
{
    return isSpinningAsync;
}

int NodeContainer::GetLoopRate() const
{
    return loop_rate;
}

void NodeContainer::SetLoopRate(int value)
{
    loop_rate = value;
}

std::string NodeContainer::GetNodeName() const
{
    return node_name;
}

int64_t NodeContainer::GetNodeId() const
{
    return node_id;<commit_msg>fixed essential bug in node container<commit_after>#include "NodeContainer.h"

namespace ros2_components {


NodeContainer::NodeContainer(rclcpp::node::Node::SharedPtr _ros_node, int64_t _node_id, std::string _name):
    ros_node(_ros_node), node_id(_node_id), node_name(_name)
{

}

NodeContainer::~NodeContainer()
{
    abort = true;
    if(spinThread)
        spinThread->join();
}

void NodeContainer::Spin(std::chrono::nanoseconds timeout)
{
    if(isSpinning)
        throw AlreadySpinningException();
    isSpinning = true;
    if(timeout == std::chrono::nanoseconds(-1))
        rclcpp::spin_some(ros_node);
    else
    {
        executor.add_node(ros_node);
        executor.spin_once(timeout);
        executor.remove_node(ros_node);

    }
    isSpinning = false;
}

void NodeContainer::SpinAsync()
{
    if(isSpinning)
        throw AlreadySpinningException();
    auto async_spin = [&]()
    {
        isSpinning = true;
        rclcpp::WallRate loopRate(this->loop_rate);
        while(!abort && rclcpp::ok())
        {
            rclcpp::spin_some(ros_node);
            loopRate.sleep();

        }
        isSpinning = false;
        isSpinningAsync = false;
    };

    spinThread = std::make_shared<std::thread>(async_spin);
    this->isSpinningAsync = true;
}

rclcpp::node::Node::SharedPtr NodeContainer::GetRosNode()
{
    return ros_node;
}

bool NodeContainer::GetIsSpinning() const
{
    return isSpinning;
}

bool NodeContainer::GetIsSpinningAsync() const
{
    return isSpinningAsync;
}

int NodeContainer::GetLoopRate() const
{
    return loop_rate;
}

void NodeContainer::SetLoopRate(int value)
{
    loop_rate = value;
}

std::string NodeContainer::GetNodeName() const
{
    //TODO difference between name and real node name!
    return ros_node->get_name();
}

int64_t NodeContainer::GetNodeId() const
{
    return node_id;
{'fraction_non_alphanumeric': 0.12451684152401987, 'fraction_numerical': 0.0033130866924351186, 'mean_word_length': 3.5687263556116013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7375689', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1198, 'n_words': 196}