BagQuery.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 <vector>
00020 
00021 #include <QApplication>
00022 
00023 #include <rosbag/message_instance.h>
00024 
00025 #include <variant_topic_tools/DataTypeRegistry.h>
00026 #include <variant_topic_tools/Message.h>
00027 #include <variant_topic_tools/MessageDefinition.h>
00028 #include <variant_topic_tools/MessageType.h>
00029 #include <variant_topic_tools/MessageVariant.h>
00030 
00031 #include <rqt_multiplot/DataTypeRegistry.h>
00032 #include <rqt_multiplot/MessageEvent.h>
00033 
00034 #include "rqt_multiplot/BagQuery.h"
00035 
00036 namespace rqt_multiplot {
00037 
00038 /*****************************************************************************/
00039 /* Constructors and Destructor                                               */
00040 /*****************************************************************************/
00041 
00042 BagQuery::BagQuery(QObject* parent) :
00043   QObject(parent) {
00044 }
00045 
00046 BagQuery::~BagQuery() {
00047 }
00048 
00049 /*****************************************************************************/
00050 /* Methods                                                                   */
00051 /*****************************************************************************/
00052 
00053 bool BagQuery::event(QEvent* event) {
00054   if (event->type() == MessageEvent::Type) {
00055     MessageEvent* messageEvent = static_cast<MessageEvent*>(event);
00056 
00057     emit messageRead(messageEvent->getTopic(), messageEvent->
00058       getMessage());
00059     
00060     return true;
00061   }
00062   
00063   return QObject::event(event);
00064 }
00065 
00066 void BagQuery::callback(const rosbag::MessageInstance& instance) {
00067   Message message;
00068 
00069   if (!dataType_.isValid()) {
00070     DataTypeRegistry::mutex_.lock();
00071     
00072     variant_topic_tools::DataTypeRegistry registry;
00073     dataType_ = registry.getDataType(instance.getDataType());
00074 
00075     if (!dataType_) {
00076       variant_topic_tools::MessageType messageType(instance.getDataType(),
00077         instance.getMD5Sum(), instance.getMessageDefinition());
00078       variant_topic_tools::MessageDefinition messageDefinition(
00079         messageType);
00080       
00081       dataType_ = messageDefinition.getMessageDataType();
00082     }
00083     
00084     DataTypeRegistry::mutex_.unlock();
00085     
00086     serializer_ = dataType_.createSerializer();
00087   }
00088 
00089   std::vector<uint8_t> data(instance.size());
00090   ros::serialization::OStream outputStream(data.data(), data.size());
00091   instance.write(outputStream);
00092 
00093   variant_topic_tools::MessageVariant variant = dataType_.createVariant();
00094   ros::serialization::IStream inputStream(data.data(), data.size());
00095   
00096   serializer_.deserialize(inputStream, variant);
00097   
00098   message.setReceiptTime(instance.getTime());
00099   message.setVariant(variant);
00100   
00101   MessageEvent* messageEvent = new MessageEvent(QString::fromStdString(
00102     instance.getTopic()), message);
00103   
00104   QApplication::postEvent(this, messageEvent);
00105 }
00106 
00107 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
00108 void BagQuery::disconnectNotify(const QMetaMethod& signal) {
00109   if (!receivers(QMetaObject::normalizedSignature(
00110       SIGNAL(messageReceived(const QString&, const Message&))))) {
00111     emit aboutToBeDestroyed();
00112 
00113     deleteLater();
00114   }
00115 }
00116 #else
00117 void BagQuery::disconnectNotify(const char* signal) {
00118   if (!receivers(QMetaObject::normalizedSignature(
00119       SIGNAL(messageReceived(const QString&, const Message&))))) {
00120     emit aboutToBeDestroyed();
00121   
00122     deleteLater();
00123   }
00124 }
00125 #endif
00126 
00127 }


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