advertise_options.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef ROSCPP_ADVERTISE_OPTIONS_H
29 #define ROSCPP_ADVERTISE_OPTIONS_H
30 
31 #include "ros/forwards.h"
32 #include "ros/message_traits.h"
33 #include "common.h"
34 
35 namespace ros
36 {
37 
41 struct ROSCPP_DECL AdvertiseOptions
42 {
44  : callback_queue(0)
45  , latch(false)
46  {
47  }
48 
49  /*
50  * \brief Constructor
51  * \param _topic Topic to publish on
52  * \param _queue_size Maximum number of outgoing messages to be queued for delivery to subscribers
53  * \param _md5sum The md5sum of the message datatype published on this topic
54  * \param _datatype Datatype of the message published on this topic (eg. "std_msgs/String")
55  * \param _connect_cb Function to call when a subscriber connects to this topic
56  * \param _disconnect_cb Function to call when a subscriber disconnects from this topic
57  */
58  AdvertiseOptions(const std::string& _topic, uint32_t _queue_size, const std::string& _md5sum,
59  const std::string& _datatype, const std::string& _message_definition,
61  const SubscriberStatusCallback& _disconnect_cb = SubscriberStatusCallback())
62  : topic(_topic)
63  , queue_size(_queue_size)
64  , md5sum(_md5sum)
65  , datatype(_datatype)
66  , message_definition(_message_definition)
67  , connect_cb(_connect_cb)
68  , disconnect_cb(_disconnect_cb)
69  , callback_queue(0)
70  , latch(false)
71  , has_header(false)
72  {}
73 
83  template <class M>
84  void init(const std::string& _topic, uint32_t _queue_size,
86  const SubscriberStatusCallback& _disconnect_cb = SubscriberStatusCallback())
87  {
88  topic = _topic;
89  queue_size = _queue_size;
90  connect_cb = _connect_cb;
91  disconnect_cb = _disconnect_cb;
92  md5sum = message_traits::md5sum<M>();
93  datatype = message_traits::datatype<M>();
94  message_definition = message_traits::definition<M>();
95  has_header = message_traits::hasHeader<M>();
96  }
97 
98  std::string topic;
99  uint32_t queue_size;
100 
101  std::string md5sum;
102  std::string datatype;
103  std::string message_definition;
104 
107 
109 
121 
126  bool latch;
127 
132 
133 
147  template<class M>
148  static AdvertiseOptions create(const std::string& topic, uint32_t queue_size,
149  const SubscriberStatusCallback& connect_cb,
150  const SubscriberStatusCallback& disconnect_cb,
151  const VoidConstPtr& tracked_object,
152  CallbackQueueInterface* queue)
153  {
154  AdvertiseOptions ops;
155  ops.init<M>(topic, queue_size, connect_cb, disconnect_cb);
156  ops.tracked_object = tracked_object;
157  ops.callback_queue = queue;
158  return ops;
159  }
160 };
161 
162 
163 }
164 
165 #endif
SubscriberStatusCallback connect_cb
The function to call when a subscriber connects to this topic.
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
Definition: forwards.h:94
std::string message_definition
The full definition of the message published on this topic.
bool has_header
Tells whether or not the message has a header. If it does, the sequence number will be written direct...
SubscriberStatusCallback disconnect_cb
The function to call when a subscriber disconnects from this topic.
void init(const std::string &_topic, uint32_t _queue_size, const SubscriberStatusCallback &_connect_cb=SubscriberStatusCallback(), const SubscriberStatusCallback &_disconnect_cb=SubscriberStatusCallback())
templated helper function for automatically filling out md5sum, datatype and message definition ...
bool latch
Whether or not this publication should "latch". A latching publication will automatically send out th...
Abstract interface for a queue used to handle all callbacks within roscpp.
Encapsulates all options available for creating a Publisher.
static AdvertiseOptions create(const std::string &topic, uint32_t queue_size, const SubscriberStatusCallback &connect_cb, const SubscriberStatusCallback &disconnect_cb, const VoidConstPtr &tracked_object, CallbackQueueInterface *queue)
Templated helper function for creating an AdvertiseOptions for a message type with most options...
const char * datatype()
VoidConstPtr tracked_object
An object whose destruction will prevent the callbacks associated with this advertisement from being ...
AdvertiseOptions(const std::string &_topic, uint32_t _queue_size, const std::string &_md5sum, const std::string &_datatype, const std::string &_message_definition, const SubscriberStatusCallback &_connect_cb=SubscriberStatusCallback(), const SubscriberStatusCallback &_disconnect_cb=SubscriberStatusCallback())
std::string datatype
The datatype of the message published on this topic (eg. "std_msgs/String")
std::string md5sum
The md5sum of the message datatype published on this topic.
std::string topic
The topic to publish on.
const char * md5sum()
CallbackQueueInterface * callback_queue
Queue to add callbacks to. If NULL, the global callback queue will be used.
uint32_t queue_size
The maximum number of outgoing messages to be queued for delivery to subscribers. ...


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Sun Feb 3 2019 03:29:54