added state machine and events handling

Signed-off-by: unknown <boris@boris-PC2.gspaces.com>