Changeset 656

Show
Ignore:
Timestamp:
05/09/08 16:14:30 (7 months ago)
Author:
sylvain
Message:

more doc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • oss/headstock/headstock/example/simplechat/simplechat.py

    r655 r656  
    11# -*- coding: utf-8 -*- 
     2""" 
     3This module is a simple XMPP chat client demonstrating the use of headstock. 
     4Many Kamaelia components are created to manage different XMPP kind of stanzas. 
     5 
     6* RosterHandler: 
     7  * querying the server for the roster list 
     8  * if supported by server, asking for the last activity of each contact 
     9 
     10* DummyMessageHandler: 
     11  * sending a message typed into the console window 
     12  * printing to the console any received messages 
     13 
     14* DiscoHandler:  
     15  * querying for the supported features by the server 
     16  * dispatching the result of the previous query to components interested in that event 
     17 
     18* ActivityHandler: 
     19  * dispatching to the RosterHandler the fact the server supports the feature 
     20 
     21 
     22The actual XMPP client is the Client component that sets up the different 
     23dispatchers and handlers involved by liking each inbox to the expected outbox and 
     24vcie versa. 
     25 
     26""" 
    227from Axon.Component import component 
    328from Kamaelia.Chassis.Graphline import Graphline 
     
    328353 
    329354    def setup(self): 
    330         Backplane("LOGGER").activate() 
     355        # Backplanes are like a global entry points that 
     356        # can be accessible both for publishing and 
     357        # recieving data.  
     358        # In other words, a component interested 
     359        # in advertising to many other components that 
     360        # something happened may link one of its outbox 
     361        # to a PublishTo component's inbox. 
     362        # A component wishing to receive that piece of 
     363        # information will link one of its inbox 
     364        # to the SubscribeTo component's outbox. 
     365        # This helps greatly to make components more 
     366        # loosely connected but also allows for some data 
     367        # to be dispatched at once to many (such as when 
     368        # the server returns the per-session JID that 
     369        # is of interest for most other components). 
    331370        Backplane("CONSOLE").activate() 
    332371        Backplane("JID").activate() 
     372        # Used to inform components that the session is now active 
    333373        Backplane("BOUND").activate() 
     374        # Used to inform components of the supported features 
    334375        Backplane("DISCO_FEAT").activate() 
    335376 
    336377        sub = SubscribeTo("JID") 
    337         sub.activate() 
    338378        self.link((sub, 'outbox'), (self, 'jid')) 
    339  
     379        self.addChildren(sub) 
     380        sub.activate() 
     381 
     382        # We pipe everything typed into the console 
     383        # directly to the console backplane so that 
     384        # every components subscribed to the console 
     385        # backplane inbox will get the typed data and 
     386        # will decide it it's of concern or not. 
    340387        Pipeline(ConsoleReader(), PublishTo('CONSOLE')).activate() 
    341         Pipeline(SubscribeTo("LOGGER"), Logger(path=None, stdout=True)).activate() 
    342  
     388 
     389        # Add two outboxes ro the ClientSteam to support specific features. 
    343390        ClientStream.Outboxes["%s.query" % XMPP_LAST_NS] = "Activity" 
    344391        ClientStream.Outboxes["%s.query" % XMPP_DISCO_INFO_NS] = "Discovery" 
     392 
    345393        self.client = ClientStream(self.jid, self.passwordLookup, use_tls=self.usetls) 
    346394         
    347395        self.graph = Graphline(client = self, 
    348396                               console = SubscribeTo('CONSOLE'), 
    349                                logger = PublishTo("LOGGER"), 
     397                               logger = Logger(path=None, stdout=True), 
    350398                               tcp = TCPClient(self.server, self.port), 
    351399                               xmlparser = XMLIncrParser(),