A lazy subscriber that subscribes only when a condition is met.
More...
#include <lazy_subscriber.hpp>
A lazy subscriber that subscribes only when a condition is met.
Definition at line 33 of file lazy_subscriber.hpp.
◆ ConnectFn
Type of the function that connects the subscriber.
- Parameters
-
[out] | sub | Reference to the subscriber object to be created. |
Definition at line 38 of file lazy_subscriber.hpp.
◆ DisconnectFn
Type of the function that disconnects the subscriber.
- Parameters
-
[in,out] | Reference | to the subscriber object to be disconnected. |
Definition at line 42 of file lazy_subscriber.hpp.
◆ ConditionalSubscriber() [1/2]
Create the conditional subscriber.
- Parameters
-
[in] | connectFn | The function that connects the subscriber. It should store the subscriber in the passed sub object. |
[in] | disconnectFn | The function that disconnects the subscriber. The sub object passed to the function is the one created previously by connectFn . The passed subscriber should be invalidated. |
[in] | logHelper | Logging helper. |
- Note
- The base class itself does not regularly check the connect/disconnect condition. Subclasses are responsible for calling
updateSubscription()
when it is possible that the subscription condition changed.
◆ ConditionalSubscriber() [2/2]
Create the conditional subscriber.
- Parameters
-
[in] | connectFn | The function that connects the subscriber. It should store the subscriber in the passed sub object. Disconnection is done by simply calling sub.shutdown() . |
[in] | logHelper | Logging helper. |
- Note
- The base class itself does not regularly check the connect/disconnect condition. Subclasses are responsible for calling
updateSubscription()
when it is possible that the subscription condition changed.
◆ ~ConditionalSubscriber()
cras::ConditionalSubscriber::~ConditionalSubscriber |
( |
| ) |
|
|
virtual |
Destroy this object and unsubscribe the subscriber if it was subscribed.
Definition at line 32 of file lazy_subscriber.cpp.
◆ connectNoLock()
void cras::ConditionalSubscriber::connectNoLock |
( |
| ) |
|
|
protected |
Connect the subscriber to its input.
- Note
- You have to lock this->connectMutex prior to calling this method.
Definition at line 86 of file lazy_subscriber.cpp.
◆ disconnectNoLock()
void cras::ConditionalSubscriber::disconnectNoLock |
( |
| ) |
|
|
protected |
Disconnect the subscriber from its input.
- Note
- You have to lock this->connectMutex prior to calling this method.
Definition at line 93 of file lazy_subscriber.cpp.
◆ isLazy()
bool cras::ConditionalSubscriber::isLazy |
( |
| ) |
const |
Tell whether this subscriber has the lazy behavior enabled.
- Returns
- Whether lazy behavior is enabled.
Definition at line 39 of file lazy_subscriber.cpp.
◆ isSubscribed()
bool cras::ConditionalSubscriber::isSubscribed |
( |
| ) |
const |
Whether the subscriber is currently subscribed to its topic or not.
- Returns
- Whether the subscriber is currently subscribed to its topic or not.
Definition at line 61 of file lazy_subscriber.cpp.
◆ setLazy()
void cras::ConditionalSubscriber::setLazy |
( |
bool |
lazy | ) |
|
Set whether the subscriber behaves in the lazy way.
- Parameters
-
[in] | lazy | If set to false, the subscriber is switched to always subscribed mode. |
- Note
- Calling this function checks the subscription condition and subscribes/unsubscribes as necessary.
Definition at line 44 of file lazy_subscriber.cpp.
◆ shouldBeSubscribed()
virtual bool cras::ConditionalSubscriber::shouldBeSubscribed |
( |
| ) |
const |
|
protectedpure virtual |
◆ updateSubscription()
void cras::ConditionalSubscriber::updateSubscription |
( |
| ) |
|
|
protected |
The callback called when the condition might have changed.
- Note
- This function locks
connectMutex
.
Definition at line 67 of file lazy_subscriber.cpp.
◆ updateSubscriptionNoLock()
void cras::ConditionalSubscriber::updateSubscriptionNoLock |
( |
| ) |
|
|
protected |
The callback called when the condition might have changed.
- Note
- You have to lock this->connectMutex prior to calling this method.
Definition at line 73 of file lazy_subscriber.cpp.
◆ connectFn
ConnectFn cras::ConditionalSubscriber::connectFn |
|
protected |
◆ connectMutex
mutable ::std::mutex cras::ConditionalSubscriber::connectMutex |
|
protected |
◆ disconnectFn
◆ lazy
bool cras::ConditionalSubscriber::lazy {true} |
|
protected |
Whether the lazy behavior is enabled (if false, the subscriber is always subscribed).
Definition at line 129 of file lazy_subscriber.hpp.
◆ sub
The underlying subscriber (valid only when subscribed
is true).
Definition at line 126 of file lazy_subscriber.hpp.
◆ subscribed
bool cras::ConditionalSubscriber::subscribed {false} |
|
protected |
Whether the subscriber is currently subscribed to its topic or not.
Definition at line 132 of file lazy_subscriber.hpp.
The documentation for this class was generated from the following files: