Package emma :: Module events
[hide private]
[frames] | no frames]

Module events

source code

Event support for emma

The events are addressed by Event class, with the event name, interface and identifier of the interface related to it. Any complement can be scubcribed and trigger any event.


Copyright: (c) 2011 hackmeeting http://sindominio.net/hackmeeting

Author: Ruben Pollan

Organization: hackmeeting http://sindominio.net/hackmeeting

Contact: meskio@sindominio.net

License: This program is free software; you can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/projects/COPYING.WTFPL for more details.

Classes [hide private]
  Event
Event addressing class
Functions [hide private]
 
_get_handlers(event) source code
 
trigger(event, data)
Trigger an event on background
source code
 
run_event(event, data)
Run an event waiting for it's result
source code
 
subscribe(event, handler)
Subscribe to an event
source code
 
unsubscribe(event, handler)
Unsubscribe from an event
source code
Variables [hide private]
  _events = {}
  _events_lock = thread.allocate_lock()
Function Details [hide private]

trigger(event, data)

source code 

Trigger an event on background

Execute in a new thread each handler subscribed to the event.

Parameters:
  • event (Event) - event to be triggered, it must have all the elements
  • data (undefined) - the information passed by the event, each event will define it's data structure

Warning: event can not have any None value

run_event(event, data)

source code 

Run an event waiting for it's result

Execute each handler subscribed to the event secuentially getting back the return value of each handler.

Parameters:
  • event (Event) - event to be triggered, it must have all the elements
  • data (undefined) - the information passed by the event, each event will define it's data structure
Returns:
[return value of each event handler]

Warning: event can not have any None value

subscribe(event, handler)

source code 

Subscribe to an event

Set a function to be call if an event is produced. The event can have some (or all) elements undefined, so it was call by any event with the defined elements equals to the subscribed event.

Parameters:
  • event (Event) - event to be triggered
  • handler (fun(event, data)) - function to call if the event is trigger

unsubscribe(event, handler)

source code 

Unsubscribe from an event

Parameters:
  • event (Event) - event used for subscription
  • handler (fun(event, data)) - the function used for subscription

Warning: it is not properly tested might have bugs