Package LICOS.core.dispatch.dispatcher


Classes

class  _Parameter
class  _Any
class  _Anonymous

Functions

def connect
def disconnect
def getReceivers
def liveReceivers
def getAllReceivers
def send
def sendExact
def _removeReceiver
def _cleanupConnections
def _removeSender
def _removeBackrefs
def _removeOldBackRefs
def _killBackref

Variables

string __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
string __cvsid__ = "$Id: dispatcher.py,v 1.3 2005/11/16 04:27:12 stuvi Exp $"
string __version__ = "$Revision: 1.3 $"
int True = 1
int False = 1
tuple Any = _Any()
tuple Anonymous = _Anonymous()
tuple WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
dictionary connections = {}
dictionary senders = {}
dictionary sendersBack = {}


Function Documentation

def LICOS.core.dispatch.dispatcher._cleanupConnections   senderkey,
  signal
 

Delete any empty signals for senderkey. Delete senderkey if empty.

Definition at line 399 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher._killBackref   receiver,
  senderkey
 

Do the actual removal of back reference from receiver to senderkey

Definition at line 478 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher._removeBackrefs   senderkey  ) 
 

Remove all back-references to this senderkey

Definition at line 431 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher._removeOldBackRefs   senderkey,
  signal,
  receiver,
  receivers
 

Kill old sendersBack references from receiver

This guards against multiple registration of the same
receiver for a given signal and sender leaking memory
as old back reference records build up.

Also removes old receiver instance from receivers

Definition at line 446 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher._removeReceiver   receiver  ) 
 

Remove receiver from connections.

Definition at line 374 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher._removeSender   senderkey  ) 
 

Remove senderkey from connections.

Definition at line 418 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.connect   receiver,
  signal = Any,
  sender = Any,
  weak = True
 

Connect receiver to sender for signal

receiver -- a callable Python object which is to receive
    messages/signals/events.  Receivers must be hashable
    objects.

    if weak is True, then receiver must be weak-referencable
    (more precisely saferef.safeRef() must be able to create
    a reference to the receiver).

    Receivers are fairly flexible in their specification,
    as the machinery in the robustApply module takes care
    of most of the details regarding figuring out appropriate
    subsets of the sent arguments to apply to a given
    receiver.

    Note:
        if receiver is itself a weak reference (a callable),
        it will be de-referenced by the system's machinery,
        so *generally* weak references are not suitable as
        receivers, though some use might be found for the
        facility whereby a higher-level library passes in
        pre-weakrefed receiver references.

signal -- the signal to which the receiver should respond

    if Any, receiver will receive any signal from the
    indicated sender (which might also be Any, but is not
    necessarily Any).
    
    Otherwise must be a hashable Python object other than
    None (DispatcherError raised on None).
    
sender -- the sender to which the receiver should respond

    if Any, receiver will receive the indicated signals
    from any sender.
    
    if Anonymous, receiver will only receive indicated
    signals from send/sendExact which do not specify a
    sender, or specify Anonymous explicitly as the sender.

    Otherwise can be any python object.
    
weak -- whether to use weak references to the receiver
    By default, the module will attempt to use weak
    references to the receiver objects.  If this parameter
    is false, then strong references will be used.

returns None, may raise DispatcherTypeError

Definition at line 84 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.disconnect   receiver,
  signal = Any,
  sender = Any,
  weak = True
 

Disconnect receiver from sender for signal

receiver -- the registered receiver to disconnect
signal -- the registered signal to disconnect
sender -- the registered sender to disconnect
weak -- the weakref state to disconnect

disconnect reverses the process of connect,
the semantics for the individual elements are
logically equivalent to a tuple of
(receiver, signal, sender, weak) used as a key
to be deleted from the internal routing tables.
(The actual process is slightly more complex
but the semantics are basically the same).

Note:
    Using disconnect is not required to cleanup
    routing when an object is deleted, the framework
    will remove routes for deleted objects
    automatically.  It's only necessary to disconnect
    if you want to stop routing to a live object.
    
returns None, may raise DispatcherTypeError or
    DispatcherKeyError

Definition at line 181 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.getAllReceivers   sender = Any,
  signal = Any
 

Get list of all receivers from global tables

This gets all receivers which should receive
the given signal from sender, each receiver should
be produced only once by the resulting generator

Definition at line 278 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.getReceivers   sender = Any,
  signal = Any
 

Get list of receivers from global tables

This utility function allows you to retrieve the
raw list of receivers from the connections table
for the given sender and signal pair.

Note:
    there is no guarantee that this is the actual list
    stored in the connections table, so the value
    should be treated as a simple iterable/truth value
    rather than, for instance a list to which you
    might append new records.

Normally you would use liveReceivers( getReceivers( ...))
to retrieve the actual receiver objects as an iterable
object.

Definition at line 236 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.liveReceivers   receivers  ) 
 

Filter sequence of receivers to get resolved, live receivers

This is a generator which will iterate over
the passed sequence, checking for weak references
and resolving them, then returning all live
receivers.

Definition at line 259 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.send   signal = Any,
  sender = Anonymous,
  arguments,
  named
 

Send signal from sender to all connected receivers.

signal -- (hashable) signal value, see connect for details

sender -- the sender of the signal

    if Any, only receivers registered for Any will receive
    the message.

    if Anonymous, only receivers registered to receive
    messages from Anonymous or Any will receive the message

    Otherwise can be any python object (normally one
    registered with a connect if you actually want
    something to occur).

arguments -- positional arguments which will be passed to
    *all* receivers. Note that this may raise TypeErrors
    if the receivers do not allow the particular arguments.
    Note also that arguments are applied before named
    arguments, so they should be used with care.

named -- named arguments which will be filtered according
    to the parameters of the receivers to only provide those
    acceptable to the receiver.

Return a list of tuple pairs [(receiver, response), ... ]

if any receiver raises an error, the error propagates back
through send, terminating the dispatch loop, so it is quite
possible to not have all receivers called if a raises an
error.

Definition at line 306 of file dispatcher.py.

def LICOS.core.dispatch.dispatcher.sendExact   signal = Any,
  sender = Anonymous,
  arguments,
  named
 

Send signal only to those receivers registered for exact message

sendExact allows for avoiding Any/Anonymous registered
handlers, sending only to those receivers explicitly
registered for a particular signal on a particular
sender.

Definition at line 353 of file dispatcher.py.


Variable Documentation

string __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>" [static]
 

Definition at line 32 of file dispatcher.py.

string __cvsid__ = "$Id: dispatcher.py,v 1.3 2005/11/16 04:27:12 stuvi Exp $" [static]
 

Definition at line 33 of file dispatcher.py.

string __version__ = "$Revision: 1.3 $" [static]
 

Definition at line 34 of file dispatcher.py.

tuple Anonymous = _Anonymous() [static]
 

Definition at line 75 of file dispatcher.py.

tuple Any = _Any() [static]
 

Definition at line 55 of file dispatcher.py.

dictionary connections = {} [static]
 

Definition at line 79 of file dispatcher.py.

int False = 1 [static]
 

Definition at line 40 of file dispatcher.py.

dictionary senders = {} [static]
 

Definition at line 80 of file dispatcher.py.

dictionary sendersBack = {} [static]
 

Definition at line 81 of file dispatcher.py.

int True = 1 [static]
 

Definition at line 39 of file dispatcher.py.

tuple WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref) [static]
 

Definition at line 77 of file dispatcher.py.


Generated on Thu Apr 27 20:53:00 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO