oysstu / pyimc

Python bindings for Inter-Module Communication Protocol (IMC)
Other
9 stars 6 forks source link

Filtering of incoming messages for subscriptions #4

Open oysstu opened 5 years ago

oysstu commented 5 years ago

When implementing subscriptions to IMC messages, one often has to filter the incoming messages based on some criteria. E.g. if the message are coming from a specific system, or is being sent to a target system, or that the actor is in a certain state

One proposed quality of life improvement wrt. this is the addition of a filtering input to the subscription decorator itself. Usage would look as follows

class TestActor(IMCBase):
    @Subscribe(pyimc.EstimatedState)
    def without_filter(self, msg):
        if msg.src == 0x5501:
            # Do stuff
            ...

    def filter(self, msg):
        return msg.src == 0x5501

    @Subscribe(pyimc.EstimatedState, filter=TestActor.filter)
    def with_filter(self, msg):
        # Do stuff immediately