Source for gnu.classpath.jdwp.transport.JdwpCommandPacket

   1: /* JdwpCommandPacket.java -- JDWP command packet
   2:    Copyright (C) 2005 Free Software Foundation
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: 
  40: package gnu.classpath.jdwp.transport;
  41: 
  42: import java.io.DataOutputStream;
  43: import java.io.IOException;
  44: 
  45: /**
  46:  * A class representing a JDWP command packet.
  47:  * This class adds command set and command to the packet header
  48:  * information in {@link gnu.classpath.jdwp.transport.JdwpPacket}
  49:  * and adds additional command packet-specific processing.
  50:  *
  51:  * @author Keith Seitz  <keiths@redhat.com>
  52:  */
  53: public class JdwpCommandPacket extends JdwpPacket
  54: {
  55:   /**
  56:    * Command set
  57:    */
  58:   protected byte _commandSet;
  59: 
  60:   /**
  61:    * Command
  62:    */
  63:   protected byte _command;
  64: 
  65:   // Minimum packet size [excluding super class]
  66:   // ( commandSet (1) + command (1) )
  67:   private static final int MINIMUM_LENGTH = 2;
  68: 
  69:   /**
  70:    * Constructs a new <code>JdwpCommandPacket</code>
  71:    */
  72:   public JdwpCommandPacket ()
  73:   {
  74:     // Don't assign an id. This constructor is called by
  75:     // JdwpPacket.fromBytes, and that will assign a packet id.
  76:   }
  77: 
  78:   /**
  79:    * Constructs a new <code>JdwpCommandPacket</code>
  80:    * with the given command set and command
  81:    *
  82:    * @param set      the command set
  83:    * @param command  the command
  84:    */
  85:   public JdwpCommandPacket (byte set, byte command)
  86:   {
  87:     _id = ++_last_id;
  88:     _commandSet = set;
  89:     _command = command;
  90:   }
  91: 
  92:   /**
  93:    * Retuns the length of this packet
  94:    */
  95:   public int getLength ()
  96:   {
  97:     return MINIMUM_LENGTH + super.getLength ();
  98:   }
  99: 
 100:   /**
 101:    * Returns the command set
 102:    */
 103:   public byte getCommandSet ()
 104:   {
 105:     return _commandSet;
 106:   }
 107: 
 108:   /**
 109:    * Sets the command set
 110:    */
 111:   public void setCommandSet (byte cs)
 112:   {
 113:     _commandSet = cs;
 114:   }
 115: 
 116:   /**
 117:    * Returns the command
 118:    */
 119:   public byte getCommand ()
 120:   {
 121:     return _command;
 122:   }
 123: 
 124:   /**
 125:    * Sets the command
 126:    */
 127:   public void setCommand (byte cmd)
 128:   {
 129:     _command = cmd;
 130:   }
 131: 
 132:   // Reads command packet data from the given buffer, starting
 133:   // at the given offset
 134:   protected int myFromBytes (byte[] bytes, int index)
 135:   {
 136:     int i = 0;
 137:     setCommandSet (bytes[index + i++]);
 138:     setCommand (bytes[index + i++]);
 139:     return i;
 140:   }
 141: 
 142:   // Writes the command packet data into the given buffer
 143:   protected void myWrite (DataOutputStream dos)
 144:     throws IOException
 145:   {
 146:     dos.writeByte (getCommandSet ());
 147:     dos.writeByte (getCommand ());
 148:   }
 149: }