MessageDefinitionLoader.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 <QMutexLocker>
00020 
00021 #include <rqt_multiplot/DataTypeRegistry.h>
00022 
00023 #include "rqt_multiplot/MessageDefinitionLoader.h"
00024 
00025 namespace rqt_multiplot {
00026 
00027 /*****************************************************************************/
00028 /* Constructors and Destructor                                               */
00029 /*****************************************************************************/
00030 
00031 MessageDefinitionLoader::MessageDefinitionLoader(QObject* parent) :
00032   QObject(parent),
00033   impl_(this) {
00034   connect(&impl_, SIGNAL(started()), this, SLOT(threadStarted()));
00035   connect(&impl_, SIGNAL(finished()), this, SLOT(threadFinished()));
00036 }
00037 
00038 MessageDefinitionLoader::~MessageDefinitionLoader() {
00039   impl_.quit();
00040   impl_.wait();
00041 }
00042 
00043 MessageDefinitionLoader::Impl::Impl(QObject* parent) :
00044   QThread(parent) {
00045 }
00046 
00047 MessageDefinitionLoader::Impl::~Impl() {
00048   terminate();
00049   wait();
00050 }
00051 
00052 /*****************************************************************************/
00053 /* Accessors                                                                 */
00054 /*****************************************************************************/
00055 
00056 QString MessageDefinitionLoader::getType() const {
00057   QMutexLocker lock(&impl_.mutex_);
00058   
00059   return impl_.type_;
00060 }
00061 
00062 variant_topic_tools::MessageDefinition MessageDefinitionLoader::
00063     getDefinition() const {
00064   QMutexLocker lock(&impl_.mutex_);
00065   
00066   return impl_.definition_;
00067 }
00068 
00069 QString MessageDefinitionLoader::getError() const {
00070   QMutexLocker lock(&impl_.mutex_);
00071   
00072   return impl_.error_;
00073 }
00074 
00075 bool MessageDefinitionLoader::isLoading() const {
00076   return impl_.isRunning();
00077 }
00078 
00079 /*****************************************************************************/
00080 /* Methods                                                                   */
00081 /*****************************************************************************/
00082 
00083 void MessageDefinitionLoader::load(const QString& type) {
00084   impl_.wait();
00085   
00086   impl_.type_ = type;
00087   impl_.start();
00088 }
00089 
00090 void MessageDefinitionLoader::wait() {
00091   impl_.wait();
00092 }
00093 
00094 void MessageDefinitionLoader::Impl::run() {
00095   QMutexLocker lock(&mutex_);
00096   
00097   error_.clear();
00098   
00099   try {
00100     QMutexLocker lock(&DataTypeRegistry::mutex_);
00101     
00102     definition_.load(type_.toStdString());
00103   }
00104   catch (const ros::Exception& exception) {
00105     definition_.clear();
00106     error_ = QString::fromStdString(exception.what());
00107   }
00108 }
00109 
00110 /*****************************************************************************/
00111 /* Slots                                                                     */
00112 /*****************************************************************************/
00113 
00114 void MessageDefinitionLoader::threadStarted() {
00115   emit loadingStarted();
00116 }
00117   
00118 void MessageDefinitionLoader::threadFinished() {
00119   if (impl_.error_.isEmpty())
00120     emit loadingFinished();
00121   else
00122     emit loadingFailed(impl_.error_);
00123 }
00124   
00125 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02