Refactor URC handling #16
Merged
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.
URCs need to get handled differently, for a couple reasons:
RING
URC, but the current implementation doesn't really allow for that, at least not easily.processURCEvent()
is very long, and adding new handlers requires remembering to updatepruneBacklog()
too (I almost missed it myself).This new implementation splits up
processURCEvent()
into individual handler methods for each URC. In the constructor, those handlers are added to a vector using the newaddURCHandler()
. ThenprocessURCEvent()
simply iterates through each handler, and only returns true if the event gets handled. This enables subclasses to add URC handlers within their constructors, and everything should be happy. This was @gigapod's suggestion, seems to work fine.Additionally,
pruneBacklog()
needs to be aware of what URC strings are "actionable events", so I added a second vector to remember those. They're set when callingaddURCHandler()
.Now to handle a new URC, you must create a method to do so, then add it (and the string it's looking for) with
addURCHandler()
. This should be more maintainable moving forward, and allow subclasses to easily add new URC handlers.