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
swri_console::NodeClickHandler::nh_
ros::NodeHandle nh_
Definition: node_click_handler.h:97
swri_console::NodeClickHandler::ALL_LOGGERS
static const std::string ALL_LOGGERS
Definition: node_click_handler.h:101
ros.h
swri_console::NodeClickHandler::all_loggers_
std::vector< std::string > all_loggers_
Definition: node_click_handler.h:99
swri_console::NodeClickHandler::createMenu
QMenu * createMenu(const QString &logger_name, const QString &current_level)
Definition: node_click_handler.cpp:124
swri_console::NodeClickHandler::node_name_
std::string node_name_
Definition: node_click_handler.h:98
swri_console::NodeClickHandler::GET_LOGGERS_SVC
static const std::string GET_LOGGERS_SVC
Definition: node_click_handler.h:102
swri_console::NodeClickHandler::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition: node_click_handler.cpp:47
swri_console::NodeClickHandler::logLevelClicked
void logLevelClicked()
Definition: node_click_handler.cpp:145
swri_console::NodeClickHandler
Definition: node_click_handler.h:50
ros::ServiceClient
swri_console::NodeClickHandler::callService
bool callService(ros::ServiceClient &client, T &service, int timeout_secs=5)
Definition: node_click_handler.h:82
swri_console
Definition: bag_reader.h:40
swri_console::NodeClickHandler::SET_LOGGER_LEVEL_SVC
static const std::string SET_LOGGER_LEVEL_SVC
Definition: node_click_handler.h:103
service_client.h
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
swri_console::NodeClickHandler::callServiceWorker
void callServiceWorker(ros::ServiceClient &client, T *service, bool *success)
Definition: node_click_handler.h:64
swri_console::NodeClickHandler::showContextMenu
bool showContextMenu(QListView *list, QContextMenuEvent *event)
Definition: node_click_handler.cpp:69
ros::NodeHandle


swri_console
Author(s): P. J. Reed , Jerry Towler , David Anthony
autogenerated on Sat Sep 23 2023 02:55:36