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

ENH: Adding python decorators for subscribing to messages #119

Open
MJafarMashhadi opened this issue Jul 2, 2020 · 0 comments
Open

ENH: Adding python decorators for subscribing to messages #119

MJafarMashhadi opened this issue Jul 2, 2020 · 0 comments

Comments

@MJafarMashhadi
Copy link
Contributor

I'm working on a project which I'm using pprzlink in. I created a couple of decorator classes for subscribing to messages and I was wondering if they are a good addition to pprzlink.

There is IvySubscribe that will bind the function to a list of message types:

# To one message type
@IvySubscribe(ivy_link=ivy, message_types=[("ground", "NEW_AIRCRAFT")])
def new_aircraft_callback(ac_id, msg):
    pass

# RegEx is also supported
@IvySubscribe(ivy_link=ivy, message_types=["(.*)")])
def new_aircraft_callback(ac_id, msg):
    pass

# Subscribe to all 
@IvySubscribe(ivy_link=ivy)
def get_all_messages(ac_id, msg):
    pass

I created IvySubscribeOnce that stop listening for that type of message as soon as it receives one (useful for the new request messages):


@IvySubscribeOnce(
    ivy_link=ivy_link,
    message_types=[r"^((\S*\s*)?\d+_\d+ ground %s_REQ( .*|$))" % request_name]
)
def request_callback(ac_id, msg):
    pass

And if you needed to unbind manually you can use get_all_messages.__ivy_subs__.unsubscribe().

They are useful in my project, but whether it's a good idea to have them as a part of pprz_link itself, I don't know. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant