MessageTopicRegistry.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QDir>
00020 #include <QMutexLocker>
00021 
00022 #include <ros/master.h>
00023 
00024 #include "rqt_multiplot/MessageTopicRegistry.h"
00025 
00026 namespace rqt_multiplot {
00027 
00028 /*****************************************************************************/
00029 /* Static Initializations                                                    */
00030 /*****************************************************************************/
00031 
00032 MessageTopicRegistry::Impl MessageTopicRegistry::impl_;
00033 
00034 /*****************************************************************************/
00035 /* Constructors and Destructor                                               */
00036 /*****************************************************************************/
00037 
00038 MessageTopicRegistry::MessageTopicRegistry(QObject* parent) :
00039   QObject(parent) {
00040   connect(&impl_, SIGNAL(started()), this, SLOT(threadStarted()));
00041   connect(&impl_, SIGNAL(finished()), this, SLOT(threadFinished()));
00042 }
00043 
00044 MessageTopicRegistry::~MessageTopicRegistry() {
00045 }
00046 
00047 MessageTopicRegistry::Impl::Impl(QObject* parent) :
00048   QThread(parent) {
00049 }
00050 
00051 MessageTopicRegistry::Impl::~Impl() {
00052   terminate();
00053   wait();
00054 }
00055 
00056 /*****************************************************************************/
00057 /* Accessors                                                                 */
00058 /*****************************************************************************/
00059 
00060 QMap<QString, QString> MessageTopicRegistry::getTopics() const {
00061   QMutexLocker lock(&impl_.mutex_);
00062   
00063   return impl_.topics_;
00064 }
00065 
00066 bool MessageTopicRegistry::isUpdating() const {
00067   return impl_.isRunning();
00068 }
00069 
00070 bool MessageTopicRegistry::isEmpty() const {
00071   QMutexLocker lock(&impl_.mutex_);
00072   
00073   return impl_.topics_.isEmpty();
00074 }
00075 
00076 /*****************************************************************************/
00077 /* Methods                                                                   */
00078 /*****************************************************************************/
00079 
00080 void MessageTopicRegistry::update() {
00081   impl_.start();
00082 }
00083 
00084 void MessageTopicRegistry::Impl::run() {
00085   std::vector<ros::master::TopicInfo> topics;
00086 
00087   mutex_.lock();
00088   topics_.clear();
00089   mutex_.unlock();
00090   
00091   if (ros::master::getTopics(topics)) {
00092     for (size_t i = 0; i < topics.size(); ++i) {
00093       QString topic = QString::fromStdString(topics[i].name);
00094       QString type = QString::fromStdString(topics[i].datatype);
00095       
00096       topics_[topic] = type;
00097     }
00098   }
00099 }
00100 
00101 /*****************************************************************************/
00102 /* Slots                                                                     */
00103 /*****************************************************************************/
00104 
00105 void MessageTopicRegistry::threadStarted() {
00106   emit updateStarted();
00107 }
00108   
00109 void MessageTopicRegistry::threadFinished() {
00110   emit updateFinished();
00111 }
00112   
00113 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11