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

Allow arbitrary functional selector for expectation #32

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

ThomasDebrunner
Copy link
Contributor

@ThomasDebrunner ThomasDebrunner commented Dec 5, 2023

This adds the following expectaction prototype:

Expectation expect(std::function<bool(const mav::Message&)> selector)

Which can be used for specifc queries, e.g.

auto expectation = connection.expect([](const mav::Message &message) {
   return message.id() == 11232 && message["field3"].as<int>() == 15;
})

auto message = connection.receive(expectation);

The current expect functions

Expectation expect(int message_id, int source_id=mav::ANY_ID, int component_id=mav::ANY_ID)
Expectation expect(const std::string &message_name, int source_id=mav::ANY_ID, int component_id=mav::ANY_ID)

Have been changed to be specializations of the more generic expect function with the funcional argument

This also adds a new receive prototype:

Message inline receive(std::function<bool(const mav::Message&)> selector, int timeout_ms=-1)

Which again gives the user the possibility to receive a very specific message. This also makes use of the new expect function.

@ThomasDebrunner ThomasDebrunner marked this pull request as ready for review December 6, 2023 10:10
@ThomasDebrunner ThomasDebrunner merged commit 0eaac49 into main Dec 7, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants