I have a project that uses wx pubsub heavily to communicate to various parts of the code. For any given message, it could be of interest to 1 to 5 different subscribers.
In a previous version of the code, I had a very large dictionary of listeners that looked something like:
{"SENSOR_FLIP": "SENSOR FLIPPED",
"ALARM_TRIGGERED": "ALARM TRIGGERED",
etc}
and I would subscribe in the various portions in the code that were interested in those events. The problem started when the code started getting large and there were lists of subscribes in the inits of most objects. It was unwieldy and became an issue of making it difficult to ever change anything about the messages or knowing what was receiving what.
So then I tried standardizing messages to 3 types: TASK, INFORM, and STATUS with an identifier at the beginning to show who sent it (a generalized identifier, so it would send "sensor STATUS" rather than "sensor 17 STATUS". I then subscribed to the general areas I was interested in and let the listener sort through if it was actually interested or not. The problem arose here with the signal "interface TASK" -- there were a bunch and I had every sensor, station, service, alarm, light, etc in the entire system grabbing them and sorting through.
Is there a better way to organize this? All I can think of is going back to specific naming of signals and a group of lists in config that flesh-out what each object is interested in, then doing a map subscribe at the init of each object to each thing in its list.
Any ideas on how to do it better?