Changeset 656
- Timestamp:
- 05/09/08 16:14:30 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oss/headstock/headstock/example/simplechat/simplechat.py
r655 r656 1 1 # -*- coding: utf-8 -*- 2 """ 3 This module is a simple XMPP chat client demonstrating the use of headstock. 4 Many 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 22 The actual XMPP client is the Client component that sets up the different 23 dispatchers and handlers involved by liking each inbox to the expected outbox and 24 vcie versa. 25 26 """ 2 27 from Axon.Component import component 3 28 from Kamaelia.Chassis.Graphline import Graphline … … 328 353 329 354 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). 331 370 Backplane("CONSOLE").activate() 332 371 Backplane("JID").activate() 372 # Used to inform components that the session is now active 333 373 Backplane("BOUND").activate() 374 # Used to inform components of the supported features 334 375 Backplane("DISCO_FEAT").activate() 335 376 336 377 sub = SubscribeTo("JID") 337 sub.activate()338 378 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. 340 387 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. 343 390 ClientStream.Outboxes["%s.query" % XMPP_LAST_NS] = "Activity" 344 391 ClientStream.Outboxes["%s.query" % XMPP_DISCO_INFO_NS] = "Discovery" 392 345 393 self.client = ClientStream(self.jid, self.passwordLookup, use_tls=self.usetls) 346 394 347 395 self.graph = Graphline(client = self, 348 396 console = SubscribeTo('CONSOLE'), 349 logger = PublishTo("LOGGER"),397 logger = Logger(path=None, stdout=True), 350 398 tcp = TCPClient(self.server, self.port), 351 399 xmlparser = XMLIncrParser(),
