bitkeeper revision 1.1050 (40ed36c3QPnXaALAJYdfejK34cJfFA)

Fix problem with message ids.
This commit is contained in:
mjw@wray-m-3.hpl.hp.com committed 2004-07-08 11:57:55 +00:00
1 parent 9873ef8814
commit e7b2e4a624
1 file changed
+48 -15
+48 -15
View File
@@ -1,3 +1,4 @@
import sys
import struct
from xen.lowlevel import xu
@@ -182,17 +183,25 @@ class Msg:
_next_msgid = 0
def nextid():
"""Generate the next message id.
@return: message id
@rtype: int
"""
global _next_msgid
return ++_next_msgid
_next_msgid += 1
return _next_msgid
def packMsg(ty, params):
"""Pack a message.
Any 'mac' parameter is passed in as an int[6] array and converted.
Any I{mac} parameter is passed in as an int[6] array and converted.
ty message type name
params message parameter dict
returns xu message
@param ty: message type name
@type ty: string
@param params: message parameters
@type params: dicy
@return: message
@rtype: xu message
"""
msgid = nextid()
if DEBUG: print '>packMsg', msgid, ty, params
@@ -208,6 +217,7 @@ def packMsg(ty, params):
for (k, v) in args.items():
print 'packMsg>', k, v, type(v)
msg = xu.message(major, minor, msgid, args)
if DEBUG: print '<packMsg', msg.get_header()['id'], ty, params
return msg
def unpackMsg(ty, msg):
@@ -215,10 +225,12 @@ def unpackMsg(ty, msg):
Any mac addresses in the message are converted to int[6] array
in the return dict.
ty message type
msg xu message
returns parameter dict
@param ty: message type
@type ty: string
@param msg: message
@type msg: xu message
@return: parameters
@rtype: dict
"""
args = msg.get_payload()
mac = [0, 0, 0, 0, 0, 0]
@@ -240,15 +252,36 @@ def unpackMsg(ty, msg):
return args
def msgTypeName(ty, subty):
"""Convert a message type, subtype pair (ints) to a message type name (string).
"""Convert a message type, subtype pair to a message type name.
ty integer message type
subty integer message subtype
returns message type name (or None)
@param ty: message type
@type ty: int
@param subty: message subtype
@type ty: int
@return: message type name (or None)
@rtype: string or None
"""
for (name, info) in msg_formats.items():
if info[0] == ty and info[1] == subty:
return name
return None
def printMsg(msg, out=sys.stdout, all=0):
"""Print a message.
@param msg: message
@type msg: xu message
@param out: where to print to
@type out: stream
@param all: print payload if true
@type all: bool
"""
hdr = msg.get_header()
major = hdr['type']
minor = hdr['subtype']
msgid = hdr['id']
ty = msgTypeName(major, minor)
print >>out, 'message:', 'type=', ty, '%d:%d' % (major, minor), 'id=%d' % msgid
if all:
print >>out, 'payload=', unpackMsg(ty, msg)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.