MessageTypeRegistry.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/package.h>
00023 
00024 #include "rqt_multiplot/MessageTypeRegistry.h"
00025 
00026 namespace rqt_multiplot {
00027 
00028 /*****************************************************************************/
00029 /* Static Initializations                                                    */
00030 /*****************************************************************************/
00031 
00032 MessageTypeRegistry::Impl MessageTypeRegistry::impl_;
00033 
00034 /*****************************************************************************/
00035 /* Constructors and Destructor                                               */
00036 /*****************************************************************************/
00037 
00038 MessageTypeRegistry::MessageTypeRegistry(QObject* parent) :
00039   QObject(parent) {
00040   connect(&impl_, SIGNAL(started()), this, SLOT(threadStarted()));
00041   connect(&impl_, SIGNAL(finished()), this, SLOT(threadFinished()));
00042 }
00043 
00044 MessageTypeRegistry::~MessageTypeRegistry() {
00045 }
00046 
00047 MessageTypeRegistry::Impl::Impl(QObject* parent) :
00048   QThread(parent) {
00049 }
00050 
00051 MessageTypeRegistry::Impl::~Impl() {
00052   terminate();
00053   wait();
00054 }
00055 
00056 /*****************************************************************************/
00057 /* Accessors                                                                 */
00058 /*****************************************************************************/
00059 
00060 QList<QString> MessageTypeRegistry::getTypes() const {
00061   QMutexLocker lock(&impl_.mutex_);
00062   
00063   return impl_.types_;
00064 }
00065 
00066 bool MessageTypeRegistry::isUpdating() const {
00067   return impl_.isRunning();
00068 }
00069 
00070 bool MessageTypeRegistry::isEmpty() const {
00071   QMutexLocker lock(&impl_.mutex_);
00072   
00073   return impl_.types_.isEmpty();
00074 }
00075 
00076 /*****************************************************************************/
00077 /* Methods                                                                   */
00078 /*****************************************************************************/
00079 
00080 void MessageTypeRegistry::update() {
00081   impl_.start();
00082 }
00083 
00084 void MessageTypeRegistry::wait() {
00085   impl_.wait();
00086 }
00087 
00088 void MessageTypeRegistry::Impl::run() {
00089   std::vector<std::string> packages;
00090   
00091   mutex_.lock();
00092   types_.clear();
00093   mutex_.unlock();
00094   
00095   if (ros::package::getAll(packages)) {
00096     for (size_t i = 0; i < packages.size(); ++i) {
00097       QString package = QString::fromStdString(packages[i]);
00098       QDir directory(QString::fromStdString(ros::package::
00099         getPath(packages[i]))+"/msg");
00100 
00101       if (directory.exists()) {
00102         QList<QString> filters;
00103         filters.append("*.msg");
00104         
00105         QFileInfoList entries = directory.entryInfoList(filters,
00106           QDir::Files | QDir::Readable);
00107         
00108         for (QFileInfoList::iterator it = entries.begin(); it !=
00109             entries.end(); ++it) {
00110           mutex_.lock();
00111           types_.append(package+"/"+it->baseName());
00112           mutex_.unlock();
00113         }
00114       }
00115     }
00116   }
00117 }
00118 
00119 /*****************************************************************************/
00120 /* Slots                                                                     */
00121 /*****************************************************************************/
00122 
00123 void MessageTypeRegistry::threadStarted() {
00124   emit updateStarted();
00125 }
00126   
00127 void MessageTypeRegistry::threadFinished() {
00128   emit updateFinished();
00129 }
00130   
00131 }


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