001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.cldchi.tools.memoryprofiler.jdwp;
028:
029: import java.util.Vector;
030:
031: /**
032: * This class represents a JDWP reply packet. This class is widely
033: * used in all parts of KJDB. A typical use of tyhis class is as follows:
034: * <ul>
035: * <li> Prepare JDWP command (see <code>jdwp.Command</code>) for details
036: * <li> Execute the command using <code>BackEndTest.checkReplyF()</code>
037: * method and receive the JDWP reply packet
038: * <li> Use <code>resetDataParser()</code> method before starting reading
039: * packet's data
040: * <li> Read the packet's data using <code>get</code> <code>ByteBuffer</code>
041: * and <code>Packet</code> methods
042: * </ul>
043: *
044: * @see jdwp.Command
045: * @see jdwp.BackEndTest#checkReplyF(jdwp.Command)
046: * @see jdwp.Packet
047: * @see jdwp.Packet#resetDataParser()
048: * @see jdwp.ByteBuffer
049: */
050:
051: class Reply extends Packet implements VMReply {
052:
053: /**
054: * Error code constant that indicates that no error occured.
055: */
056: public final static int errOk = 0x0;
057:
058: /**
059: * Error code constant that indicates that the packet has wrong size.
060: */
061: public final static int errWrongPacketSize = 0x400;
062:
063: /**
064: * Error code constant that indicates that JDWP reply packet is not
065: * received as expected.
066: */
067: public final static int errNotAvailable = 0x401;
068:
069: /**
070: * JDWP Event/Composite command number.
071: */
072: public final static int errEvent = 0x4064;
073:
074: /**
075: * Returns value of the "error code" field of JDWP reply packet.
076: *
077: * @return a error code of JDWP reply
078: */
079: public int getErrorCode() {
080: int err = 0;
081: try {
082: err = (int) getID(ErrorCodeOffset, 2);
083: } catch (BoundException e) {
084: }
085: ;
086: return err;
087: }
088:
089: /**
090: * Sets value of the "error code" field of JDWP reply packet.
091: *
092: * @param err a error code of JDWP reply that should be set
093: */
094:
095: public void setErrorCode(long err) {
096: try {
097: putID(ErrorCodeOffset, err, 2);
098: } catch (BoundException e) {
099: }
100: ;
101: }
102:
103: /**
104: * This method
105: * prepares a JDWP reply packet with specified error code.
106: *
107: * @param ErrorCode a error code of the JDWP reply
108: * @return a JDWP reply with the specified error code
109: */
110:
111: static Reply Error(int ErrorCode) {
112:
113: Reply r = new Reply();
114: r.setLength();
115: r.setID(0);
116: r.setFlags(flReply);
117: r.setErrorCode(ErrorCode);
118: return r;
119: }
120:
121: /**
122: * Returns true if this packet's error code equals zero.
123: *
124: * @return <code>true</code> if the JDWP reply has error code
125: * <code>NONE</code> and <code>false</code> otherwise
126: */
127: public boolean ok() {
128: return (getErrorCode() == errOk);
129: }
130:
131: /**
132: * Returns a string representation of the reply packet. This method
133: * is used by <code>BackEndTest</code> to print all the
134: * replies that were not requested by other parts of code. It's useful
135: * for localizing problems.
136: *
137: * @return a string representation of the reply packet
138: *
139: * @see jdwp.BackEndTest#printReplies()
140: */
141: public String toString() {
142: String s;
143: if (getFlags() == 0)
144: s = "command ";
145: else
146: s = "error code ";
147: return "length " + Tools.Hex(length(), 8) + "\n"
148: + "id " + Tools.Hex(getID(), 8) + "\n"
149: + "flags " + Tools.Hex(getFlags(), 2) + "\n" + s
150: + Tools.Hex(getErrorCode(), 4) + "\n"
151: + super.toString(PacketHeaderSize);
152: }
153: }
|