node_click_handler.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2016, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 //
29 // *****************************************************************************
30 
31 #ifndef SWRI_CONSOLE_NODE_CLICK_HANDLER_H
32 #define SWRI_CONSOLE_NODE_CLICK_HANDLER_H
33 
34 #include <vector>
35 
36 #include <boost/thread.hpp>
37 
38 #include <QContextMenuEvent>
39 #include <QObject>
40 #include <QEvent>
41 #include <QFuture>
42 #include <QListView>
43 #include <QMenu>
44 
45 #include <ros/ros.h>
46 #include <ros/service_client.h>
47 
48 namespace swri_console
49 {
50  class NodeClickHandler : public QObject
51  {
52  Q_OBJECT
53 
54  public Q_SLOTS:
55  void logLevelClicked();
56 
57  protected:
58  bool eventFilter(QObject* obj, QEvent* event);
59 
60  private:
64  template <class T> void callServiceWorker(ros::ServiceClient& client, T* service, bool* success)
65  {
66  *success = client.call(*service);
67  }
68 
82  template <class T> bool callService(ros::ServiceClient& client, T& service, int timeout_secs = 5)
83  {
84  bool success = false;
85  boost::thread svc_thread(&NodeClickHandler::callServiceWorker<T>, this, client, &service, &success);
86 
87  if (svc_thread.try_join_for(boost::chrono::seconds(timeout_secs))) {
88  return success;
89  }
90  svc_thread.interrupt();
91  return false;
92  }
93 
94  bool showContextMenu(QListView* list, QContextMenuEvent* event);
95  QMenu* createMenu(const QString& logger_name, const QString& current_level);
96 
98  std::string node_name_;
99  std::vector<std::string> all_loggers_;
100 
101  static const std::string ALL_LOGGERS;
102  static const std::string GET_LOGGERS_SVC;
103  static const std::string SET_LOGGER_LEVEL_SVC;
104  };
105 }
106 
107 #endif //SWRI_CONSOLE_NODE_CLICK_HANDLER_H
bool callService(ros::ServiceClient &client, T &service, int timeout_secs=5)
bool call(MReq &req, MRes &res)
bool showContextMenu(QListView *list, QContextMenuEvent *event)
void callServiceWorker(ros::ServiceClient &client, T *service, bool *success)
QMenu * createMenu(const QString &logger_name, const QString &current_level)
bool eventFilter(QObject *obj, QEvent *event)
static const std::string SET_LOGGER_LEVEL_SVC
static const std::string ALL_LOGGERS
std::vector< std::string > all_loggers_
static const std::string GET_LOGGERS_SVC


swri_console
Author(s):
autogenerated on Wed Jun 5 2019 21:25:59