Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions rqt_gui_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ cmake_minimum_required(VERSION 3.20)
project(rqt_gui_cpp)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros_core REQUIRED)

if(WIN32)
message(STATUS "rqt_gui_cpp is not yet supported on Windows. Package will not be built.")
ament_package()
return()
endif()

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# The C++ standard (C++20) is provided by the
# ament_cmake_ros_core::ament_ros_defaults interface target linked below.

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -fPIC)
Expand Down Expand Up @@ -59,6 +57,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
)

target_link_libraries(${PROJECT_NAME} PRIVATE
ament_cmake_ros_core::ament_ros_defaults
pluginlib::pluginlib
Qt${QT_VERSION_MAJOR}::Widgets
)
Expand Down
6 changes: 2 additions & 4 deletions rqt_gui_cpp/include/rqt_gui_cpp/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ class Plugin
: public qt_gui_cpp::Plugin
{
public:
Plugin()
: qt_gui_cpp::Plugin()
{}
Plugin() = default;

/**
* Shutdown and clean up the plugin before unloading.
* I.e. unregister subscribers and stop timers.
*/
virtual void shutdownPlugin()
void shutdownPlugin() override
{}

virtual void passInNode(std::shared_ptr<rclcpp::Node> node)
Expand Down
1 change: 1 addition & 0 deletions rqt_gui_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<author email="michael.jeronimo@openrobotics.org">Michael Jeronimo</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_ros_core</buildtool_depend>

<depend>pluginlib</depend>
<depend>rclcpp</depend>
Expand Down
20 changes: 8 additions & 12 deletions rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "nodelet_plugin_provider.hpp"

#include <unistd.h>
#include <format>
#include <memory>
#include <stdexcept>
#include <string>
Expand All @@ -46,17 +47,17 @@ NodeletPluginProvider::NodeletPluginProvider(
const QString & base_class_type)
: qt_gui_cpp::RosPluginlibPluginProvider<rqt_gui_cpp::Plugin>(export_tag, base_class_type)
, loader_initialized_(false)
, ros_spin_thread_(0)
, ros_spin_thread_(nullptr)
{}

NodeletPluginProvider::~NodeletPluginProvider()
{
if (ros_spin_thread_ != 0) {
if (ros_spin_thread_ != nullptr) {
ros_spin_thread_->abort = true;
ros_spin_thread_->exec_.remove_node(node_);
ros_spin_thread_->wait();
ros_spin_thread_->deleteLater();
ros_spin_thread_ = 0;
ros_spin_thread_ = nullptr;
}
}

Expand All @@ -76,16 +77,13 @@ void NodeletPluginProvider::init_loader()
loader_initialized_ = true;

// spawn ros spin thread
if (ros_spin_thread_ == 0) {
if (ros_spin_thread_ == nullptr) {
ros_spin_thread_ = new RosSpinThread(this);
ros_spin_thread_->start();
}

std::stringstream name;
name << "rqt_gui_cpp_node_";
name << getpid();
// Initialize a node for execution to be shared by cpp plugins
node_ = rclcpp::Node::make_shared(name.str().c_str());
node_ = rclcpp::Node::make_shared(std::format("rqt_gui_cpp_node_{}", getpid()));
// Add our node to the executor for execution
if (ros_spin_thread_) {
ros_spin_thread_->exec_.add_node(node_);
Expand All @@ -101,8 +99,7 @@ std::shared_ptr<Plugin> NodeletPluginProvider::create_plugin(
{
init_loader();

std::string nodelet_name = lookup_name + "_" +
QString::number(plugin_context->serialNumber()).toStdString();
std::string nodelet_name = std::format("{}_{}", lookup_name, plugin_context->serialNumber());
instance_.reset();

instance_ =
Expand Down Expand Up @@ -137,8 +134,7 @@ NodeletPluginProvider::RosSpinThread::RosSpinThread(QObject * parent)
, abort(false)
{}

NodeletPluginProvider::RosSpinThread::~RosSpinThread()
{}
NodeletPluginProvider::RosSpinThread::~RosSpinThread() = default;

void NodeletPluginProvider::RosSpinThread::run()
{
Expand Down
18 changes: 9 additions & 9 deletions rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ class NodeletPluginProvider
public:
NodeletPluginProvider(const QString & export_tag, const QString & base_class_type);

virtual ~NodeletPluginProvider();
~NodeletPluginProvider() override;

virtual void unload(void * instance);
void unload(void * instance) override;

protected:
void init_loader();

virtual std::shared_ptr<Plugin> create_plugin(
std::shared_ptr<Plugin> create_plugin(
const std::string & lookup_name,
qt_gui_cpp::PluginContext * plugin_context);
qt_gui_cpp::PluginContext * plugin_context) override;

virtual void init_plugin(
void init_plugin(
const QString & plugin_id, qt_gui_cpp::PluginContext * plugin_context,
qt_gui_cpp::Plugin * plugin);
qt_gui_cpp::Plugin * plugin) override;

std::shared_ptr<rqt_gui_cpp::Plugin> instance_;

Expand All @@ -82,9 +82,9 @@ class NodeletPluginProvider
: public QThread
{
public:
explicit RosSpinThread(QObject * parent = 0);
virtual ~RosSpinThread();
void run();
explicit RosSpinThread(QObject * parent = nullptr);
~RosSpinThread() override;
void run() override;
bool abort;
// Create an executor that will be responsible for execution of callbacks for a set of nodes.
// With this version, all callbacks will be called from within this thread (the main one).
Expand Down
2 changes: 1 addition & 1 deletion rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void RosCppPluginProvider::init_rclcpp()
// initialize ROS node once
if (!rclcpp_initialized_) {
int argc = 0;
char ** argv = 0;
char ** argv = nullptr;

// Initialize any global resources needed by the middleware and the client library.
// This will also parse command line arguments one day (as of Beta 1 they are not used).
Expand Down
8 changes: 4 additions & 4 deletions rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class RosCppPluginProvider
public:
RosCppPluginProvider();

virtual ~RosCppPluginProvider();
~RosCppPluginProvider() override;

virtual void * load(const QString & plugin_id, qt_gui_cpp::PluginContext * plugin_context);
void * load(const QString & plugin_id, qt_gui_cpp::PluginContext * plugin_context) override;

virtual qt_gui_cpp::Plugin * load_plugin(
qt_gui_cpp::Plugin * load_plugin(
const QString & plugin_id,
qt_gui_cpp::PluginContext * plugin_context);
qt_gui_cpp::PluginContext * plugin_context) override;

protected:
void init_rclcpp();
Expand Down