ij-16.png   inspectorJ -- JavaTM Profiler
sf project site browse source checkout source
SourceForge.net Logo



inspectorj::client::ClientPacketHandler Class Reference

#include <clientpackethandler.h>

Collaboration diagram for inspectorj::client::ClientPacketHandler:

Collaboration graph
[legend]
List of all members.

Detailed Description

ClientPacketHandler class is responsible for low level handling of jdwp packets.

ClientPacketHandler handles reading and writing packets to the socket and dispatching incoming replies to the correct actions.

The JDWP protocol is stateless and asynchronous. Therefore commands and replies must be paired by using a common id. ClientPacketHandler manages this by storing one or more callback actions when sending a command. The callbacks are mapped to the command's id. When a reply is received, any callback actions that are mapped to the reply's id are retreived and triggered. The reply packet is passed as a parameter to the callback action's trigger function.

Definition at line 63 of file clientpackethandler.h.

Public Member Functions

 ClientPacketHandler (QTcpSocket &)
 Constructor.
void readJDWPPacket ()
 Read a packet from the profiler server.
void sendJDWPCommand (JDWPCommand *, QList< JDWPAction * > &)
 Send a command to the profiler server.
void getHandshake (bool &attached, QString &msg)
 Get the handshake response from the profiler server.
void getSocketError (QAbstractSocket::SocketError error, QString &errMsg)
 Get an error message describing the SocketError.

Static Public Member Functions

static void getJDWPError (int errCode, QString &s)
 Evaluate the errorCode returned by a jdwpReplyPacket.
static bool handleJDWPError (JDWPPacket &packet)
 Handle errors, if any, returned by jdwpReplyPackets.

Private Slots

void initIdSizes (JDWPPacket &)
 Initialize the static id sizes after we are connected.

Private Member Functions

void operator>> (QString &s)
 Reads string data from the socket.
void handleResponse (JDWPPacket &)
 Retrieve the Callback actions that are mapped to the id of the JDWPPacket.

Private Attributes

JDWPActioninitIdSizesAction
 JDWPAction to initialize the JDWP ID sizes when attached.
QMultiMap< int, JDWPAction * > replyCallbackMap
 A map that holds the callback actions.
QTcpSocket & tcpSocket
 The socket used to communicate with the profiler server.
quint32 packetSize
 The size of the incoming packet.


Constructor & Destructor Documentation

ClientPacketHandler::ClientPacketHandler ( QTcpSocket &  socket  ) 

Constructor.

Parameters:
socket The QTcpSocket used for the connection to the profiler server.

Definition at line 39 of file clientpackethandler.cpp.

References initIdSizes(), and initIdSizesAction.


Member Function Documentation

void ClientPacketHandler::readJDWPPacket (  ) 

Read a packet from the profiler server.

The packet may be a jdwpReplyPacket or a jdwpCmdPacket. After reading the complete packet, the packet will be passed to handleResponse(JDWPPacket).

Definition at line 85 of file clientpackethandler.cpp.

References handleResponse(), inspectorj::jdwp::JDWP_HEADER_LENGTH, packetSize, and tcpSocket.

Referenced by inspectorj::client::ConnectionManager::readPacket().

void ClientPacketHandler::sendJDWPCommand ( JDWPCommand cmd,
QList< JDWPAction * > &  actions 
)

Send a command to the profiler server.

The CallbackFunctor(s) are stored and mapped to the command's id so they can be invoked when a jdwpReplyPacket is received from the server that has a matching id.

Parameters:
cmd The JDWPCommand to be sent
actions The list of actions to be invoked when a reply to this command is received.

Definition at line 55 of file clientpackethandler.cpp.

References inspectorj::jdwp::JDWPCommand::getCmd(), inspectorj::jdwp::JDWPCommand::getCmdSet(), inspectorj::jdwp::JDWPPacket::getDataBytes(), inspectorj::jdwp::JDWPCommand::getId(), inspectorj::jdwp::JDWPPacket::getLength(), inspectorj::jdwp::JDWPCommand::getPacketType(), inspectorj::jdwp::JDWP_HEADER_LENGTH, replyCallbackMap, and tcpSocket.

Referenced by getHandshake(), and inspectorj::client::ConnectionManager::sendRequest().

void ClientPacketHandler::getHandshake ( bool &  attached,
QString &  msg 
)

Get the handshake response from the profiler server.

This function is called when there is incoming data to read and we are not yet attached to the server. Note: attached and connected are different in this context. Connected means that we've established a TCP connection. Attached means we've successfully performed a handshake with the server.

Definition at line 180 of file clientpackethandler.cpp.

References initIdSizesAction, inspectorj::jdwp::JDWP_HANDSHAKE, inspectorj::jdwp::JDWP_HANDSHAKE_LENGTH, sendJDWPCommand(), and tcpSocket.

Referenced by inspectorj::client::ConnectionManager::receiveHandshake().

void ClientPacketHandler::getJDWPError ( int  errCode,
QString &  s 
) [static]

Evaluate the errorCode returned by a jdwpReplyPacket.

The errorCodes are defined in jdwpconstants.h

Parameters:
errCode the errorCode
s a QString reference to store the error string in
See also:
jdwpconstants.h

Definition at line 310 of file clientpackethandler.cpp.

References inspectorj::jdwp::ERR_ABSENT_INFORMATION, inspectorj::jdwp::ERR_ACCESS_DENIED, inspectorj::jdwp::ERR_ADD_METHOD_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_ALREADY_INVOKING, inspectorj::jdwp::ERR_CIRCULAR_CLASS_DEFINITION, inspectorj::jdwp::ERR_CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_CLASS_NOT_PREPARED, inspectorj::jdwp::ERR_DELETE_METHOD_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_DUPLICATE, inspectorj::jdwp::ERR_FAILS_VERIFICATION, inspectorj::jdwp::ERR_HIERARCHY_CHANGE_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_ILLEGAL_ARGUMENT, inspectorj::jdwp::ERR_INTERNAL, inspectorj::jdwp::ERR_INTERRUPT, inspectorj::jdwp::ERR_INVALID_ARRAY, inspectorj::jdwp::ERR_INVALID_CLASS, inspectorj::jdwp::ERR_INVALID_CLASS_FORMAT, inspectorj::jdwp::ERR_INVALID_CLASS_LOADER, inspectorj::jdwp::ERR_INVALID_COUNT, inspectorj::jdwp::ERR_INVALID_EVENT_TYPE, inspectorj::jdwp::ERR_INVALID_FIELDID, inspectorj::jdwp::ERR_INVALID_FRAMEID, inspectorj::jdwp::ERR_INVALID_INDEX, inspectorj::jdwp::ERR_INVALID_LENGTH, inspectorj::jdwp::ERR_INVALID_LOCATION, inspectorj::jdwp::ERR_INVALID_METHODID, inspectorj::jdwp::ERR_INVALID_MONITOR, inspectorj::jdwp::ERR_INVALID_OBJECT, inspectorj::jdwp::ERR_INVALID_PRIORITY, inspectorj::jdwp::ERR_INVALID_SLOT, inspectorj::jdwp::ERR_INVALID_STRING, inspectorj::jdwp::ERR_INVALID_TAG, inspectorj::jdwp::ERR_INVALID_THREAD, inspectorj::jdwp::ERR_INVALID_THREAD_GROUP, inspectorj::jdwp::ERR_INVALID_TYPESTATE, inspectorj::jdwp::ERR_METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_NAMES_DONT_MATCH, inspectorj::jdwp::ERR_NATIVE_METHOD, inspectorj::jdwp::ERR_NO_MORE_FRAMES, inspectorj::jdwp::ERR_NONE, inspectorj::jdwp::ERR_NOT_CURRENT_FRAME, inspectorj::jdwp::ERR_NOT_FOUND, inspectorj::jdwp::ERR_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_NOT_MONITOR_OWNER, inspectorj::jdwp::ERR_NULL_POINTER, inspectorj::jdwp::ERR_OPAQUE_FRAME, inspectorj::jdwp::ERR_OUT_OF_MEMORY, inspectorj::jdwp::ERR_SCHEMA_CHANGE_NOT_IMPLEMENTED, inspectorj::jdwp::ERR_THREAD_NOT_SUSPENDED, inspectorj::jdwp::ERR_THREAD_SUSPENDED, inspectorj::jdwp::ERR_TRANSPORT_INIT, inspectorj::jdwp::ERR_TRANSPORT_LOAD, inspectorj::jdwp::ERR_TYPE_MISMATCH, inspectorj::jdwp::ERR_UNATTACHED_THREAD, inspectorj::jdwp::ERR_UNSUPPORTED_VERSION, and inspectorj::jdwp::ERR_VM_DEAD.

bool ClientPacketHandler::handleJDWPError ( JDWPPacket packet  )  [static]

Handle errors, if any, returned by jdwpReplyPackets.

Parameters:
packet A JDWPPacet that will be checked for errors.

Definition at line 288 of file clientpackethandler.cpp.

References inspectorj::jdwp::ERR_NONE, inspectorj::jdwp::JDWPPacket::getErrorCode(), and inspectorj::jdwp::getJDWPError().

Referenced by inspectorj::model::JavaClass::setFields(), inspectorj::model::JavaClass::setMethods(), and inspectorj::client::InspectorJ::showJvmInfo().

void ClientPacketHandler::getSocketError ( QAbstractSocket::SocketError  error,
QString &  errMsg 
)

Get an error message describing the SocketError.

Store the message in errMsg reference.

Parameters:
error The SocketError
errMsg The QString reference to store the error message
See also:
QAbstractSocket::SocketError

Definition at line 265 of file clientpackethandler.cpp.

Referenced by inspectorj::client::ConnectionManager::error().

void ClientPacketHandler::operator>> ( QString &  s  )  [private]

Reads string data from the socket.

The string data is stored as a QString in s.

Parameters:
s The QString reference that will hold the string data.

Definition at line 239 of file clientpackethandler.cpp.

References tcpSocket.

void ClientPacketHandler::handleResponse ( JDWPPacket reply  )  [private]

Retrieve the Callback actions that are mapped to the id of the JDWPPacket.

The packet will be passed to the action's trigger function.

Parameters:
reply The JDWPPacket for the action's data

Definition at line 160 of file clientpackethandler.cpp.

References inspectorj::jdwp::JDWPPacket::getId(), and replyCallbackMap.

Referenced by readJDWPPacket().

void ClientPacketHandler::initIdSizes ( JDWPPacket reply  )  [private, slot]

Initialize the static id sizes after we are connected.

These sizes vary depending on the jvm implementation.

Definition at line 228 of file clientpackethandler.cpp.

Referenced by ClientPacketHandler().


Member Data Documentation

JDWPAction* inspectorj::client::ClientPacketHandler::initIdSizesAction [private]

JDWPAction to initialize the JDWP ID sizes when attached.

Definition at line 78 of file clientpackethandler.h.

Referenced by ClientPacketHandler(), and getHandshake().

QMultiMap<int, JDWPAction* > inspectorj::client::ClientPacketHandler::replyCallbackMap [private]

A map that holds the callback actions.

Definition at line 81 of file clientpackethandler.h.

Referenced by handleResponse(), and sendJDWPCommand().

QTcpSocket& inspectorj::client::ClientPacketHandler::tcpSocket [private]

The socket used to communicate with the profiler server.

Definition at line 84 of file clientpackethandler.h.

Referenced by getHandshake(), operator>>(), readJDWPPacket(), and sendJDWPCommand().

quint32 inspectorj::client::ClientPacketHandler::packetSize [private]

The size of the incoming packet.

Definition at line 87 of file clientpackethandler.h.

Referenced by readJDWPPacket().


The documentation for this class was generated from the following files:
Generated on Sun Aug 19 17:08:15 2007 for inspectorJ by  doxygen 1.5.1