BagQuery.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <vector>
20 
21 #include <QApplication>
22 
24 
25 #include <variant_topic_tools/DataTypeRegistry.h>
26 #include <variant_topic_tools/Message.h>
27 #include <variant_topic_tools/MessageDefinition.h>
28 #include <variant_topic_tools/MessageType.h>
29 #include <variant_topic_tools/MessageVariant.h>
30 
33 
34 #include "rqt_multiplot/BagQuery.h"
35 
36 namespace rqt_multiplot {
37 
38 /*****************************************************************************/
39 /* Constructors and Destructor */
40 /*****************************************************************************/
41 
42 BagQuery::BagQuery(QObject* parent) :
43  QObject(parent) {
44 }
45 
47 }
48 
49 /*****************************************************************************/
50 /* Methods */
51 /*****************************************************************************/
52 
53 bool BagQuery::event(QEvent* event) {
54  if (event->type() == MessageEvent::Type) {
55  MessageEvent* messageEvent = static_cast<MessageEvent*>(event);
56 
57  emit messageRead(messageEvent->getTopic(), messageEvent->
58  getMessage());
59 
60  return true;
61  }
62 
63  return QObject::event(event);
64 }
65 
67  Message message;
68 
69  if (!dataType_.isValid()) {
71 
72  variant_topic_tools::DataTypeRegistry registry;
73  dataType_ = registry.getDataType(instance.getDataType());
74 
75  if (!dataType_) {
76  variant_topic_tools::MessageType messageType(instance.getDataType(),
77  instance.getMD5Sum(), instance.getMessageDefinition());
78  variant_topic_tools::MessageDefinition messageDefinition(
79  messageType);
80 
81  dataType_ = messageDefinition.getMessageDataType();
82  }
83 
84  DataTypeRegistry::mutex_.unlock();
85 
86  serializer_ = dataType_.createSerializer();
87  }
88 
89  std::vector<uint8_t> data(instance.size());
90  ros::serialization::OStream outputStream(data.data(), data.size());
91  instance.write(outputStream);
92 
93  variant_topic_tools::MessageVariant variant = dataType_.createVariant();
94  ros::serialization::IStream inputStream(data.data(), data.size());
95 
96  serializer_.deserialize(inputStream, variant);
97 
98  message.setReceiptTime(instance.getTime());
99  message.setVariant(variant);
100 
101  MessageEvent* messageEvent = new MessageEvent(QString::fromStdString(
102  instance.getTopic()), message);
103 
104  QApplication::postEvent(this, messageEvent);
105 }
106 
107 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
108 void BagQuery::disconnectNotify(const QMetaMethod& signal) {
109  if (!receivers(QMetaObject::normalizedSignature(
110  SIGNAL(messageReceived(const QString&, const Message&))))) {
111  emit aboutToBeDestroyed();
112 
113  deleteLater();
114  }
115 }
116 #else
117 void BagQuery::disconnectNotify(const char* signal) {
118  if (!receivers(QMetaObject::normalizedSignature(
119  SIGNAL(messageReceived(const QString&, const Message&))))) {
120  emit aboutToBeDestroyed();
121 
122  deleteLater();
123  }
124 }
125 #endif
126 
127 }
void callback(const rosbag::MessageInstance &instance)
Definition: BagQuery.cpp:66
BagQuery(QObject *parent=0)
Definition: BagQuery.cpp:42
const QString & getTopic() const
std::string const & getMD5Sum() const
void messageRead(const QString &topic, const Message &message)
void disconnectNotify(const QMetaMethod &signal)
Definition: BagQuery.cpp:108
bool event(QEvent *event)
Definition: BagQuery.cpp:53
ros::Time const & getTime() const
static const QEvent::Type Type
Definition: MessageEvent.h:31
uint32_t size() const
void setReceiptTime(const ros::Time &receiptTime)
Definition: Message.cpp:42
std::string const & getMessageDefinition() const
std::string const & getTopic() const
std::string const & getDataType() const
void setVariant(const variant_topic_tools::MessageVariant &variant)
Definition: Message.cpp:50
void write(Stream &stream) const
variant_topic_tools::MessageDataType dataType_
Definition: BagQuery.h:50
variant_topic_tools::MessageSerializer serializer_
Definition: BagQuery.h:51


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44