OOP based event handler implementation (nexus511-mod) #831
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I wanted to build some LED-based status information I have been in the need for some more flexible plugin mechanism.
The already implemented callback-mechanism is nice, if you do not plan to extend the functionality by only one hook. So I decided to implement an OOP based approach using an observer pattern which allows to attach multiple listeners to events produced by the printercore.
As I think that this would be also useful for other people using custom external hardware, it would be nice to see this as a general feature of printrun.
A sample implementation of an empty plugin can be found within the plugins folder. It is theoretically possible to attach multiple plugins as a list while each one should of course be carefully implemented to not interfere with the overall performance of the printing-process.
I have been using the patch-set for several month on my own printer on a raspberry-pi. If you see any problems with the patches, please let me know.