publisher_subscriber_base.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 
23 
24 namespace fkie_message_filters
25 {
26 
27 std::tuple<boost::signals2::connection, boost::signals2::connection> PublisherBase::link_with_subscriber(SubscriberBase& sub)
28 {
29  boost::signals2::connection c1, c2;
30  c1 = enable_signal_.connect([&sub]() { sub.subscribe_impl(); });
31  c2 = disable_signal_.connect([&sub]() { sub.unsubscribe_impl(); });
32  if (is_active()) sub.subscribe_impl(); else sub.unsubscribe_impl();
33  return std::tie(c1, c2);
34 }
35 
37 {
38  if (is_active()) enable_signal_(); else disable_signal_();
39 }
40 
42 {
43  unlink_from_publisher();
44 }
45 
47 {
48  unlink_from_publisher();
49  if (is_configured()) subscribe_impl();
50 }
51 
53 {
54  unlink_from_publisher();
55  if (is_configured()) unsubscribe_impl();
56 }
57 
59 {
60  unlink_from_publisher();
61  if (is_configured()) link_with_publisher(pub);
62 }
63 
65 {
66  conn1_.disconnect();
67  conn2_.disconnect();
68 }
69 
71 {
72  unlink_from_publisher();
73  std::tie(conn1_, conn2_) = pub.link_with_subscriber(*this);
74 }
75 
76 } // namespace fkie_message_filters
Base class for ROS publishers in a filter pipeline.
boost::signals2::signal< void()> disable_signal_
virtual void subscribe_on_demand(PublisherBase &pub)
Subscribe to the configured ROS topic whenever the given publisher is active.
virtual void subscribe()
Subscribe to the configured ROS topic.
Base class for ROS subscribers in a filter pipeline.
void update_subscriber_state()
Cause all linked subscribers to subscribe or unsubscribe to their ROS topics.
Primary namespace.
Definition: buffer.h:33
void link_with_publisher(PublisherBase &pub)
Add self to the list of subscribers which are controlled by a publisher.
virtual void unsubscribe()
Unsubscribe from the configured ROS topic.
void unlink_from_publisher()
Remove self from the list of subscribers which are controlled by a publisher.
virtual void unsubscribe_impl()=0
Implement how to unsubscribe from the configured ROS topic.
virtual void subscribe_impl()=0
Implement how to subscribe to the configured ROS topic.
boost::signals2::signal< void()> enable_signal_
std::tuple< boost::signals2::connection, boost::signals2::connection > link_with_subscriber(SubscriberBase &sub)
Add a new subscriber that will be controlled by this publisher.
virtual bool is_active() const =0
Check if the publisher is active.


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Mon Feb 28 2022 22:21:43