image_subscriber.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 
22 
23 namespace fkie_message_filters
24 {
25 
26 ImageSubscriber::ImageSubscriber(const image_transport::ImageTransport& it, const std::string& base_topic, uint32_t queue_size, const image_transport::TransportHints& transport_hints) noexcept
27 {
28  set_subscribe_options(it, base_topic, queue_size, transport_hints);
29  subscribe();
30 }
31 
32 void ImageSubscriber::set_subscribe_options(const image_transport::ImageTransport& it, const std::string& base_topic, uint32_t queue_size, const image_transport::TransportHints& transport_hints) noexcept
33 {
34  it_ = std::make_shared<image_transport::ImageTransport>(it);
35  base_topic_ = base_topic;
36  queue_size_ = queue_size;
37  hints_ = transport_hints;
38 }
39 
40 void ImageSubscriber::subscribe(const image_transport::ImageTransport& it, const std::string& base_topic, uint32_t queue_size, const image_transport::TransportHints& transport_hints) noexcept
41 {
42  set_subscribe_options(it, base_topic, queue_size, transport_hints);
43  subscribe();
44 }
45 
46 std::string ImageSubscriber::topic() const noexcept
47 {
48  return sub_.getTopic();
49 }
50 
51 bool ImageSubscriber::is_configured() const noexcept
52 {
53  return it_ && !base_topic_.empty();
54 }
55 
56 void ImageSubscriber::subscribe_impl() noexcept
57 {
58  if (!sub_)
59  {
60  sub_ = it_->subscribe(
62  [this](const sensor_msgs::ImageConstPtr& m)
63  {
64  this->cb(m);
65  },
67  );
68  }
69 }
70 
72 {
73  sub_.shutdown();
74 }
75 
76 void ImageSubscriber::cb (const sensor_msgs::ImageConstPtr& m)
77 {
78  send(m);
79 }
80 
81 } // namespace fkie_message_filters
fkie_message_filters
Definition: buffer.h:33
fkie_message_filters::Source< sensor_msgs::ImageConstPtr >::send
void send(const Outputs &... out)
Pass data to all connected sinks.
Definition: source_impl.h:69
fkie_message_filters::ImageSubscriber::topic
virtual std::string topic() const noexcept override
Return the subscribed topic name.
Definition: image_subscriber.cpp:64
image_transport::ImageTransport
fkie_message_filters::ImageSubscriber::is_configured
virtual bool is_configured() const noexcept override
Check if the ROS subscriber is properly configured.
Definition: image_subscriber.cpp:69
fkie_message_filters::ImageSubscriber::set_subscribe_options
void set_subscribe_options(const image_transport::ImageTransport &it, const std::string &base_topic, uint32_t queue_size, const image_transport::TransportHints &transport_hints=image_transport::TransportHints()) noexcept
Configure ROS topic that is to be subscribed.
Definition: image_subscriber.cpp:50
image_subscriber.h
fkie_message_filters::ImageSubscriber::sub_
image_transport::Subscriber sub_
Definition: image_subscriber.h:153
fkie_message_filters::ImageSubscriber::subscribe_impl
virtual void subscribe_impl() noexcept override
Create a ROS subscriber.
Definition: image_subscriber.cpp:74
fkie_message_filters::ImageSubscriber::ImageSubscriber
ImageSubscriber() noexcept
Constructs an empty subscriber.
Definition: image_subscriber.h:88
fkie_message_filters::ImageSubscriber::cb
void cb(const sensor_msgs::ImageConstPtr &)
Definition: image_subscriber.cpp:94
fkie_message_filters::ImageSubscriber::unsubscribe_impl
virtual void unsubscribe_impl() noexcept override
Shut the ROS subscriber down.
Definition: image_subscriber.cpp:89
fkie_message_filters::SubscriberBase::subscribe
virtual void subscribe()
Subscribe to the configured ROS topic.
Definition: publisher_subscriber_base.cpp:64
fkie_message_filters::ImageSubscriber::it_
std::shared_ptr< image_transport::ImageTransport > it_
Definition: image_subscriber.h:149
image_transport::TransportHints
ros::VoidPtr
boost::shared_ptr< void > VoidPtr
fkie_message_filters::ImageSubscriber::base_topic_
std::string base_topic_
Definition: image_subscriber.h:150
fkie_message_filters::ImageSubscriber::hints_
image_transport::TransportHints hints_
Definition: image_subscriber.h:152
fkie_message_filters::ImageSubscriber::queue_size_
uint32_t queue_size_
Definition: image_subscriber.h:151
image_transport::Subscriber::getTopic
std::string getTopic() const
image_transport::Subscriber::shutdown
void shutdown()


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57