Changeset 655

Show
Ignore:
Timestamp:
05/09/08 15:52:34 (7 months ago)
Author:
sylvain
Message:

updated boxes documentation string

Files:

Legend:

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

    r654 r655  
    3131 
    3232class RosterHandler(component):     
    33     Inboxes = {"inbox"              : "headstock.api.contact.Roster instance to be echoed back", 
    34                "control"            : "Shutdown the client stream", 
    35                "jid" :"", 
    36                "ask-activity": "", 
    37                } 
    38      
    39     Outboxes = {"outbox"       : "UNUSED", 
    40                 "signal"       : "Shutdown signal", 
    41                 "message"      : "Message to send", 
    42                 "activity"     : "", } 
     33    Inboxes = {"inbox"        : "headstock.api.contact.Roster instance", 
     34               "control"      : "stops the component", 
     35               "jid"          : "headstock.api.jid.JID instance received from the server", 
     36               "ask-activity" : "request activity status to the server for each roster contact"} 
     37     
     38    Outboxes = {"outbox"      : "UNUSED", 
     39                "signal"      : "Shutdown signal", 
     40                "message"     : "Message to send", 
     41                "activity"    : "headstock.api.activity.Activity instance to send to the server"} 
    4342 
    4443    def __init__(self, from_jid): 
     
    4746        self.roster = None 
    4847 
     48    def initComponents(self): 
     49        # We subscribe to the JID backplane component 
     50        # that will inform us when the server has 
     51        # returned the per-session jid 
     52        sub = SubscribeTo("JID") 
     53        self.link((sub, 'outbox'), (self, 'jid')) 
     54        self.addChildren(sub) 
     55        sub.activate() 
     56 
     57        return 1 
     58 
    4959    def main(self): 
    50         sub = SubscribeTo("JID") 
    51         sub.activate() 
    52         self.link((sub, 'outbox'), (self, 'jid')) 
     60        yield self.initComponents() 
    5361 
    5462        while 1: 
     
    7179                    print "  ", contact.jid 
    7280                     
    73                     # 
    74  
    7581            if self.dataReady('ask-activity'): 
    7682                self.recv('ask-activity') 
     
    8793 
    8894class DummyMessageHandler(component): 
    89     Inboxes = {"inbox"              : "headstock.api.contact.Message instance to be echoed back", 
    90                "control"            : "Shutdown the client stream", 
    91                "jid": "", 
    92                } 
    93      
    94     Outboxes = {"outbox"       : "bridge.Element instance generated from the Message instance", 
    95                 "signal"       : "Shutdown signal", 
    96                 } 
     95    Inboxes = {"inbox"    : "headstock.api.contact.Message instance received from a peer"\ 
     96                   "or the string input in the console", 
     97               "control"  : "stops the component"} 
     98     
     99    Outboxes = {"outbox"  : "headstock.api.im.Message to send to the client", 
     100                "signal"  : "Shutdown signal"} 
    97101 
    98102    def __init__(self): 
     
    100104        self.from_jid = None 
    101105 
    102     def main(self): 
     106    def initComponents(self): 
    103107        sub = SubscribeTo("JID") 
    104108        self.link((sub, 'outbox'), (self, 'jid')) 
     109        self.addChildren(sub) 
    105110        sub.activate() 
    106111 
    107112        sub = SubscribeTo("CONSOLE") 
    108113        self.link((sub, 'outbox'), (self, 'inbox')) 
    109         sub.activate() 
     114        self.addChildren(sub) 
     115        sub.activate() 
     116 
     117        return 1 
     118 
     119    def main(self): 
     120        yield self.initComponents() 
    110121 
    111122        while 1: 
     
    121132            if self.dataReady("inbox"): 
    122133                m = self.recv("inbox") 
     134                # in this first case, we want to send the message 
     135                # typed in the console. 
     136                # The message is of the form: 
     137                #    contant_jid message 
    123138                if isinstance(m, str) and m != '': 
    124                     contact_jid, message = m.split(' ', 1) 
     139                    try: 
     140                        contact_jid, message = m.split(' ', 1) 
     141                    except ValueError: 
     142                        print "Messages format: contact_jid message" 
     143                        continue 
    125144                    m = Message(unicode(self.from_jid), unicode(contact_jid),  
    126145                                type=u'chat', stanza_id=generate_unique()) 
    127                     m.event = Event.composing 
     146                    m.event = Event.composing # note the composing event status 
    128147                    m.bodies.append(Body(unicode(message))) 
    129148                    self.send(m, "outbox") 
     149                     
     150                    # Right after we sent the first message 
     151                    # we send another one reseting the event status 
    130152                    m = Message(unicode(self.from_jid), unicode(contact_jid),  
    131153                                type=u'chat', stanza_id=generate_unique()) 
    132154                    self.send(m, "outbox") 
     155                # In this case we actually received a message 
     156                # from a contact, we print it. 
    133157                elif isinstance(m, Message): 
    134158                    for body in m.bodies: 
     
    141165 
    142166class DiscoHandler(component): 
    143     Inboxes = {"inbox"       : "", 
    144                "control"     : "",  
    145                "initiate"    : "", 
    146                "jid" :"", 
    147                "features.result": "",} 
    148      
    149     Outboxes = {"outbox"        : "", 
    150                 "signal"        : "Shutdown signal", 
    151                 "features-disco": "",   
    152                 "features-announce": ""} 
     167    Inboxes = {"inbox"          : "UNUSED", 
     168               "control"        : "stops the component",  
     169               "initiate"       : "event informing the component the client session is active", 
     170               "jid"            : "headstock.api.jid.JID instance received from the server", 
     171               "features.result": "headstock.api.discovery.FeaturesDiscovery instance from the server",} 
     172     
     173    Outboxes = {"outbox"           : "UNUSED", 
     174                "signal"           : "Shutdown signal", 
     175                "features-disco"   : "headstock.api.discovery.FeaturesDiscovery query to the server",   
     176                "features-announce": "headstock.api.discovery.FeaturesDiscovery informs"\ 
     177                    "the other components about the features instance received from the server"} 
    153178 
    154179    def __init__(self, from_jid, to_jid): 
     
    157182        self.to_jid = to_jid 
    158183 
     184    def initComponents(self): 
     185        sub = SubscribeTo("JID") 
     186        self.link((sub, 'outbox'), (self, 'jid')) 
     187        self.addChildren(sub) 
     188        sub.activate() 
     189 
     190        pub = PublishTo("DISCO_FEAT") 
     191        self.link((self, 'features-announce'), (pub, 'inbox')) 
     192        self.addChildren(sub) 
     193        sub.activate() 
     194 
     195        sub = SubscribeTo("BOUND") 
     196        self.link((sub, 'outbox'), (self, 'initiate')) 
     197        self.addChildren(sub) 
     198        sub.activate() 
     199 
     200        return 1 
     201 
    159202    def main(self): 
    160         sub = SubscribeTo("JID") 
    161         sub.activate() 
    162         self.link((sub, 'outbox'), (self, 'jid')) 
    163  
    164         pub = PublishTo("DISCO_FEAT") 
    165         pub.activate() 
    166         self.link((self, 'features-announce'), (pub, 'inbox')) 
    167  
    168         sub = SubscribeTo("BOUND") 
    169         sub.activate() 
    170         self.link((sub, 'outbox'), (self, 'initiate')) 
     203        yield self.initComponents() 
    171204 
    172205        while 1: 
     
    206239 
    207240class ActivityHandler(component): 
    208     Inboxes = {"inbox"              : "", 
    209                "control"            : "Shutdown the client stream", 
     241    Inboxes = {"inbox"   : "headstock.api.discovery.FeaturesDiscovery instance", 
     242               "control" : "stops the component", 
    210243               } 
    211244     
    212     Outboxes = {"outbox"       : "bridge.Element instance generated from the Message instance", 
    213                 "signal"       : "Shutdown signal", 
    214                 "activity-supported": "", 
     245    Outboxes = {"outbox"            : "UNUSED", 
     246                "signal"            : "Shutdown signal", 
     247                "activity-supported": "when used this tells the RosterHandler it needs"\ 
     248                    "to request the server for each contact's activity."\ 
     249                    "This is only used when the server supports the feature", 
    215250                } 
    216251 
     
    218253        super(ActivityHandler, self).__init__()  
    219254 
     255    def initComponents(self): 
     256        sub = SubscribeTo("DISCO_FEAT") 
     257        self.link((sub, 'outbox'), (self, 'inbox')) 
     258        self.addChildren(sub) 
     259        sub.activate() 
     260         
     261        return 1 
     262 
    220263    def main(self): 
    221         sub = SubscribeTo("DISCO_FEAT") 
    222         sub.activate() 
    223         self.link((sub, 'outbox'), (self, 'inbox')) 
    224  
    225264        while 1: 
    226265            if self.dataReady("control"):