ia64/xen-unstable

changeset 1718:98bb9542a5bc

bitkeeper revision 1.1050 (40ed36c3QPnXaALAJYdfejK34cJfFA)

Fix problem with message ids.
author mjw@wray-m-3.hpl.hp.com
date Thu Jul 08 11:57:55 2004 +0000 (2004-07-08)
parents bae23a1177c6
children 430a2d09d6ad
files tools/python/xen/xend/server/messages.py
line diff
     1.1 --- a/tools/python/xen/xend/server/messages.py	Wed Jul 07 19:33:06 2004 +0000
     1.2 +++ b/tools/python/xen/xend/server/messages.py	Thu Jul 08 11:57:55 2004 +0000
     1.3 @@ -1,3 +1,4 @@
     1.4 +import sys
     1.5  import struct
     1.6  
     1.7  from xen.lowlevel import xu
     1.8 @@ -182,17 +183,25 @@ class Msg:
     1.9  _next_msgid = 0
    1.10  
    1.11  def nextid():
    1.12 +    """Generate the next message id.
    1.13 +
    1.14 +    @return: message id
    1.15 +    @rtype: int
    1.16 +    """
    1.17      global _next_msgid
    1.18 -    return ++_next_msgid
    1.19 +    _next_msgid += 1
    1.20 +    return _next_msgid
    1.21  
    1.22  def packMsg(ty, params):
    1.23      """Pack a message.
    1.24 -    Any 'mac' parameter is passed in as an int[6] array and converted.
    1.25 +    Any I{mac} parameter is passed in as an int[6] array and converted.
    1.26  
    1.27 -    ty     message type name
    1.28 -    params message parameter dict
    1.29 -
    1.30 -    returns xu message
    1.31 +    @param ty: message type name
    1.32 +    @type ty: string
    1.33 +    @param params: message parameters
    1.34 +    @type params: dicy
    1.35 +    @return: message
    1.36 +    @rtype: xu message
    1.37      """
    1.38      msgid = nextid()
    1.39      if DEBUG: print '>packMsg', msgid, ty, params
    1.40 @@ -208,6 +217,7 @@ def packMsg(ty, params):
    1.41          for (k, v) in args.items():
    1.42              print 'packMsg>', k, v, type(v)
    1.43      msg = xu.message(major, minor, msgid, args)
    1.44 +    if DEBUG: print '<packMsg', msg.get_header()['id'], ty, params
    1.45      return msg
    1.46  
    1.47  def unpackMsg(ty, msg):
    1.48 @@ -215,10 +225,12 @@ def unpackMsg(ty, msg):
    1.49      Any mac addresses in the message are converted to int[6] array
    1.50      in the return dict.
    1.51  
    1.52 -    ty  message type
    1.53 -    msg xu message
    1.54 -
    1.55 -    returns parameter dict
    1.56 +    @param ty:  message type
    1.57 +    @type ty: string
    1.58 +    @param msg: message
    1.59 +    @type msg: xu message
    1.60 +    @return: parameters
    1.61 +    @rtype: dict
    1.62      """
    1.63      args = msg.get_payload()
    1.64      mac = [0, 0, 0, 0, 0, 0]
    1.65 @@ -240,15 +252,36 @@ def unpackMsg(ty, msg):
    1.66      return args
    1.67  
    1.68  def msgTypeName(ty, subty):
    1.69 -    """Convert a message type, subtype pair (ints) to a message type name (string).
    1.70 +    """Convert a message type, subtype pair to a message type name.
    1.71  
    1.72 -    ty    integer message type
    1.73 -    subty integer message subtype
    1.74 -
    1.75 -    returns message type name (or None)
    1.76 +    @param ty: message type
    1.77 +    @type ty: int
    1.78 +    @param subty: message subtype
    1.79 +    @type ty: int
    1.80 +    @return: message type name (or None)
    1.81 +    @rtype: string or None
    1.82      """
    1.83      for (name, info) in msg_formats.items():
    1.84          if info[0] == ty and info[1] == subty:
    1.85              return name
    1.86      return None
    1.87  
    1.88 +def printMsg(msg, out=sys.stdout, all=0):
    1.89 +    """Print a message.
    1.90 +
    1.91 +    @param msg: message
    1.92 +    @type msg: xu message
    1.93 +    @param out: where to print to
    1.94 +    @type out: stream
    1.95 +    @param all: print payload if true
    1.96 +    @type all: bool
    1.97 +    """
    1.98 +    hdr = msg.get_header()
    1.99 +    major = hdr['type']
   1.100 +    minor = hdr['subtype']
   1.101 +    msgid = hdr['id']
   1.102 +    ty = msgTypeName(major, minor)
   1.103 +    print >>out, 'message:', 'type=', ty, '%d:%d' % (major, minor), 'id=%d' % msgid
   1.104 +    if all:
   1.105 +        print >>out, 'payload=', unpackMsg(ty, msg)
   1.106 +