iotile.core.utilities.validating_dispatcher

A class that dispatches messages to handlers based on their schema.

Module Contents

class ValidatingDispatcher

An object that dispatches messages to handlers based on their schema.

add_message_type(self, validator, callback)

Add a message type that should trigger a callback.

Each validator must be unique, in that a message will be dispatched to the first callback whose validator matches the message.

Args:
validator (Verifier): A schema verifier that will
validate a received message uniquely
callback (callable): The function that should be called
when a message that matches validator is received.
dispatch(self, message)

Dispatch a message to a callback based on its schema.

Args:
message (dict): The message to dispatch