interactive_marker_client.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_CLIENT
33 #define INTERACTIVE_MARKER_CLIENT
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/thread/mutex.hpp>
37 #include <boost/function.hpp>
38 #include <boost/unordered_map.hpp>
39 
40 #include <string>
41 
42 #include <ros/subscriber.h>
43 #include <ros/node_handle.h>
44 
45 #include <tf/tf.h>
46 
47 #include <visualization_msgs/InteractiveMarkerInit.h>
48 #include <visualization_msgs/InteractiveMarkerUpdate.h>
50 
51 #include "detail/state_machine.h"
52 
53 namespace interactive_markers
54 {
55 
56 class SingleClient;
57 
68 class InteractiveMarkerClient : boost::noncopyable
69 {
70 public:
71 
72  enum StatusT {
73  OK = 0,
74  WARN = 1,
75  ERROR = 2
76  };
77 
78  typedef visualization_msgs::InteractiveMarkerUpdateConstPtr UpdateConstPtr;
79  typedef visualization_msgs::InteractiveMarkerInitConstPtr InitConstPtr;
80 
81  typedef boost::function< void ( const UpdateConstPtr& ) > UpdateCallback;
82  typedef boost::function< void ( const InitConstPtr& ) > InitCallback;
83  typedef boost::function< void ( const std::string& ) > ResetCallback;
84  typedef boost::function< void ( StatusT, const std::string&, const std::string& ) > StatusCallback;
85 
91  const std::string& target_frame = "",
92  const std::string &topic_ns = "" );
93 
97 
100  void subscribe( std::string topic_ns );
101 
104  void shutdown();
105 
108  void update();
109 
112  void setTargetFrame( std::string target_frame );
113 
116  void setInitCb( const InitCallback& cb );
117 
120  void setUpdateCb( const UpdateCallback& cb );
121 
124  void setResetCb( const ResetCallback& cb );
125 
128  void setStatusCb( const StatusCallback& cb );
129 
132 
133 private:
134 
135  // Process message from the init or update channel
136  template<class MsgConstPtrT>
137  void process( const MsgConstPtrT& msg );
138 
140 
141  enum StateT
142  {
146  };
147 
149 
150  std::string topic_ns_;
151 
154 
155  // subscribe to the init channel
156  void subscribeInit();
157 
158  // subscribe to the init channel
159  void subscribeUpdate();
160 
161  void statusCb( StatusT status, const std::string& server_id, const std::string& msg );
162 
164  typedef boost::unordered_map<std::string, SingleClientPtr> M_SingleClient;
165  M_SingleClient publisher_contexts_;
167 
169  std::string target_frame_;
170 
171 public:
172  // for internal usage
174  {
175  void initCb( const InitConstPtr& i ) const {
176  if (init_cb_) init_cb_( i ); }
177  void updateCb( const UpdateConstPtr& u ) const {
178  if (update_cb_) update_cb_( u ); }
179  void resetCb( const std::string& s ) const {
180  if (reset_cb_) reset_cb_(s); }
181  void statusCb( StatusT s, const std::string& id, const std::string& m ) const {
182  if (status_cb_) status_cb_(s,id,m); }
183 
184  void setInitCb( InitCallback init_cb ) {
185  init_cb_ = init_cb;
186  }
187  void setUpdateCb( UpdateCallback update_cb ) {
188  update_cb_ = update_cb;
189  }
190  void setResetCb( ResetCallback reset_cb ) {
191  reset_cb_ = reset_cb;
192  }
193  void setStatusCb( StatusCallback status_cb ) {
194  status_cb_ = status_cb;
195  }
196 
197  private:
198  InitCallback init_cb_;
199  UpdateCallback update_cb_;
200  ResetCallback reset_cb_;
201  StatusCallback status_cb_;
202  };
203 
204  // handle init message
205  void processInit( const InitConstPtr& msg );
206 
207  // handle update message
208  void processUpdate( const UpdateConstPtr& msg );
209 
210 private:
212 
213  // this is the real (external) status callback
214  StatusCallback status_cb_;
215 
216  // this allows us to detect if a server died (in most cases)
218 
219  // if false, auto-completed markers will have alpha = 1.0
221 };
222 
223 
224 
225 }
226 
227 #endif
visualization_msgs::InteractiveMarkerInitConstPtr InitConstPtr
std::string target_frame
Definition: client_test.cpp:74
INTERACTIVE_MARKERS_PUBLIC void shutdown()
Unsubscribe, clear queues & call reset callbacks.
#define INTERACTIVE_MARKERS_PUBLIC
INTERACTIVE_MARKERS_PUBLIC void setInitCb(const InitCallback &cb)
Set callback for init messages.
boost::function< void(StatusT, const std::string &, const std::string &) > StatusCallback
boost::function< void(const InitConstPtr &) > InitCallback
boost::unordered_map< std::string, SingleClientPtr > M_SingleClient
INTERACTIVE_MARKERS_PUBLIC void setResetCb(const ResetCallback &cb)
Set callback for resetting one server connection.
INTERACTIVE_MARKERS_PUBLIC void subscribe(std::string topic_ns)
Subscribe to the topics topic_ns/update and topic_ns/init.
INTERACTIVE_MARKERS_PUBLIC void setUpdateCb(const UpdateCallback &cb)
Set callback for update messages.
INTERACTIVE_MARKERS_PUBLIC void setStatusCb(const StatusCallback &cb)
Set callback for status updates.
INTERACTIVE_MARKERS_PUBLIC InteractiveMarkerClient(tf::Transformer &tf, const std::string &target_frame="", const std::string &topic_ns="")
INTERACTIVE_MARKERS_PUBLIC ~InteractiveMarkerClient()
Will cause a &#39;reset&#39; call for all server ids.
boost::function< void(const std::string &) > ResetCallback
visualization_msgs::InteractiveMarkerUpdateConstPtr UpdateConstPtr
void statusCb(StatusT status, const std::string &server_id, const std::string &msg)
INTERACTIVE_MARKERS_PUBLIC void setEnableAutocompleteTransparency(bool enable)
INTERACTIVE_MARKERS_PUBLIC void update()
Update tf info, call callbacks.
boost::function< void(const UpdateConstPtr &) > UpdateCallback
INTERACTIVE_MARKERS_PUBLIC void setTargetFrame(std::string target_frame)
Change the target frame and reset the connection.
void statusCb(StatusT s, const std::string &id, const std::string &m) const


interactive_markers
Author(s): David Gossow, William Woodall
autogenerated on Mon Feb 28 2022 22:33:22