Generic filter with user-defined callback function. More...
#include <user_filter.h>
Public Types | |
using | CallbackFunction = FilterCB< Outputs... > |
Callback function type. More... | |
using | ProcessingFunction = std::function< void(const Inputs &..., const CallbackFunction &)> |
Processing function type. More... | |
Public Member Functions | |
void | set_processing_function (const ProcessingFunction &f) noexcept |
Set the user-defined processing function. More... | |
Protected Member Functions | |
void | receive (const Inputs &... in) override |
Process incoming data. More... | |
Private Attributes | |
ProcessingFunction | f_ |
Additional Inherited Members |
Generic filter with user-defined callback function.
You can implement your own filter logic and integrate it with the filter pipeline. For this, you need to define your own function that takes the Inputs and a CallbackFunction as arguments. The function will be called by the generic filter, and expects you to feed back the processed data using the callback function. Typically, your code will look similar to this:
Set up your filter pipeline like this:
In your processing function, you can call the callback function as often as you want, or even not at all. There is no requirement that each input produces exactly one output. When you have no output at all, or the output is the same as the input, you should consider the SimpleUserFilter instead, which is easier to set up.
The filter will throw a std::bad_function_call
exception if it is invoked without a user-defined processing function.
Definition at line 78 of file user_filter.h.
using fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::CallbackFunction = FilterCB<Outputs...> |
Callback function type.
This is the signature of the callback function pointer your processing function will receive.
Definition at line 89 of file user_filter.h.
using fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::ProcessingFunction = std::function<void(const Inputs&..., const CallbackFunction&)> |
Processing function type.
This can be any user-defined function and will be called to process incoming data. The results are expected be returned via the callback function.
Definition at line 95 of file user_filter.h.
|
overrideprotectedvirtual |
Process incoming data.
Derived classes need to override this method to handle all data that is to be consumed by the sink.
Implements fkie_message_filters::Sink< Inputs... >.
Definition at line 35 of file user_filter_impl.h.
|
noexcept |
Set the user-defined processing function.
You must call this method before the filter gets invoked with incoming data.
Definition at line 29 of file user_filter_impl.h.
|
private |
Definition at line 106 of file user_filter.h.