ChunkHandler

public abstract class ChunkHandler
extends JdwpInterceptor

java.lang.Object
   ↳ com.android.tradefed.device.server.jdwp.JdwpInterceptor
     ↳ com.android.tradefed.device.server.jdwp.chunkhandler.ChunkHandler


Subclass this with a class that handles one or more chunk types.

Summary

Constants

int CHUNK_HEADER_LEN

int DDMS_CMD

int DDMS_CMD_SET

Fields

public static final int CHUNK_FAIL

public static final ByteOrder CHUNK_ORDER

Public constructors

ChunkHandler()

Public methods

static ByteBuffer allocBuffer(int maxChunkLen)

Allocate a ByteBuffer with enough space to hold the JDWP packet header and one chunk header in addition to the demands of the chunk being created.

abstract void clientDisconnected(ClientImpl client)

Client has gone away.

abstract void clientReady(ClientImpl client)

Client is ready.

static void finishChunkPacket(JdwpPacket packet, int type, int chunkLen)

Write the chunk header at the start of the chunk.

static ByteBuffer getChunkDataBuf(ByteBuffer jdwpBuf)

Return the slice of the JDWP packet buffer that holds just the chunk data.

abstract void handleChunk(ClientImpl client, int type, ByteBuffer data, boolean isReply, int msgId)

Handle an incoming chunk.

void handlePacket(ClientImpl client, JdwpPacket packet)
JdwpPacket intercept(JdwpAgent agent, JdwpPacket packet)
static int type(String typeName)

Convert a 4-character string to a 32-bit type.

Protected methods

void handleUnknownChunk(ClientImpl client, int type, ByteBuffer data, boolean isReply, int msgId)

Handle chunks not recognized by handlers.

Constants

CHUNK_HEADER_LEN

public static final int CHUNK_HEADER_LEN

Constant Value: 8 (0x00000008)

DDMS_CMD

public static final int DDMS_CMD

Constant Value: 1 (0x00000001)

DDMS_CMD_SET

public static final int DDMS_CMD_SET

Constant Value: 199 (0x000000c7)

Fields

CHUNK_FAIL

public static final int CHUNK_FAIL

CHUNK_ORDER

public static final ByteOrder CHUNK_ORDER

Public constructors

ChunkHandler

public ChunkHandler ()

Public methods

allocBuffer

public static ByteBuffer allocBuffer (int maxChunkLen)

Allocate a ByteBuffer with enough space to hold the JDWP packet header and one chunk header in addition to the demands of the chunk being created.

"maxChunkLen" indicates the size of the chunk contents only.

Parameters
maxChunkLen int

Returns
ByteBuffer

clientDisconnected

public abstract void clientDisconnected (ClientImpl client)

Client has gone away. Can be used to clean up any resources associated with this client connection.

Parameters
client ClientImpl

clientReady

public abstract void clientReady (ClientImpl client)

Client is ready. The monitor thread calls this method on all handlers when the client is determined to be DDM-aware (usually after receiving a HELO response.)

The handler can use this opportunity to initialize client-side activity. Because there's a fair chance we'll want to send a message to the client, this method can throw an IOException.

Parameters
client ClientImpl

finishChunkPacket

public static void finishChunkPacket (JdwpPacket packet, 
                int type, 
                int chunkLen)

Write the chunk header at the start of the chunk.

Pass in the byte buffer returned by JdwpPacket.getPayload().

Parameters
packet JdwpPacket

type int

chunkLen int

getChunkDataBuf

public static ByteBuffer getChunkDataBuf (ByteBuffer jdwpBuf)

Return the slice of the JDWP packet buffer that holds just the chunk data.

Parameters
jdwpBuf ByteBuffer

Returns
ByteBuffer

handleChunk

public abstract void handleChunk (ClientImpl client, 
                int type, 
                ByteBuffer data, 
                boolean isReply, 
                int msgId)

Handle an incoming chunk. The data, of chunk type "type", begins at the start of "data" and continues to data.limit().

If "isReply" is set, then "msgId" will be the ID of the request we sent to the client. Otherwise, it's the ID generated by the client for this event. Note that it's possible to receive chunks in reply packets for which we are not registered.

The handler may not modify the contents of "data".

Parameters
client ClientImpl

type int

data ByteBuffer

isReply boolean

msgId int

handlePacket

public void handlePacket (ClientImpl client, 
                JdwpPacket packet)

Parameters
client ClientImpl

packet JdwpPacket

intercept

public JdwpPacket intercept (JdwpAgent agent, 
                JdwpPacket packet)

Parameters
agent JdwpAgent

packet JdwpPacket

Returns
JdwpPacket

type

public static int type (String typeName)

Convert a 4-character string to a 32-bit type.

Parameters
typeName String

Returns
int

Protected methods

handleUnknownChunk

protected void handleUnknownChunk (ClientImpl client, 
                int type, 
                ByteBuffer data, 
                boolean isReply, 
                int msgId)

Handle chunks not recognized by handlers. The handleChunk() method in sub-classes should call this if the chunk type isn't recognized.

Parameters
client ClientImpl

type int

data ByteBuffer

isReply boolean

msgId int