PackageRegistry.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 <QDir>
20 #include <QMutexLocker>
21 
22 #include <ros/package.h>
23 
25 
26 namespace rqt_multiplot {
27 
28 /*****************************************************************************/
29 /* Static Initializations */
30 /*****************************************************************************/
31 
32 PackageRegistry::Impl PackageRegistry::impl_;
33 
34 /*****************************************************************************/
35 /* Constructors and Destructor */
36 /*****************************************************************************/
37 
39  QObject(parent) {
40  connect(&impl_, SIGNAL(started()), this, SLOT(threadStarted()));
41  connect(&impl_, SIGNAL(finished()), this, SLOT(threadFinished()));
42 }
43 
45 }
46 
47 PackageRegistry::Impl::Impl(QObject* parent) :
48  QThread(parent) {
49 }
50 
52  terminate();
53  wait();
54 }
55 
56 /*****************************************************************************/
57 /* Accessors */
58 /*****************************************************************************/
59 
60 QMap<QString, QString> PackageRegistry::getPackages() const {
61  QMutexLocker lock(&impl_.mutex_);
62 
63  return impl_.packages_;
64 }
65 
67  return impl_.isRunning();
68 }
69 
71  QMutexLocker lock(&impl_.mutex_);
72 
73  return impl_.packages_.isEmpty();
74 }
75 
76 /*****************************************************************************/
77 /* Methods */
78 /*****************************************************************************/
79 
81  impl_.start();
82 }
83 
85  impl_.wait();
86 }
87 
89  std::vector<std::string> packages;
90 
91  mutex_.lock();
92  packages_.clear();
93  mutex_.unlock();
94 
95  if (ros::package::getAll(packages)) {
96  for (size_t i = 0; i < packages.size(); ++i) {
97  QString package = QString::fromStdString(packages[i]);
98  QDir directory(QString::fromStdString(ros::package::
99  getPath(packages[i])));
100 
101  if (directory.exists()) {
102  mutex_.lock();
103  packages_[package] = directory.absolutePath();
104  mutex_.unlock();
105  }
106  }
107  }
108 }
109 
110 /*****************************************************************************/
111 /* Slots */
112 /*****************************************************************************/
113 
115  emit updateStarted();
116 }
117 
119  emit updateFinished();
120 }
121 
122 }
ROSLIB_DECL bool getAll(V_string &packages)
string package
QMap< QString, QString > packages_
PackageRegistry(QObject *parent=0)
ROSLIB_DECL std::string getPath(const std::string &package_name)
QMap< QString, QString > getPackages() const


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