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



src/inspectorj/agent/agentpackethandler.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   inspectorJ - java profiler                                            *
00003  *   Copyright (C) 2007 by James May
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include "agentpackethandler.h"
00028 
00029 using namespace inspectorj::agent::commandset;            
00030 using namespace inspectorj::jdwp;
00031         
00032 namespace inspectorj {
00033 namespace agent {
00034     
00040 AgentPacketHandler::AgentPacketHandler(JavaVM* vm, JNIEnv *env, jvmtiEnv *jvmti, AgentSocket *socket)
00041     : vm(vm), env(env), jvmti(jvmti), socket(socket)
00042 {   
00043     // initialize the command sets    
00044     createCommandSets(); 
00045 }
00046 
00050 AgentPacketHandler::~AgentPacketHandler()
00051 {
00052     if (vmCmdSet) {
00053         delete vmCmdSet;
00054        // delete refTypeCmdSet;
00055     }
00056 }
00057 
00061 void AgentPacketHandler::createCommandSets()
00062 {
00063     vmCmdSet = new VirtualMachineCmdSet(vm, env, jvmti);
00064     refTypeCmdSet = new ReferenceTypeCmdSet(vm, env, jvmti);
00065     bcCmdSet = new BytecodeCmdSet(vm, env, jvmti);
00066 }
00067 
00071 void AgentPacketHandler::attachCurrentThreadToVM()
00072 {
00073     vm->AttachCurrentThread((void**)&env, NULL);    
00074 }
00075 
00076 
00081 void AgentPacketHandler::writeReply(JDWPReply* reply)
00082 {
00083     if (reply) {
00084         socket->writeReply(reply);
00085     }
00086 }
00087 
00088 
00093 void AgentPacketHandler::processCommand(JDWPCommand *cmd)
00094 {
00095     JDWPCommandSet *cmdSet = getCommandSet(cmd->getCmdSet());
00096     
00097     // Check to see if the command is supported
00098     if (!cmdSet) {
00099         jdwpReplyPacket replyPkt;
00100         replyPkt.len = (jint)11;
00101         replyPkt.id = cmd->getId();
00102         replyPkt.flags = (jbyte)JDWPTRANSPORT_FLAGS_REPLY;
00103         replyPkt.errorCode = (jshort)ERR_NOT_IMPLEMENTED;
00104         
00105         JDWPReply *reply = new JDWPReply(replyPkt);
00106         writeReply(reply);
00107     } else {
00108         cmdSet->process(cmd, boost::bind(&AgentPacketHandler::writeReply, this, _1));  
00109     } 
00110     
00111     delete cmd;
00112 }
00113 
00118 void AgentPacketHandler::setAgentSocket(AgentSocket *& socket)
00119 {
00120     this->socket = socket;
00121 }
00122 
00127 JDWPCommandSet* AgentPacketHandler::getCommandSet(jbyte cmd)
00128 {
00129     switch (cmd) {
00130         /*
00131     CLASS_TYPE_COMMAND_SET = 3,
00132     ARRAY_TYPE_COMMAND_SET = 4,
00133     IF_COMMAND_SET = 5,
00134     METHOD_COMMAND_SET = 6,
00135     OBJECT_REF_COMMAND_SET = 9,
00136     STRING_REF_COMMAND_SET = 10,
00137     THREAD_REF_COMMAND_SET = 11,
00138     THREAD_GROUP_REF_COMMAND_SET = 12,
00139     ARRAY_REF_COMMAND_SET = 13,
00140     CLASS_LDR_REF_COMMAND_SET = 14,
00141     EVENT_REQUEST_COMMAND_SET = 15,
00142     STACK_FRAME_COMMAND_SET = 16,
00143     CLASS_OBJECT_REF_COMMAND_SET = 17,
00144     EVENT_COMMAND_SET = 64,        
00145         
00146         */
00147         case BYTECODE_COMMAND_SET : return bcCmdSet;
00148         case VM_COMMAND_SET : return vmCmdSet;
00149         case REF_TYPE_COMMAND_SET : return refTypeCmdSet;
00150         default: return (JDWPCommandSet*)0;
00151         
00152     }
00153     return vmCmdSet;
00154 }
00155 
00156 } // end namespace agent
00157 } // end namespace inspectorj

Generated on Sun Aug 19 17:07:52 2007 for inspectorJ by  doxygen 1.5.1