Files
Hippolyzer/pyogp/lib/base/tests/message_handler.txt
2009-10-15 21:48:05 +00:00

43 lines
1.1 KiB
Plaintext

"""
Contributors can be viewed at:
http://svn.secondlife.com/svn/linden/projects/2008/pyogp/lib/base/trunk/CONTRIBUTORS.txt
$LicenseInfo:firstyear=2008&license=apachev2$
Copyright 2009, Linden Research, Inc.
Licensed under the Apache License, Version 2.0.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
or in
http://svn.secondlife.com/svn/linden/projects/2008/pyogp/lib/base/LICENSE.txt
$/LicenseInfo$
"""
MessageHandler
~~~~~~~~~~~~~~
The basic message handling event/callbackcase
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First, initialize the packet handler
>>> from pyogp.lib.base.message.message_handler import MessageHandler
>>> message_handler = MessageHandler()
How about a mock callback handler
>>> def callback(packet): print packet
>>> onStartPingCheck_received = message_handler.register("StartPingCheck")
>>> onStartPingCheck_received.subscribe(callback)
Stage a packet
>>> from pyogp.lib.base.message.message import Message
>>> packet = Message('StartPingCheck')
Fire the event, it returns a Message instance
>>> type(message_handler.handle(packet))
>>> Message