Files
Hippolyzer/pyogp/lib/base/tests/message_handler.txt
2009-08-20 22:57:24 +00:00

45 lines
1.3 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$
"""
PacketHandler
~~~~~~~~~~~~~
The basic packet 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 packet
Unpossible to include this in the test, the memory ref keeps changing
But, you get the idea...
event_data = message_handler.handle(packet)
<pyogp.lib.base.message.message.Message object at 0x14da450>