22 cras::HasLogger(logHelper), connectFn(
std::move(connectFn)), disconnectFn(
std::move(disconnectFn))
28 ConditionalSubscriber(
std::move(connectFn), [](
ros::Subscriber& sub) {
sub.shutdown(); }, logHelper)
34 std::lock_guard<std::mutex> lock(this->connectMutex);
36 this->disconnectNoLock();
46 std::lock_guard<std::mutex> lock(this->connectMutex);
48 if (lazy == this->lazy)
54 CRAS_DEBUG(
"Switching to lazy subscription mode");
56 CRAS_DEBUG(
"Switching to non-lazy subscription mode");
58 this->updateSubscriptionNoLock();
63 std::lock_guard<std::mutex> lock(this->connectMutex);
64 return this->subscribed;
69 std::lock_guard<std::mutex> lock(this->connectMutex);
70 this->updateSubscriptionNoLock();
75 const auto shouldBeSubscribed = !this->lazy || this->shouldBeSubscribed();
76 if (this->subscribed && !shouldBeSubscribed)
78 this->disconnectNoLock();
80 else if (!this->subscribed && shouldBeSubscribed)
82 this->connectNoLock();
88 this->connectFn(this->sub);
89 this->subscribed =
true;
90 CRAS_DEBUG(
"Connected to topic " + this->sub.getTopic());
95 CRAS_DEBUG(
"Disconnecting from topic " + this->sub.getTopic());
96 this->disconnectFn(this->sub);
97 this->subscribed =
false;