API for a generic state machine