MessageSubscriberRegistry.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 <QMetaType>
20 
22 
23 namespace rqt_multiplot {
24 
25 /*****************************************************************************/
26 /* Constructors and Destructor */
27 /*****************************************************************************/
28 
30  ros::NodeHandle& nodeHandle) :
31  MessageBroker(parent),
32  nodeHandle_(nodeHandle) {
33 }
34 
36 }
37 
38 /*****************************************************************************/
39 /* Accessors */
40 /*****************************************************************************/
41 
43  return nodeHandle_;
44 }
45 
46 /*****************************************************************************/
47 /* Methods */
48 /*****************************************************************************/
49 
50 bool MessageSubscriberRegistry::subscribe(const QString& topic,
51  QObject* receiver, const char* method, const PropertyMap& properties,
52  Qt::ConnectionType type) {
53  QMap<QString, MessageSubscriber*>::iterator it = subscribers_.find(topic);
54 
55  size_t queueSize = 100;
56  if (properties.contains(MessageSubscriber::QueueSize))
57  queueSize = properties[MessageSubscriber::QueueSize].toULongLong();
58 
59  if (it == subscribers_.end()) {
60  it = subscribers_.insert(topic, new MessageSubscriber(this,
61  getNodeHandle()));
62 
63  it.value()->setQueueSize(queueSize);
64  it.value()->setTopic(topic);
65 
66  connect(it.value(), SIGNAL(aboutToBeDestroyed()), this,
68  }
69  else if (it.value()->getQueueSize() < queueSize)
70  it.value()->setQueueSize(queueSize);
71 
72  return receiver->connect(it.value(), SIGNAL(messageReceived(const
73  QString&, const Message&)), method, type);
74 }
75 
76 bool MessageSubscriberRegistry::unsubscribe(const QString& topic, QObject*
77  receiver, const char* method) {
78  QMap<QString, MessageSubscriber*>::iterator it = subscribers_.find(topic);
79 
80  if (it != subscribers_.end()) {
81  return it.value()->disconnect(SIGNAL(messageReceived(const QString&,
82  const Message&)), receiver, method);
83  }
84  else
85  return false;
86 }
87 
88 /*****************************************************************************/
89 /* Slots */
90 /*****************************************************************************/
91 
93  for (QMap<QString, MessageSubscriber*>::iterator it = subscribers_.begin();
94  it != subscribers_.end(); ++it) {
95  if (it.value() == static_cast<MessageSubscriber*>(sender())) {
96  subscribers_.erase(it);
97  break;
98  }
99  }
100 }
101 
102 }
bool subscribe(const QString &topic, QObject *receiver, const char *method, const PropertyMap &properties=PropertyMap(), Qt::ConnectionType type=Qt::AutoConnection)
QMap< int, QVariant > PropertyMap
Definition: MessageBroker.h:33
QMap< QString, MessageSubscriber * > subscribers_
MessageSubscriberRegistry(QObject *parent=0, const ros::NodeHandle &nodeHandle=ros::NodeHandle("~"))
const ros::NodeHandle & getNodeHandle() const
bool unsubscribe(const QString &topic, QObject *receiver, const char *method=0)


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