Home | History | Annotate | Download | only in jdwp
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 /**
     20  * @author Khen G. Kim
     21  */
     22 
     23 /**
     24  * Created on 10.01.2004
     25  */
     26 package org.apache.harmony.jpda.tests.framework.jdwp;
     27 
     28 import org.apache.harmony.jpda.tests.framework.jdwp.Packet;
     29 
     30 /**
     31  * This class represents JDWP command packet.
     32  */
     33 public class CommandPacket extends Packet {
     34     private final int COMMAND_SET_INDEX = 9;
     35     private final int COMMAND_INDEX     = 10;
     36 
     37     private byte      command_set;
     38     private byte      command;
     39 
     40     /**
     41      * Creates an empty CommandPacket with empty header and no data.
     42      */
     43     public CommandPacket() {
     44         super();
     45     }
     46 
     47     /**
     48      * Creates an empty CommandPacket for specific JDWP command with no data.
     49      */
     50     public CommandPacket(byte commandSet, byte command) {
     51         super();
     52         this.command_set = commandSet;
     53         this.command = command;
     54     }
     55 
     56     /**
     57      * Creates CommandPacket from given array of bytes including header and data sections.
     58      *
     59      * @param bytes_array the JDWP packet, given as array of bytes.
     60      */
     61     public CommandPacket(byte bytes_array[]) {
     62         super(bytes_array);
     63         command_set = bytes_array[COMMAND_SET_INDEX];
     64         command = bytes_array[COMMAND_INDEX];
     65     }
     66 
     67     /**
     68      * Sets command set value of the header of the CommandPacket as byte.
     69      *
     70      * @param val the command set.
     71      */
     72     public void setCommandSet(byte val) {
     73         command_set = val;
     74     }
     75 
     76     /**
     77      * Gets command set value of the header of the CommandPacket as byte.
     78      *
     79      * @return the command set value of the header of the CommandPacket as byte.
     80      */
     81     public byte getCommandSet() {
     82         return command_set;
     83     }
     84 
     85     /**
     86      * Sets command value of the header of the CommandPacket as byte.
     87      *
     88      * @param val the command.
     89      */
     90     public void setCommand(byte val) {
     91         command = val;
     92     }
     93 
     94     /**
     95      * Sets command value of the header of the CommandPacket as byte.
     96      *
     97      * @param commandSet number of the command set.
     98      * @param command number of the command.
     99      */
    100     public void setCommand(byte commandSet, byte command) {
    101         this.command_set = commandSet;
    102         this.command = command;
    103     }
    104 
    105     /**
    106      * Gets command value of the header of the CommandPacket as byte.
    107      *
    108      * @return the command value of the header of the CommandPacket as byte.
    109      */
    110     public byte getCommand() {
    111         return command;
    112     }
    113 
    114     /**
    115      * Gets the representation of the CommandPacket as array of bytes in the
    116      * JDWP format including header and data sections.
    117      *
    118      * @return the representation of the CommandPacket as array of bytes in the
    119      *         JDWP format.
    120      */
    121     @Override
    122     public byte[] toBytesArray() {
    123         byte res[] = super.toBytesArray();
    124         res[COMMAND_SET_INDEX] = command_set;
    125         res[COMMAND_INDEX] = command;
    126         return res;
    127     }
    128 
    129 }