[Jsmooth-cvs] jsmooth/skeletons/commonjava JVMBase.cpp, 1.1, 1.2 JVMBase.h, 1.1, 1.2 JavaMachineMan
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-05-26 11:24:41
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8035 Modified Files: JVMBase.cpp JVMBase.h JavaMachineManager.cpp JavaMachineManager.h Makefile.win ResourceManager.cpp ResourceManager.h SunJVMDLL.cpp SunJVMDLL.h SunJVMExe.cpp SunJVMLauncher.cpp SunJVMLauncher.h Removed Files: JniSmooth.cpp JniSmooth.h Log Message: jnismooth and splash refactoring Index: JavaMachineManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** JavaMachineManager.cpp 13 May 2007 19:56:35 -0000 1.19 --- JavaMachineManager.cpp 26 May 2007 11:24:36 -0000 1.20 *************** *** 60,72 **** return true; } - - // DEBUG("Trying to use bundled VM " + m_localVM.JavaHome); - // if (m_localVM.runProc(m_resman, m_useConsole, "bundled")) - // { - // m_exitCode = m_localVM.getExitCode(); - // return true; - // } - // if (m_localVM.run(m_resman, "bundled")) - // return true; } --- 60,63 ---- *************** *** 134,137 **** --- 125,131 ---- SunJVMLauncher launcher; + for(int i=0; i<m_listeners.size(); i++) + launcher.addListener(m_listeners[i]); + if (launcher.runProc(m_resman, m_useConsole, "path")) { *************** *** 149,152 **** --- 143,152 ---- bool JavaMachineManager::internalRun(SunJVMLauncher& launcher, const string& org) { + DEBUG("JavaMachineManager: setting " + StringUtils::toString(m_jnireg.size()) + " JNI libs"); + launcher.setJNI(m_jnireg); + + for(int i=0; i<m_listeners.size(); i++) + launcher.addListener(m_listeners[i]); + if (m_acceptDLL && m_preferDLL) { *************** *** 189,192 **** --- 189,193 ---- DEBUG("- Trying registry: " + m_registryVms[i].toString()); + m_registryVms[i].setJNI(m_jnireg); bool res = m_registryVms[i].run(m_resman, "registry", justInstanciate); *************** *** 222,223 **** --- 223,229 ---- return m_exitCode; } + + void JavaMachineManager::setJNI(vector<JNIRegister*> reg) + { + m_jnireg = reg; + } Index: SunJVMDLL.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMDLL.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SunJVMDLL.cpp 18 May 2007 21:33:59 -0000 1.4 --- SunJVMDLL.cpp 26 May 2007 11:24:36 -0000 1.5 *************** *** 23,27 **** #include "JClassProxy.h" ! #include "JniSmooth.h" SunJVMDLL::SunJVMDLL(const std::string& jvmdll, const Version& v) --- 23,27 ---- #include "JClassProxy.h" ! ////#include "JniSmooth.h" SunJVMDLL::SunJVMDLL(const std::string& jvmdll, const Version& v) *************** *** 59,62 **** --- 59,69 ---- ma[0].l = mainargs; disp.invokeStatic(std::string("void main(java.lang.String[] args)"), ma); + DEBUG("main class invoked"); + + if (env()->ExceptionOccurred()) + { + env()->ExceptionDescribe(); + } + if (waitDeath == true) m_javavm->DestroyJavaVM(); *************** *** 104,112 **** res = setupVM12DLL(CreateJavaVM, GetDefaultJavaVMInitArgs); ! registerJniSmooth(); DEBUG("Result code on DLL: " + StringUtils::toString(res)); if (res) { m_statusCode = SunJVMDLL::JVM_LOADED; return true; --- 111,130 ---- res = setupVM12DLL(CreateJavaVM, GetDefaultJavaVMInitArgs); ! // ! // registerJniSmooth(); ! DEBUG("Registration of " + StringUtils::toString(m_jnireg.size()) + " JNI libraries"); ! for (int i=0; i<m_jnireg.size(); i++) ! { ! JNIRegister* reg = m_jnireg[i]; ! reg->registerJNI(this); ! } DEBUG("Result code on DLL: " + StringUtils::toString(res)); if (res) { + // + // Call the JVM listeners + callListeners(GetCurrentProcessId()); + m_statusCode = SunJVMDLL::JVM_LOADED; return true; *************** *** 240,243 **** --- 258,278 ---- } + jmethodID SunJVMDLL::findMethod(const std::string& clsname, const std::string& methodname, const std::string& signature, bool isStatic) + { + jclass cls = findClass(clsname); + if (cls == 0) + return NULL; + + std::string sig = StringUtils::replace(signature, ".", "/"); + + jmethodID mid; + if (isStatic) + mid = env()->GetStaticMethodID(cls, methodname.c_str(), sig.c_str()); + else + mid = env()->GetMethodID(cls, methodname.c_str(), sig.c_str()); + + return mid; + } + JavaVM* SunJVMDLL::getJavaVM() { *************** *** 397,403 **** void* fn) { jclass cc = this->findClass(classname); if (cc == 0) ! return false; JNINativeMethod jnm; jnm.name = (char*)methodname.c_str(); --- 432,442 ---- void* fn) { + DEBUG("Registering JNI " + classname + "::" + methodname + "::" + signature); jclass cc = this->findClass(classname); if (cc == 0) ! { ! DEBUG("Error registering JNI " + classname + "::" + methodname + ": class not found"); ! return false; ! } JNINativeMethod jnm; jnm.name = (char*)methodname.c_str(); *************** *** 407,418 **** int res = env()->RegisterNatives(cc, &jnm, 1); if (res != 0) ! return false; return true; } ! bool SunJVMDLL::registerJniSmooth() { ! registerNativeMethods(this); ! return true; } --- 446,467 ---- int res = env()->RegisterNatives(cc, &jnm, 1); if (res != 0) ! { ! DEBUG("Error registering JNI " + classname + "::" + methodname + ": failed for some reason"); ! return false; ! } return true; } ! // bool SunJVMDLL::registerJniSmooth() ! // { ! // registerNativeMethods(this); ! // return true; ! // } ! ! ! void SunJVMDLL::setJNI(vector<JNIRegister*> reg) { ! m_jnireg = reg; ! DEBUG("SunJVMDLL: Got " + StringUtils::toString(m_jnireg.size()) + " JNI libs"); } Index: ResourceManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ResourceManager.h 18 May 2007 21:33:59 -0000 1.15 --- ResourceManager.h 26 May 2007 11:24:36 -0000 1.16 *************** *** 57,60 **** --- 57,61 ---- int m_resourcePropsId; int m_resourceJarId; + int m_resourceJniId; std::string m_lastError; HGLOBAL m_jarHandler; Index: SunJVMDLL.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMDLL.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SunJVMDLL.h 18 May 2007 21:33:59 -0000 1.3 --- SunJVMDLL.h 26 May 2007 11:24:36 -0000 1.4 *************** *** 31,34 **** --- 31,35 ---- #include "JavaProperty.h" #include "JVMBase.h" + #include "JNIRegister.h" typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, JNIEnv **env, void *args); *************** *** 64,67 **** --- 65,70 ---- StatusCode m_statusCode; + + vector<JNIRegister*> m_jnireg; protected: *************** *** 79,83 **** bool registerMethod(const std::string& classname, const std::string& methodname, const std::string& signature, void* fn); ! bool registerJniSmooth(); JNIEnv* env() --- 82,87 ---- bool registerMethod(const std::string& classname, const std::string& methodname, const std::string& signature, void* fn); ! // bool registerJniSmooth(); ! void setJNI(vector<JNIRegister*> reg); JNIEnv* env() *************** *** 93,96 **** --- 97,101 ---- jclass findClass(const std::string& clazz); jmethodID findMethod(jclass& cls, const std::string& methodname, const std::string& signature, bool isStatic); + jmethodID findMethod(const std::string& clsname, const std::string& methodname, const std::string& signature, bool isStatic); JavaVM* getJavaVM(); Index: SunJVMLauncher.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** SunJVMLauncher.h 13 May 2007 19:56:35 -0000 1.15 --- SunJVMLauncher.h 26 May 2007 11:24:36 -0000 1.16 *************** *** 33,36 **** --- 33,37 ---- #include "SunJVMDLL.h" #include "SunJVMExe.h" + #include "JNIRegister.h" typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, JNIEnv **env, void *args); *************** *** 59,62 **** --- 60,64 ---- int LaunchingStatus; + vector<JNIRegister*> m_jnireg; protected: *************** *** 112,116 **** * false otherwise. */ - virtual bool runProc(ResourceManager& resource, bool noConsole, const string& origin); --- 114,117 ---- *************** *** 121,124 **** --- 122,126 ---- std::string toString() const; + void setJNI(vector<JNIRegister*> reg); friend bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2); *************** *** 126,163 **** int getExitCode(); ! ! ! ! // Version guessVersionByProcess(const string& exepath); ! ! ! ! // bool runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const std::string& version, const string& origin); ! // bool dllInstanciate(ResourceManager& resource, const string& origin); ! ! // bool callDLLStaticMethod(const std::string& classname, const std::string& methodname, const std::string& signature); ! // bool callDLLStaticMethodInt(const std::string& classname, const std::string& methodname, const std::string& signature, int value); ! ! // int destroyVM(); ! // JavaVM* getJavaVM(); ! ! // jclass findClass(const std::string& clazz); ! // jmethodID findMethod(jclass& cls, const std::string& methodname, const std::string& signature, bool isStatic); ! ! // void invokeVoidStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]); ! // // jvaluea invokeIntStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]); ! // jint invokeIntStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]); ! // jlong invokeLongStatic(jclass clazz, jmethodID& methodid, jvalue arguments[]); ! ! private: ! ! // bool runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate=false); ! ! // bool setupVM12DLL(ResourceManager& resource, const string& origin); ! // bool setupVM11DLL(ResourceManager& resource, const string& origin); ! ! // bool runVM11proc(ResourceManager& resource, bool noConsole, const string& origin); ! // bool runVM12proc(ResourceManager& resource, bool noConsole, const string& origin); }; --- 128,137 ---- int getExitCode(); + std::vector<JVMSetUpListener*> m_listeners; ! void addListener(JVMSetUpListener* listener) ! { ! m_listeners.push_back(listener); ! } }; Index: JavaMachineManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JavaMachineManager.h 1 May 2007 19:40:16 -0000 1.6 --- JavaMachineManager.h 26 May 2007 11:24:36 -0000 1.7 *************** *** 31,34 **** --- 31,35 ---- #include "JVMEnvVarLookup.h" #include "MSJViewLauncher.h" + #include "JNIRegister.h" /** Manages the JVM available on the computer. It builds the list of *************** *** 60,63 **** --- 61,66 ---- bool m_acceptDLL; bool m_preferDLL; + vector<JNIRegister*> m_jnireg; + std::vector<JVMSetUpListener*> m_listeners; public: *************** *** 75,78 **** --- 78,88 ---- void setPreferDLL(bool prefDLL); + void setJNI(vector<JNIRegister*> reg); + + void addListener(JVMSetUpListener* listener) + { + m_listeners.push_back(listener); + } + /** * Start the Java application. The java application started is --- JniSmooth.cpp DELETED --- Index: Makefile.win =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/Makefile.win,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.win 18 May 2007 21:33:59 -0000 1.9 --- Makefile.win 26 May 2007 11:24:36 -0000 1.10 *************** *** 8,16 **** MINGW = RES = ! OBJ = JniSmooth.o JVMBase.o SunJVMExe.o JArgs.o JClassProxy.o SunJVMDLL.o JavaMachineManager.o JVMEnvVarLookup.o JVMRegistryLookup.o MSJViewLauncher.o Properties.o ResourceManager.o SunJVMLauncher.o Version.o global.o JavaProperty.o JMethodCaller.o $(RES) ! LINKOBJ = JniSmooth.o JVMBase.o SunJVMExe.o JArgs.o JClassProxy.o SunJVMDLL.o JavaMachineManager.o JVMEnvVarLookup.o JVMRegistryLookup.o MSJViewLauncher.o Properties.o ResourceManager.o SunJVMLauncher.o Version.o global.o JavaProperty.o JMethodCaller.o $(RES) LIBS = -L"$(MINGW)/lib" INCS = -I"../util-core" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" ! CXXINCS = -g -fno-rtti -Os -I"../util-core" -I"$(MINGW)/include/c++" -I"$(MINGW)/include/c++/mingw32" -I"$(MINGW)/include/c++/backward" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" BIN = CommonJava.a CXXFLAGS = $(CUSTOMFLAGS) $(CXXINCS) -DJDK="$(JDK)" --- 8,16 ---- MINGW = RES = ! OBJ = JVMBase.o SunJVMExe.o JArgs.o JClassProxy.o SunJVMDLL.o JavaMachineManager.o JVMEnvVarLookup.o JVMRegistryLookup.o MSJViewLauncher.o Properties.o ResourceManager.o SunJVMLauncher.o Version.o global.o JavaProperty.o JMethodCaller.o $(RES) ! LINKOBJ = JVMBase.o SunJVMExe.o JArgs.o JClassProxy.o SunJVMDLL.o JavaMachineManager.o JVMEnvVarLookup.o JVMRegistryLookup.o MSJViewLauncher.o Properties.o ResourceManager.o SunJVMLauncher.o Version.o global.o JavaProperty.o JMethodCaller.o $(RES) LIBS = -L"$(MINGW)/lib" INCS = -I"../util-core" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" ! CXXINCS = -g -fno-rtti -Os -I"../util-core" -I"$(MINGW)/include/c++" -I"$(MINGW)/include/c++/mingw32" -I"$(MINGW)/include/c++/backward" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" BIN = CommonJava.a CXXFLAGS = $(CUSTOMFLAGS) $(CXXINCS) -DJDK="$(JDK)" Index: ResourceManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ResourceManager.cpp 19 May 2007 23:34:07 -0000 1.26 --- ResourceManager.cpp 26 May 2007 11:24:36 -0000 1.27 *************** *** 38,41 **** --- 38,42 ---- m_resourcePropsId = propsId; m_resourceJarId = jarId; + m_resourceJniId = jniId; // *************** *** 49,54 **** --- 50,57 ---- mainsize = SizeofResource(NULL, resprop); // char mainbuf[mainsize+1]; + DEBUG("Loading resource..."); HGLOBAL main = LoadResource(NULL, resprop); m_props.setData((const char*)main, mainsize); + DEBUG("Loading resource... done"); } else *************** *** 63,85 **** m_arguments = StringUtils::split(getProperty(KEY_ARGUMENTS, ""), " \t\n\r", "\"\'"); ! // ! // loads the jar information ! // ! std::string jaridstr = this->idToResourceName(jarId); ! HRSRC resjar = FindResource(NULL, jaridstr.c_str(), category.c_str()); ! if (resjar != NULL) ! { ! m_jarSize = SizeofResource(NULL, resjar); ! m_jarHandler = LoadResource(NULL, resjar); ! } ! else ! { ! m_lastError = "Can't find JAR resource!"; ! return; ! } ! ! ! m_jnismoothSize = this->getResourceSize(jniId); ! m_jnismoothHandler = this->getResource(jniId); // --- 66,71 ---- m_arguments = StringUtils::split(getProperty(KEY_ARGUMENTS, ""), " \t\n\r", "\"\'"); ! m_jnismoothSize = 0; ! m_jnismoothHandler = 0; // *************** *** 118,128 **** { m_currentDirectory = FileUtils::concFile(exepath, curdirmodifier.substr(pos + string("${EXECUTABLEPATH}").size())); - // m_currentDirectory = StringUtils::replace(curdirmodifier, "${EXECUTABLEPATH}", exepath); } else { ! DEBUG(string("Currentdirectory =") + curdirmodifier); m_currentDirectory = curdirmodifier; - // m_currentDirectory = FileUtils::concFile(FileUtils::getExecutablePath(), curdirmodifier); m_currentDirectory = StringUtils::replaceEnvironmentVariable(m_currentDirectory); } --- 104,112 ---- { m_currentDirectory = FileUtils::concFile(exepath, curdirmodifier.substr(pos + string("${EXECUTABLEPATH}").size())); } else { ! DEBUG(string("Currentdirectory: ") + curdirmodifier); m_currentDirectory = curdirmodifier; m_currentDirectory = StringUtils::replaceEnvironmentVariable(m_currentDirectory); } *************** *** 132,136 **** m_currentDirectory = ""; } - // printf("CURDIR SET TO: [%s]\n", m_currentDirectory.c_str()); } --- 116,119 ---- *************** *** 211,214 **** --- 194,211 ---- return ""; + // + std::string jaridstr = this->idToResourceName(m_resourceJarId); + HRSRC resjar = FindResource(NULL, jaridstr.c_str(), m_resourceCategory.c_str()); + if (resjar != NULL) + { + m_jarSize = SizeofResource(NULL, resjar); + m_jarHandler = LoadResource(NULL, resjar); + } + else + { + m_lastError = "Can't find JAR resource!"; + return ""; + } + std::string tempfilename = FileUtils::createTempFileName(".jar"); DEBUG("Created temporary filename to hold the jar (" + tempfilename + ")"); *************** *** 344,349 **** if (m_jnismoothHandler == 0) { ! DEBUG("NO JNI SMOOTH ID !!"); ! return ""; } --- 341,352 ---- if (m_jnismoothHandler == 0) { ! m_jnismoothSize = this->getResourceSize( m_resourceJniId ); ! m_jnismoothHandler = this->getResource( m_resourceJniId ); ! ! if (m_jnismoothHandler == 0) ! { ! DEBUG("NO JNI SMOOTH ID !!"); ! return ""; ! } } Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** SunJVMLauncher.cpp 18 May 2007 21:33:59 -0000 1.30 --- SunJVMLauncher.cpp 26 May 2007 11:24:36 -0000 1.31 *************** *** 119,122 **** --- 119,124 ---- m_dllrunner = new SunJVMDLL(this->RuntimeLibPath, v); + m_dllrunner->setJNI(m_jnireg); + // set up the vm parameters... setupVM(resource, m_dllrunner); *************** *** 140,143 **** --- 142,146 ---- DEBUG("No version identified for " + toString()); SunJVMExe exe(this->JavaHome); + VmVersion = exe.guessVersion(); DEBUG("Version found: " + VmVersion.toString()); *************** *** 160,163 **** --- 163,167 ---- SunJVMExe exe(this->JavaHome, VmVersion); + setupVM(resource, &exe); if (exe.run(classname, useConsole)) *************** *** 171,174 **** --- 175,181 ---- bool SunJVMLauncher::setupVM(ResourceManager& resource, JVMBase* vm) { + for(int i=0; i<m_listeners.size(); i++) + vm->addListener(m_listeners[i]); + // // create the properties array *************** *** 229,230 **** --- 236,241 ---- } + void SunJVMLauncher::setJNI(vector<JNIRegister*> reg) + { + m_jnireg = reg; + } Index: JVMBase.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JVMBase.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JVMBase.cpp 28 Apr 2007 08:43:43 -0000 1.1 --- JVMBase.cpp 26 May 2007 11:24:36 -0000 1.2 *************** *** 67,68 **** --- 67,81 ---- } } + + void JVMBase::addListener(JVMSetUpListener* listener) + { + m_listeners.push_back(listener); + } + + void JVMBase::callListeners(int pid) + { + for (int i=0; i<m_listeners.size(); i++) + { + m_listeners[i]->jvmHasPid(pid); + } + } --- JniSmooth.h DELETED --- Index: SunJVMExe.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMExe.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SunJVMExe.cpp 1 May 2007 19:40:16 -0000 1.2 --- SunJVMExe.cpp 26 May 2007 11:24:36 -0000 1.3 *************** *** 92,95 **** --- 92,99 ---- if (proc.run()) { + // + // Call the JVM listeners + callListeners(proc.getProcessId()); + DEBUG("Started successfully"); proc.join(); Index: JVMBase.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JVMBase.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JVMBase.h 28 Apr 2007 08:43:43 -0000 1.1 --- JVMBase.h 26 May 2007 11:24:36 -0000 1.2 *************** *** 23,27 **** #include <string> - #include "jni.h" #include "Version.h" --- 23,26 ---- *************** *** 35,38 **** --- 34,43 ---- */ + class JVMSetUpListener + { + public: + virtual void jvmHasPid(int pid)=0; + }; + class JVMBase { *************** *** 44,48 **** int m_initialHeap; std::vector<std::string> m_arguments; ! public: JVMBase(); --- 49,54 ---- int m_initialHeap; std::vector<std::string> m_arguments; ! std::vector<JVMSetUpListener*> m_listeners; ! public: JVMBase(); *************** *** 54,57 **** --- 60,69 ---- void addArgument(const std::string& arg); void setArguments(const std::string& args); + + void addListener(JVMSetUpListener* listener); + + protected: + void callListeners(int pid); + }; |