ros/publisher.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Copyright (C) 2009, Willow Garage, Inc.
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  * * Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef ROSCPP_PUBLISHER_HANDLE_H
30 #define ROSCPP_PUBLISHER_HANDLE_H
31 
32 #include "ros/forwards.h"
33 #include "ros/common.h"
34 #include "ros/message.h"
35 #include "ros/serialization.h"
36 //#include <boost/bind.hpp>
37 
38 namespace roswrap
39 {
49  {
50  public:
51  Publisher() {}
52  Publisher(const Publisher& rhs);
53  ~Publisher();
54 
63  template <typename M>
64  void publish(const std::shared_ptr<M>& message) const
65  {
66  using namespace serialization;
67 
68  if (!impl_)
69  {
70  ROS_ASSERT_MSG(false, "Call to publish() on an invalid Publisher");
71  return;
72  }
73 
74  if (!impl_->isValid())
75  {
76  ROS_ASSERT_MSG(false, "Call to publish() on an invalid Publisher (topic [%s])", impl_->topic_.c_str());
77  return;
78  }
79 
80  ROS_ASSERT_MSG(impl_->md5sum_ == "*" || std::string(mt::md5sum<M>(*message)) == "*" || impl_->md5sum_ == mt::md5sum<M>(*message),
81  "Trying to publish message of type [%s/%s] on a publisher with type [%s/%s]",
82  mt::datatype<M>(*message), mt::md5sum<M>(*message),
83  impl_->datatype_.c_str(), impl_->md5sum_.c_str());
84 
86  m.type_info = &typeid(M);
87  m.message = message;
88 
89  publish(std::bind(serializeMessage<M>, std::ref(*message)), m);
90  }
91 
95  template <typename M>
96  void publish(const M& message) const
97  {
98 #ifdef ROSSIMU
99  return;
100 #endif
101  using namespace serialization;
102  namespace mt = ros::message_traits;
103 
104  if (!impl_)
105  {
106  ROS_ASSERT_MSG(false, "Call to publish() on an invalid Publisher");
107  return;
108  }
109 
110  if (!impl_->isValid())
111  {
112  ROS_ASSERT_MSG(false, "Call to publish() on an invalid Publisher (topic [%s])", impl_->topic_.c_str());
113  return;
114  }
115 
116  ROS_ASSERT_MSG(impl_->md5sum_ == "*" || std::string(mt::md5sum<M>(message)) == "*" || impl_->md5sum_ == mt::md5sum<M>(message),
117  "Trying to publish message of type [%s/%s] on a publisher with type [%s/%s]",
118  mt::datatype<M>(message), mt::md5sum<M>(message),
119  impl_->datatype_.c_str(), impl_->md5sum_.c_str());
120 
122  publish(std::bind(serializeMessage<M>, std::ref(message)), m);
123  }
124 
135  void shutdown();
136 
140  std::string getTopic() const;
141 
145  uint32_t getNumSubscribers() const;
146 
150  bool isLatched() const;
151 
152  operator void*() const { return (impl_ && impl_->isValid()) ? (void*)1 : (void*)0; }
153 
154  bool operator<(const Publisher& rhs) const
155  {
156  return impl_ < rhs.impl_;
157  }
158 
159  bool operator==(const Publisher& rhs) const
160  {
161  return impl_ == rhs.impl_;
162  }
163 
164  bool operator!=(const Publisher& rhs) const
165  {
166  return impl_ != rhs.impl_;
167  }
168 
169  private:
170 
171  Publisher(const std::string& topic, const std::string& md5sum,
172  const std::string& datatype, const NodeHandle& node_handle,
173  const SubscriberCallbacksPtr& callbacks);
174 
175  void publish(const std::function<SerializedMessage(void)>& serfunc, SerializedMessage& m) const;
176  void incrementSequence() const;
177 
179  {
180  public:
181  Impl();
182  ~Impl();
183 
184  void unadvertise();
185  bool isValid() const;
186 
187  std::string topic_;
188  std::string md5sum_;
189  std::string datatype_;
193  };
194  typedef std::shared_ptr<Impl> ImplPtr;
195  typedef std::weak_ptr<Impl> ImplWPtr;
196 
198 
199  friend class NodeHandle;
200  friend class NodeHandleBackingCollection;
201  };
202 
203  typedef std::vector<Publisher> V_Publisher;
204 }
205 
206 #endif // ROSCPP_PUBLISHER_HANDLE_H
207 
roswrap::message_traits::md5sum
const char * md5sum()
returns MD5Sum<M>::value();
Definition: message_traits.h:227
roswrap::Publisher::publish
void publish(const M &message) const
Publish a message on the topic associated with this Publisher.
Definition: ros/publisher.h:96
roswrap::Publisher::operator!=
bool operator!=(const Publisher &rhs) const
Definition: ros/publisher.h:164
roswrap::Publisher::Impl::unadvertised_
bool unadvertised_
Definition: ros/publisher.h:192
roswrap::Publisher::ImplPtr
std::shared_ptr< Impl > ImplPtr
Definition: ros/publisher.h:194
roswrap::Publisher
Manages an advertisement on a specific topic.
Definition: ros/publisher.h:48
roswrap::Publisher::operator==
bool operator==(const Publisher &rhs) const
Definition: ros/publisher.h:159
roswrap::NodeHandlePtr
std::shared_ptr< NodeHandle > NodeHandlePtr
Definition: forwards.h:92
roswrap::message_traits::datatype
const char * datatype()
returns DataType<M>::value();
Definition: message_traits.h:236
roswrap::Publisher::impl_
ImplPtr impl_
Definition: ros/publisher.h:197
roswrap::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: rossimu.cpp:269
roswrap::Publisher::Impl::md5sum_
std::string md5sum_
Definition: ros/publisher.h:188
roswrap::SerializedMessage::type_info
const std::type_info * type_info
Definition: serialized_message.h:48
ros::message_traits
roswrap::SerializedMessage
Definition: serialized_message.h:40
message
def message(msg, *args, **kwargs)
roswrap::Publisher::Impl::topic_
std::string topic_
Definition: ros/publisher.h:187
roswrap::Publisher::operator<
bool operator<(const Publisher &rhs) const
Definition: ros/publisher.h:154
roswrap::Publisher::Impl
Definition: ros/publisher.h:178
roswrap::Publisher::publish
void publish(const std::shared_ptr< M > &message) const
Publish a message on the topic associated with this Publisher.
Definition: ros/publisher.h:64
roswrap::V_Publisher
std::vector< Publisher > V_Publisher
Definition: ros/publisher.h:203
ROS_ASSERT_MSG
#define ROS_ASSERT_MSG(cond,...)
Asserts that the provided condition evaluates to true.
Definition: assert.h:131
roswrap
Definition: param_modi.cpp:41
roswrap::SerializedMessage::message
std::shared_ptr< void const > message
Definition: serialized_message.h:47
roswrap::NodeHandle
roscpp's interface for creating subscribers, publishers, etc.
Definition: node_handle.h:87
roswrap::Publisher::ImplWPtr
std::weak_ptr< Impl > ImplWPtr
Definition: ros/publisher.h:195
roswrap::Publisher::Impl::callbacks_
SubscriberCallbacksPtr callbacks_
Definition: ros/publisher.h:191
roswrap::Publisher::Impl::node_handle_
NodeHandlePtr node_handle_
Definition: ros/publisher.h:190
sick_scan_base.h
roswrap::SubscriberCallbacksPtr
std::shared_ptr< SubscriberCallbacks > SubscriberCallbacksPtr
Definition: forwards.h:128
roswrap::Publisher::Impl::datatype_
std::string datatype_
Definition: ros/publisher.h:189
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::Publisher::Publisher
Publisher()
Definition: ros/publisher.h:51


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:10