pdk.Messaging ($Date: 2002/12/04 10:13:05 $)
index
pdk/Messaging.py

Generalized messaging services.

Allows broadcasting of messages to arbitrary listeners (cf. observer pattern, Signal/Slot architecture of the Qt toolkit), both locally and across a network.

Message IDs are strings (internally, the hash value of each ID string is used for efficiency).

Also features

Notes:

FOG,RH 01.2000,08.2001,10.2002

 
Classes
            
_MessagingRegistry
_MsgIdGenerator
__builtin__.object
_Messaging
Signal
Slot
 
class Signal(_Messaging)
       
  
Method resolution order:
Signal
_Messaging
__builtin__.object

Methods defined here:
__init__(self, messageIdString, sendData=None)
send(self)

Data and non-method functions defined here:
__getstate__ = <built-in function __getstate__>
__slots__ = ['sendData']
sendData = <member 'sendData' of 'Signal' objects>
 
class Slot(_Messaging)
     
Purpose:receive a message from another object
Detail:sets up a slot for the message ID messageIdString and object obj. Message payload data can be received by specifying receiveFunc. Note that only a weak reference to the slot object obj is stored.

 
  
Method resolution order:
Slot
_Messaging
__builtin__.object

Methods defined here:
__init__(self, messageId, obj, receiveFunction=None, rank=None)
receive(self, *argT, **optionD)
calls the specified receive function of the slot with argT and optionD as positional and keyword argumentds, respectively.

Properties defined here:
slotObject
slotObject getter = __getObject(self)
returns a reference to the object passed to the constructor. Note that this returns None if the object has been deleted in the meantime.

Data and non-method functions defined here:
__getstate__ = <built-in function __getstate__>
__slots__ = ['slotObject', 'slotObjectReference', 'receiveFunction', 'receiveWithMethod', 'rank']
rank = <member 'rank' of 'Slot' objects>
receiveFunction = <member 'receiveFunction' of 'Slot' objects>
receiveWithMethod = <member 'receiveWithMethod' of 'Slot' objects>
slotObjectReference = <member 'slotObjectReference' of 'Slot' objects>
 
class _Messaging(__builtin__.object)
       
   Methods defined here:
__init__(self, messageIdString)

Data and non-method functions defined here:
__getstate__ = <built-in function __getstate__>
__slots__ = ['messageIdString', 'messageId']
messageId = <member 'messageId' of '_Messaging' objects>
messageIdString = <member 'messageIdString' of '_Messaging' objects>
 
class _MsgIdGenerator
     
Purpose: generates unique message IDs

 
   Methods defined here:
newId(self, text=None)
newIds(self, n, text=None)
 
class _MessagingRegistry
     
Purpose:global registry for setting up slignal/slot connections
Detail:

the messaging registry is instantiated as a singleton. Messages are sent as a signal and received by one or several slots. Slots have to be registered with the .registerSlot method. When a message is sent (by calling the .sendSignal method or indirectly via the SENDSIGNAL method)

  1. the .Signal.send method of the signal is called, which possibly returns the "message payload" data (i.e., arbitrary data to be passed to the receiving slot(s))
  2. the list of slots connected to the signal is traversed (in the order of the rank(s) defined by some or all of the slots) and non-None client data are passed to the ._Messaging.receive method of each slot

Note that only weak references to the messaging objects are kept.


 
   Methods defined here:
registerSlot(self, slot, remote=None)
registers the slot slot to respond to incoming signals. Note that any message ID:object pair uniquely identifies one slot (i.e., when two slots with identical message id and object are registered, the second _replaces_ the first). Note that slots are un-registered automatically whenever the object that is referenced in the slot is being destroyed (by virtue of using a weakref.WeakKeyDictionary for managing the slots).
sendSignal(self, signal)
main signalling routine to call all slots associated with the signal signal, possibly sorted by the rank of each slot.
unregisterSlot(self, slot)
explicitly removes the registered slot slot. Will raise a KeyError, if no such slot is found. Note that this does not need to be called in the usual case where we want a slot to be unregistered when its associated object is destroyed.
 
Functions
            
REGISTERSLOT(messageIdString, obj, receiveFunction=None, rank=None, remote=0)
Purpose:create a slot that responds to a message type
Detail:convenience function to create a slot for obj to respond to messages of id messageIdString, possibly receiving data from the sender with the callable receiveFunction. rank determines the processing order in case more than one slot is defined for messageId; if rank is not specified, processing order is random.
SENDSIGNAL(messageIdString, sendData=None)
Purpose:broadcast a message
Detail:convenience function to broadcast a message with ID messageId and send data sendData from an object object. All slots that have been configured previously to respond to messages of ID messageId will be notified. See the _MessageRegistry class for more details
UNREGISTERSLOT(messageIdString, obj)
Purpose:explicit removal of a slot for message id messageIdString and obj previously created with REGISTERSLOT
Detail:calling this is only necessary if obj is kept alive but should not receive any more messages.
new_message_id = newId(self, text=None) method of _MsgIdGenerator instance
new_message_ids = newIds(self, n, text=None) method of _MsgIdGenerator instance
register_slot = registerSlot(self, slot, remote=None) method of _MessagingRegistry instance
send_signal = sendSignal(self, signal) method of _MessagingRegistry instance
unregister_slot = unregisterSlot(self, slot) method of _MessagingRegistry instance
 
Data
             MSG_OK = 'msg_ok'
MSG_CANCEL = 'msg_cancel'
MSG_CLOSE = 'msg_close'
MSG_KEYPRESSED = 'msg_keypressed'
MSG_EXIT = 'msg_exit'
 
Author
            
$Author: gathmann $