diff --git a/rqt_gui_cpp/CMakeLists.txt b/rqt_gui_cpp/CMakeLists.txt index 2b039be9..11cabb2c 100644 --- a/rqt_gui_cpp/CMakeLists.txt +++ b/rqt_gui_cpp/CMakeLists.txt @@ -55,6 +55,11 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets ) +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + install( TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} diff --git a/rqt_gui_cpp/include/rqt_gui_cpp/plugin.h b/rqt_gui_cpp/include/rqt_gui_cpp/plugin.h index 1cc66608..3a606df9 100644 --- a/rqt_gui_cpp/include/rqt_gui_cpp/plugin.h +++ b/rqt_gui_cpp/include/rqt_gui_cpp/plugin.h @@ -30,54 +30,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef rqt_gui_cpp__Plugin_H -#define rqt_gui_cpp__Plugin_H +#ifndef RQT_GUI_CPP__PLUGIN_H_ +#define RQT_GUI_CPP__PLUGIN_H_ -#include -#include -#include +// *INDENT-OFF* (prevent uncrustify from adding indention below) +#warning Including header is deprecated, \ +include instead. -#include +// *INDENT-ON* +#include "./plugin.hpp" -namespace rqt_gui_cpp { - -/** - * The base class for C++ plugins which use the ROS client library. - * A plugin must not call rclcpp::init() as this is performed once by the framework. - */ -class Plugin - : public qt_gui_cpp::Plugin -{ - -public: - - Plugin() - : qt_gui_cpp::Plugin() - {} - - /** - * Shutdown and clean up the plugin before unloading. - * I.e. unregister subscribers and stop timers. - */ - virtual void shutdownPlugin() - {} - - virtual void passInNode(std::shared_ptr node) - { - node_ = node; - } - -protected: - - rclcpp::Node::SharedPtr node_; - -private: - - void onInit() - {} - -}; - -} // namespace - -#endif // rqt_gui_cpp__Plugin_H +#endif // RQT_GUI_CPP__PLUGIN_H_ diff --git a/rqt_gui_cpp/include/rqt_gui_cpp/plugin.hpp b/rqt_gui_cpp/include/rqt_gui_cpp/plugin.hpp new file mode 100644 index 00000000..f2200654 --- /dev/null +++ b/rqt_gui_cpp/include/rqt_gui_cpp/plugin.hpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011, Dirk Thomas, TU Darmstadt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the TU Darmstadt nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RQT_GUI_CPP__PLUGIN_HPP_ +#define RQT_GUI_CPP__PLUGIN_HPP_ + +#include + +#include +#include +#include + +#include + +namespace rqt_gui_cpp +{ + +/** + * The base class for C++ plugins which use the ROS client library. + * A plugin must not call rclcpp::init() as this is performed once by the framework. + */ +class Plugin + : public qt_gui_cpp::Plugin +{ +public: + Plugin() + : qt_gui_cpp::Plugin() + {} + + /** + * Shutdown and clean up the plugin before unloading. + * I.e. unregister subscribers and stop timers. + */ + virtual void shutdownPlugin() + {} + + virtual void passInNode(std::shared_ptr node) + { + node_ = node; + } + +protected: + rclcpp::Node::SharedPtr node_; + +private: + void onInit() + {} +}; +} // namespace rqt_gui_cpp + +#endif // RQT_GUI_CPP__PLUGIN_HPP_ diff --git a/rqt_gui_cpp/package.xml b/rqt_gui_cpp/package.xml index 10996a47..649680fc 100644 --- a/rqt_gui_cpp/package.xml +++ b/rqt_gui_cpp/package.xml @@ -22,6 +22,9 @@ qtbase5-dev qt_gui_cpp + ament_lint_auto + ament_lint_common + ament_cmake diff --git a/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp b/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp index e36e32b1..5ff0cc90 100644 --- a/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp +++ b/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp @@ -30,26 +30,27 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "nodelet_plugin_provider.h" - -#include "roscpp_plugin_provider.h" +#include "nodelet_plugin_provider.hpp" #include #include #include -namespace rqt_gui_cpp { +#include "roscpp_plugin_provider.hpp" -NodeletPluginProvider::NodeletPluginProvider(const QString& export_tag, const QString& base_class_type) - : qt_gui_cpp::RosPluginlibPluginProvider(export_tag, base_class_type) +namespace rqt_gui_cpp +{ +NodeletPluginProvider::NodeletPluginProvider( + const QString & export_tag, + const QString & base_class_type) +: qt_gui_cpp::RosPluginlibPluginProvider(export_tag, base_class_type) , loader_initialized_(false) , ros_spin_thread_(0) {} NodeletPluginProvider::~NodeletPluginProvider() { - if (ros_spin_thread_ != 0) - { + if (ros_spin_thread_ != 0) { ros_spin_thread_->abort = true; ros_spin_thread_->exec_.remove_node(node_); ros_spin_thread_->wait(); @@ -58,10 +59,9 @@ NodeletPluginProvider::~NodeletPluginProvider() } } -void NodeletPluginProvider::unload(void* instance) +void NodeletPluginProvider::unload(void * instance) { - if (!instances_.contains(instance)) - { + if (!instances_.contains(instance)) { qCritical("rqt_gui_cpp::NodeletPluginProvider::unload() instance not found"); return; } @@ -73,14 +73,11 @@ void NodeletPluginProvider::unload(void* instance) void NodeletPluginProvider::init_loader() { - - if (!loader_initialized_) - { + if (!loader_initialized_) { loader_initialized_ = true; // spawn ros spin thread - if (ros_spin_thread_ == 0) - { + if (ros_spin_thread_ == 0) { ros_spin_thread_ = new RosSpinThread(this); ros_spin_thread_->start(); } @@ -91,26 +88,26 @@ void NodeletPluginProvider::init_loader() // Initialize a node for execution to be shared by cpp plugins node_ = rclcpp::Node::make_shared(name.str().c_str()); // Add our node to the executor for execution - if (ros_spin_thread_) - { + if (ros_spin_thread_) { ros_spin_thread_->exec_.add_node(node_); - } - else - { + } else { qWarning("rqt_gui_cpp::NodeletPluginProvider.init_loader: ros_spin_thread_ not initialized"); } } - } -std::shared_ptr NodeletPluginProvider::create_plugin(const std::string& lookup_name, qt_gui_cpp::PluginContext* plugin_context) +std::shared_ptr NodeletPluginProvider::create_plugin( + const std::string & lookup_name, + qt_gui_cpp::PluginContext * plugin_context) { init_loader(); - std::string nodelet_name = lookup_name + "_" + QString::number(plugin_context->serialNumber()).toStdString(); + std::string nodelet_name = lookup_name + "_" + + QString::number(plugin_context->serialNumber()).toStdString(); instance_.reset(); - instance_ = qt_gui_cpp::RosPluginlibPluginProvider::create_plugin(lookup_name); + instance_ = + qt_gui_cpp::RosPluginlibPluginProvider::create_plugin(lookup_name); instance_->passInNode(node_); instances_[&*instance_] = nodelet_name.c_str(); @@ -120,22 +117,24 @@ std::shared_ptr NodeletPluginProvider::create_plugin(const std::string& } -void NodeletPluginProvider::init_plugin(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context, qt_gui_cpp::Plugin* plugin) +void NodeletPluginProvider::init_plugin( + const QString & plugin_id, + qt_gui_cpp::PluginContext * plugin_context, qt_gui_cpp::Plugin * plugin) { qDebug("rqt_gui_cpp::NodeletPluginProvider::init_plugin()"); init_loader(); - rqt_gui_cpp::Plugin* rqt_plugin = dynamic_cast(plugin); - if (!rqt_plugin) - { + rqt_gui_cpp::Plugin * rqt_plugin = dynamic_cast(plugin); + if (!rqt_plugin) { throw std::runtime_error("plugin is not a rqt_plugin::Plugin"); } - qt_gui_cpp::RosPluginlibPluginProvider::init_plugin(plugin_id, plugin_context, plugin); + qt_gui_cpp::RosPluginlibPluginProvider::init_plugin(plugin_id, + plugin_context, plugin); } -NodeletPluginProvider::RosSpinThread::RosSpinThread(QObject* parent) - : QThread(parent) +NodeletPluginProvider::RosSpinThread::RosSpinThread(QObject * parent) +: QThread(parent) , abort(false) {} @@ -144,12 +143,9 @@ NodeletPluginProvider::RosSpinThread::~RosSpinThread() void NodeletPluginProvider::RosSpinThread::run() { - while (!abort) - { + while (!abort) { // Spin the executor exec_.spin_once(); } } - - -} +} // namespace rqt_gui_cpp diff --git a/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.h b/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.hpp similarity index 75% rename from rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.h rename to rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.hpp index 68f2e854..ce4612e9 100644 --- a/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.h +++ b/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.hpp @@ -30,48 +30,47 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef rqt_gui_cpp__NodeletPluginProvider_H -#define rqt_gui_cpp__NodeletPluginProvider_H +#ifndef RQT_GUI_CPP__NODELET_PLUGIN_PROVIDER_HPP_ +#define RQT_GUI_CPP__NODELET_PLUGIN_PROVIDER_HPP_ +#include +#include +#include + +#include #include -#include +#include #include -#include - -#include -#include -#include - -namespace rqt_gui_cpp { - -class RosCppPluginProvider; +namespace rqt_gui_cpp +{ class NodeletPluginProvider : public qt_gui_cpp::RosPluginlibPluginProvider { - public: - - NodeletPluginProvider(const QString& export_tag, const QString& base_class_type); + NodeletPluginProvider(const QString & export_tag, const QString & base_class_type); virtual ~NodeletPluginProvider(); - virtual void unload(void* instance); + virtual void unload(void * instance); protected: - void init_loader(); - virtual std::shared_ptr create_plugin(const std::string& lookup_name, qt_gui_cpp::PluginContext* plugin_context); + virtual std::shared_ptr create_plugin( + const std::string & lookup_name, + qt_gui_cpp::PluginContext * plugin_context); - virtual void init_plugin(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context, qt_gui_cpp::Plugin* plugin); + virtual void init_plugin( + const QString & plugin_id, qt_gui_cpp::PluginContext * plugin_context, + qt_gui_cpp::Plugin * plugin); std::shared_ptr instance_; - QMap instances_; + QMap instances_; bool loader_initialized_; @@ -82,8 +81,8 @@ class NodeletPluginProvider class RosSpinThread : public QThread { - public: - RosSpinThread(QObject* parent = 0); +public: + explicit RosSpinThread(QObject * parent = 0); virtual ~RosSpinThread(); void run(); bool abort; @@ -92,10 +91,7 @@ class NodeletPluginProvider rclcpp::executors::MultiThreadedExecutor exec_; }; - RosSpinThread* ros_spin_thread_; - + RosSpinThread * ros_spin_thread_; }; - -} - -#endif // rqt_gui_cpp__NodeletPluginProvider_H +} // namespace rqt_gui_cpp +#endif // RQT_GUI_CPP__NODELET_PLUGIN_PROVIDER_HPP_ diff --git a/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.cpp b/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.cpp index 42af03fb..b20e2391 100644 --- a/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.cpp +++ b/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.cpp @@ -30,52 +30,56 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "roscpp_plugin_provider.h" +#include "roscpp_plugin_provider.hpp" -#include "nodelet_plugin_provider.h" -#include +#include + +#include + +#include "nodelet_plugin_provider.hpp" +#include #include #include #include -#include -#include - -namespace rqt_gui_cpp { +namespace rqt_gui_cpp +{ RosCppPluginProvider::RosCppPluginProvider() - : qt_gui_cpp::CompositePluginProvider() +: qt_gui_cpp::CompositePluginProvider() , rclcpp_initialized_(false) { - if (rclcpp::ok()) - { + if (rclcpp::ok()) { rclcpp_initialized_ = true; } init_rclcpp(); - QList plugin_providers; + QList plugin_providers; plugin_providers.append(new NodeletPluginProvider("rqt_gui", "rqt_gui_cpp::Plugin")); set_plugin_providers(plugin_providers); } RosCppPluginProvider::~RosCppPluginProvider() { - if (rclcpp::ok()) - { + if (rclcpp::ok()) { rclcpp::shutdown(); } } -void* RosCppPluginProvider::load(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context) +void * RosCppPluginProvider::load( + const QString & plugin_id, + qt_gui_cpp::PluginContext * plugin_context) { qDebug("RosCppPluginProvider::load(%s)", plugin_id.toStdString().c_str()); init_rclcpp(); return qt_gui_cpp::CompositePluginProvider::load(plugin_id, plugin_context); } -qt_gui_cpp::Plugin* RosCppPluginProvider::load_plugin(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context) +qt_gui_cpp::Plugin * RosCppPluginProvider::load_plugin( + const QString & plugin_id, + qt_gui_cpp::PluginContext * plugin_context) { qDebug("RosCppPluginProvider::load_plugin(%s)", plugin_id.toStdString().c_str()); init_rclcpp(); @@ -85,10 +89,9 @@ qt_gui_cpp::Plugin* RosCppPluginProvider::load_plugin(const QString& plugin_id, void RosCppPluginProvider::init_rclcpp() { // initialize ROS node once - if (!rclcpp_initialized_) - { + if (!rclcpp_initialized_) { int argc = 0; - char** argv = 0; + char ** argv = 0; // 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). @@ -101,7 +104,5 @@ void RosCppPluginProvider::init_rclcpp() rclcpp_initialized_ = true; } } - -} - +} // namespace rqt_gui_cpp PLUGINLIB_EXPORT_CLASS(rqt_gui_cpp::RosCppPluginProvider, qt_gui_cpp::PluginProvider) diff --git a/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.h b/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.hpp similarity index 82% rename from rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.h rename to rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.hpp index b6e9edb7..175e53e7 100644 --- a/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.h +++ b/rqt_gui_cpp/src/rqt_gui_cpp/roscpp_plugin_provider.hpp @@ -30,40 +30,37 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef rqt_gui_cpp__RosCppPluginProvider_H -#define rqt_gui_cpp__RosCppPluginProvider_H - -#include +#ifndef RQT_GUI_CPP__ROSCPP_PLUGIN_PROVIDER_HPP_ +#define RQT_GUI_CPP__ROSCPP_PLUGIN_PROVIDER_HPP_ #include #include #include -namespace rqt_gui_cpp { +#include + +namespace rqt_gui_cpp +{ class RosCppPluginProvider : public qt_gui_cpp::CompositePluginProvider { - public: - RosCppPluginProvider(); virtual ~RosCppPluginProvider(); - virtual void* load(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context); + virtual void * load(const QString & plugin_id, qt_gui_cpp::PluginContext * plugin_context); - virtual qt_gui_cpp::Plugin* load_plugin(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context); + virtual qt_gui_cpp::Plugin * load_plugin( + const QString & plugin_id, + qt_gui_cpp::PluginContext * plugin_context); protected: - void init_rclcpp(); bool rclcpp_initialized_; - }; - -} - -#endif // rqt_gui_cpp__RosCppPluginProvider_H +} // namespace rqt_gui_cpp +#endif // RQT_GUI_CPP__ROSCPP_PLUGIN_PROVIDER_HPP_