Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qos parameter to SubscriberState #19

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions flexbe_states/flexbe_states/subscriber_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,34 @@
from flexbe_core import EventState, Logger

from flexbe_core.proxy import ProxySubscriberCached
from flexbe_core.proxy.qos import QOS_DEFAULT


class SubscriberState(EventState):
"""
Gets the latest message on the given topic and stores it to userdata.

-- topic string The topic on which should be listened.
-- msg_type type The type of messages of this topic.
-- blocking bool Blocks until a message is received.
-- clear bool Drops last message on this topic on enter
in order to only handle message received since this state is active.
-- qos QoSProfile A QoSProfile to apply to the subscription.

#> message object Latest message on the given topic of the respective type.

<= received Message has been received and stored in userdata or state is not blocking.
<= unavailable The topic is not available when this state becomes actives.
"""

def __init__(self, topic, msg_type="", blocking=True, clear=False):
def __init__(self, topic, msg_type="", blocking=True, clear=False, qos=QOS_DEFAULT):
super(SubscriberState, self).__init__(outcomes=['received', 'unavailable'],
output_keys=['message'])
self._topic = topic
self._msg_type = msg_type
self._blocking = blocking
self._clear = clear
self._qos = qos
self._connected = False
self._sub = None
if not self._connect():
Expand Down Expand Up @@ -91,7 +95,7 @@ def on_enter(self, userdata):

def _connect(self):
try:
self._sub = ProxySubscriberCached({self._topic: self._msg_type}, inst_id=id(self))
self._sub = ProxySubscriberCached({self._topic: self._msg_type}, qos=self._qos, inst_id=id(self))
self._connected = True
return True
except Exception: # pylint: disable=W0703
Expand Down
Loading