interactive_marker_server.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
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 the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * 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 THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Author: David Gossow
30  */
31 
32 #ifndef INTERACTIVE_MARKER_SERVER
33 #define INTERACTIVE_MARKER_SERVER
34 
35 #include <visualization_msgs/InteractiveMarkerUpdate.h>
36 #include <visualization_msgs/InteractiveMarkerFeedback.h>
38 
39 #include <boost/scoped_ptr.hpp>
40 #include <boost/thread/thread.hpp>
41 #include <boost/thread/recursive_mutex.hpp>
42 
43 #include <ros/ros.h>
44 #include <ros/callback_queue.h>
45 
46 #include <boost/function.hpp>
47 #include <boost/unordered_map.hpp>
48 
49 namespace interactive_markers
50 {
51 
56 class InteractiveMarkerServer : boost::noncopyable
57 {
58 public:
59 
60  typedef visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr;
61  typedef boost::function< void ( const FeedbackConstPtr& ) > FeedbackCallback;
62 
63  static const uint8_t DEFAULT_FEEDBACK_CB = 255;
64 
73  InteractiveMarkerServer( const std::string &topic_ns, const std::string &server_id="", bool spin_thread = false );
74 
78 
84  void insert( const visualization_msgs::InteractiveMarker &int_marker );
85 
93  void insert( const visualization_msgs::InteractiveMarker &int_marker,
94  FeedbackCallback feedback_cb,
95  uint8_t feedback_type=DEFAULT_FEEDBACK_CB );
96 
104  bool setPose( const std::string &name,
105  const geometry_msgs::Pose &pose,
106  const std_msgs::Header &header=std_msgs::Header() );
107 
113  bool erase( const std::string &name );
114 
118  void clear();
119 
124  bool empty() const;
125 
130  std::size_t size() const;
131 
143  bool setCallback( const std::string &name, FeedbackCallback feedback_cb,
144  uint8_t feedback_type=DEFAULT_FEEDBACK_CB );
145 
149  void applyChanges();
150 
156  bool get( std::string name, visualization_msgs::InteractiveMarker &int_marker ) const;
157 
161  std::vector<std::string> getNames();
162 
163 private:
164 
166  {
168  std::string last_client_id;
170  boost::unordered_map<uint8_t,FeedbackCallback> feedback_cbs;
171  visualization_msgs::InteractiveMarker int_marker;
172  };
173 
174  typedef boost::unordered_map< std::string, MarkerContext > M_MarkerContext;
175 
176  // represents an update to a single marker
178  {
179  enum {
183  } update_type;
184  visualization_msgs::InteractiveMarker int_marker;
186  boost::unordered_map<uint8_t,FeedbackCallback> feedback_cbs;
187  };
188 
189  typedef boost::unordered_map< std::string, UpdateContext > M_UpdateContext;
190 
191  // main loop when spinning our own thread
192  // - process callbacks in our callback queue
193  // - process pending goals
194  void spinThread();
195 
196  // update marker pose & call user callback
197  void processFeedback( const FeedbackConstPtr& feedback );
198 
199  // send an empty update to keep the client GUIs happy
200  void keepAlive();
201 
202  // increase sequence number & publish an update
203  void publish( visualization_msgs::InteractiveMarkerUpdate &update );
204 
205  // publish the current complete state to the latched "init" topic.
206  void publishInit();
207 
208  // Update pose, schedule update without locking
209  void doSetPose( M_UpdateContext::iterator update_it,
210  const std::string &name,
211  const geometry_msgs::Pose &pose,
212  const std_msgs::Header &header );
213 
214  // contains the current state of all markers
216 
217  // updates that have to be sent on the next publish
219 
220  // topic namespace to use
221  std::string topic_ns_;
222 
223  mutable boost::recursive_mutex mutex_;
224 
225  // these are needed when spinning up a dedicated thread
226  boost::scoped_ptr<boost::thread> spin_thread_;
229  volatile bool need_to_terminate_;
230 
231  // this is needed when running in non-threaded mode
233 
237 
238  uint64_t seq_num_;
239 
240  std::string server_id_;
241 };
242 
243 }
244 
245 #endif
interactive_markers::InteractiveMarkerServer::UpdateContext::ERASE
@ ERASE
Definition: interactive_marker_server.h:182
interactive_markers::InteractiveMarkerServer::feedback_sub_
ros::Subscriber feedback_sub_
Definition: interactive_marker_server.h:236
interactive_markers::InteractiveMarkerServer::spinThread
void spinThread()
Definition: interactive_marker_server.cpp:97
interactive_markers::InteractiveMarkerServer::UpdateContext::FULL_UPDATE
@ FULL_UPDATE
Definition: interactive_marker_server.h:180
interactive_markers::InteractiveMarkerServer::get
INTERACTIVE_MARKERS_PUBLIC bool get(std::string name, visualization_msgs::InteractiveMarker &int_marker) const
Definition: interactive_marker_server.cpp:347
interactive_markers::InteractiveMarkerServer::erase
INTERACTIVE_MARKERS_PUBLIC bool erase(const std::string &name)
Definition: interactive_marker_server.cpp:192
ros::Publisher
interactive_markers::InteractiveMarkerServer::MarkerContext::feedback_cbs
boost::unordered_map< uint8_t, FeedbackCallback > feedback_cbs
Definition: interactive_marker_server.h:170
ros.h
interactive_markers::InteractiveMarkerServer::MarkerContext
Definition: interactive_marker_server.h:165
interactive_markers::InteractiveMarkerServer::M_MarkerContext
boost::unordered_map< std::string, MarkerContext > M_MarkerContext
Definition: interactive_marker_server.h:174
interactive_markers::InteractiveMarkerServer::MarkerContext::default_feedback_cb
FeedbackCallback default_feedback_cb
Definition: interactive_marker_server.h:169
interactive_markers::InteractiveMarkerServer::FeedbackConstPtr
visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr
Definition: interactive_marker_server.h:60
interactive_markers::InteractiveMarkerServer::MarkerContext::int_marker
visualization_msgs::InteractiveMarker int_marker
Definition: interactive_marker_server.h:171
interactive_markers::InteractiveMarkerServer::getNames
INTERACTIVE_MARKERS_PUBLIC std::vector< std::string > getNames()
Definition: interactive_marker_server.cpp:391
interactive_markers::InteractiveMarkerServer::topic_ns_
std::string topic_ns_
Definition: interactive_marker_server.h:221
INTERACTIVE_MARKERS_PUBLIC
#define INTERACTIVE_MARKERS_PUBLIC
Definition: visibility_control.hpp:64
interactive_markers::InteractiveMarkerServer::marker_contexts_
M_MarkerContext marker_contexts_
Definition: interactive_marker_server.h:215
interactive_markers::InteractiveMarkerServer::processFeedback
void processFeedback(const FeedbackConstPtr &feedback)
Definition: interactive_marker_server.cpp:424
interactive_markers::InteractiveMarkerServer::size
INTERACTIVE_MARKERS_PUBLIC std::size_t size() const
Definition: interactive_marker_server.cpp:225
interactive_markers::InteractiveMarkerServer::DEFAULT_FEEDBACK_CB
static const uint8_t DEFAULT_FEEDBACK_CB
Definition: interactive_marker_server.h:63
interactive_markers::InteractiveMarkerServer::~InteractiveMarkerServer
INTERACTIVE_MARKERS_PUBLIC ~InteractiveMarkerServer()
Destruction of the interface will lead to all managed markers being cleared.
Definition: interactive_marker_server.cpp:81
interactive_markers::InteractiveMarkerServer::M_UpdateContext
boost::unordered_map< std::string, UpdateContext > M_UpdateContext
Definition: interactive_marker_server.h:189
interactive_markers::InteractiveMarkerServer::UpdateContext::update_type
enum interactive_markers::InteractiveMarkerServer::UpdateContext::@0 update_type
ros::CallbackQueue
interactive_markers::InteractiveMarkerServer::callback_queue_
ros::CallbackQueue callback_queue_
Definition: interactive_marker_server.h:228
interactive_markers::InteractiveMarkerServer::UpdateContext::feedback_cbs
boost::unordered_map< uint8_t, FeedbackCallback > feedback_cbs
Definition: interactive_marker_server.h:186
interactive_markers::InteractiveMarkerServer::keep_alive_timer_
ros::Timer keep_alive_timer_
Definition: interactive_marker_server.h:232
interactive_markers::InteractiveMarkerServer::UpdateContext::POSE_UPDATE
@ POSE_UPDATE
Definition: interactive_marker_server.h:181
interactive_markers::InteractiveMarkerServer::FeedbackCallback
boost::function< void(const FeedbackConstPtr &) > FeedbackCallback
Definition: interactive_marker_server.h:61
interactive_markers::InteractiveMarkerServer::node_handle_
ros::NodeHandle node_handle_
Definition: interactive_marker_server.h:227
interactive_markers::InteractiveMarkerServer::seq_num_
uint64_t seq_num_
Definition: interactive_marker_server.h:238
interactive_markers::InteractiveMarkerServer::insert
INTERACTIVE_MARKERS_PUBLIC void insert(const visualization_msgs::InteractiveMarker &int_marker)
Definition: interactive_marker_server.cpp:325
interactive_markers::InteractiveMarkerServer::publish
void publish(visualization_msgs::InteractiveMarkerUpdate &update)
Definition: interactive_marker_server.cpp:485
interactive_markers::InteractiveMarkerServer::empty
INTERACTIVE_MARKERS_PUBLIC bool empty() const
Definition: interactive_marker_server.cpp:219
interactive_markers::InteractiveMarkerServer::applyChanges
INTERACTIVE_MARKERS_PUBLIC void applyChanges()
Definition: interactive_marker_server.cpp:110
interactive_markers::InteractiveMarkerServer::MarkerContext::last_feedback
ros::Time last_feedback
Definition: interactive_marker_server.h:167
interactive_markers::InteractiveMarkerServer::UpdateContext::int_marker
visualization_msgs::InteractiveMarker int_marker
Definition: interactive_marker_server.h:184
interactive_markers::InteractiveMarkerServer
Definition: interactive_marker_server.h:56
interactive_markers::InteractiveMarkerServer::mutex_
boost::recursive_mutex mutex_
Definition: interactive_marker_server.h:223
callback_queue.h
interactive_markers::InteractiveMarkerServer::need_to_terminate_
volatile bool need_to_terminate_
Definition: interactive_marker_server.h:229
interactive_markers::InteractiveMarkerServer::setPose
INTERACTIVE_MARKERS_PUBLIC bool setPose(const std::string &name, const geometry_msgs::Pose &pose, const std_msgs::Header &header=std_msgs::Header())
Definition: interactive_marker_server.cpp:231
interactive_markers::InteractiveMarkerServer::InteractiveMarkerServer
INTERACTIVE_MARKERS_PUBLIC InteractiveMarkerServer(const std::string &topic_ns, const std::string &server_id="", bool spin_thread=false)
Definition: interactive_marker_server.cpp:42
interactive_markers::InteractiveMarkerServer::setCallback
INTERACTIVE_MARKERS_PUBLIC bool setCallback(const std::string &name, FeedbackCallback feedback_cb, uint8_t feedback_type=DEFAULT_FEEDBACK_CB)
Definition: interactive_marker_server.cpp:269
ros::Time
interactive_markers::InteractiveMarkerServer::init_pub_
ros::Publisher init_pub_
Definition: interactive_marker_server.h:234
interactive_markers::InteractiveMarkerServer::UpdateContext::default_feedback_cb
FeedbackCallback default_feedback_cb
Definition: interactive_marker_server.h:185
visibility_control.hpp
interactive_markers::InteractiveMarkerServer::keepAlive
void keepAlive()
Definition: interactive_marker_server.cpp:477
interactive_markers::InteractiveMarkerServer::pending_updates_
M_UpdateContext pending_updates_
Definition: interactive_marker_server.h:218
interactive_markers::InteractiveMarkerServer::MarkerContext::last_client_id
std::string last_client_id
Definition: interactive_marker_server.h:168
interactive_markers::InteractiveMarkerServer::doSetPose
void doSetPose(M_UpdateContext::iterator update_it, const std::string &name, const geometry_msgs::Pose &pose, const std_msgs::Header &header)
Definition: interactive_marker_server.cpp:493
interactive_markers::InteractiveMarkerServer::server_id_
std::string server_id_
Definition: interactive_marker_server.h:240
interactive_markers::InteractiveMarkerServer::UpdateContext
Definition: interactive_marker_server.h:177
interactive_markers
Definition: message_context.h:45
interactive_markers::InteractiveMarkerServer::clear
INTERACTIVE_MARKERS_PUBLIC void clear()
Definition: interactive_marker_server.cpp:205
interactive_markers::InteractiveMarkerServer::spin_thread_
boost::scoped_ptr< boost::thread > spin_thread_
Definition: interactive_marker_server.h:226
interactive_markers::InteractiveMarkerServer::publishInit
void publishInit()
Definition: interactive_marker_server.cpp:405
interactive_markers::InteractiveMarkerServer::update_pub_
ros::Publisher update_pub_
Definition: interactive_marker_server.h:235
ros::Timer
ros::NodeHandle
ros::Subscriber


interactive_markers
Author(s): David Gossow, William Woodall
autogenerated on Fri Oct 27 2023 02:31:54