URCs need to get handled differently, for a couple reasons:
There isn't really a way for subclasses to add new URCs. For instance, the voice class needs to be able to process the RING URC, but the current implementation doesn't really allow for that, at least not easily.
Maintenance is tricky. processURCEvent() is very long, and adding new handlers requires remembering to update pruneBacklog() 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 new addURCHandler(). Then processURCEvent() 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 calling addURCHandler().
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.
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.