[Jsmooth-cvs] jsmooth/skeletons/commonjava JavaMachineManager.cpp, 1.15, 1.16 JavaMachineManager.h,
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-04-09 17:18:20
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9385 Modified Files: JavaMachineManager.cpp JavaMachineManager.h SunJVMLauncher.cpp SunJVMLauncher.h Log Message: adds methods to launch specificly a DLL JVM and call a static method Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** SunJVMLauncher.cpp 1 Apr 2007 22:18:05 -0000 1.23 --- SunJVMLauncher.cpp 9 Apr 2007 17:18:16 -0000 1.24 *************** *** 38,46 **** } ! bool SunJVMLauncher::run(ResourceManager& resource, const string& origin) { // patch proposed by zregvart // if you're using bundeled JVM, you apriori ! // specified version, and the version check // would require instantiateing JVM which is // an overhead in both code and runtime --- 38,48 ---- } ! bool SunJVMLauncher::run(ResourceManager& resource, const string& origin, bool justInstanciate) { + DEBUG("Running now " + this->toString() + ", instanciate=" + (justInstanciate?"yes":"no")); + // patch proposed by zregvart // if you're using bundeled JVM, you apriori ! // specified the version, and the version check // would require instantiateing JVM which is // an overhead in both code and runtime *************** *** 123,127 **** if ((m_javavm != 0) && (m_javaenv != 0)) { ! return runVMDLL(resource, origin); } return false; --- 125,129 ---- if ((m_javavm != 0) && (m_javaenv != 0)) { ! return runVMDLL(resource, origin, justInstanciate); } return false; *************** *** 300,305 **** } ! bool SunJVMLauncher::runVMDLL(ResourceManager& resource, const string& origin) { std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); classname = StringUtils::replace(classname,".", "/"); --- 302,309 ---- } ! bool SunJVMLauncher::runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate) { + DEBUG("DLL set up " + this->toString() + ", instanciate=" + (justInstanciate?"yes":"no")); + std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); classname = StringUtils::replace(classname,".", "/"); *************** *** 341,344 **** --- 345,354 ---- if ((mid != 0) && (args != 0)) { + DEBUG(std::string("VM OK, instanciate ? ") + (justInstanciate?"yes":"no")); + if (justInstanciate) + { + return true; + } + DEBUG("Calling static void main(String[]) method from " + classname); m_javaenv->CallStaticVoidMethod(cls, mid, args); *************** *** 356,422 **** - // bool SunJVMLauncher::runVM12DLL(ResourceManager& resource, const string& origin) - // { - // if (setupVM12DLL(resource, origin) == false) - // { - // DEBUG("CAN'T LOAD DLL"); - // return false; - // } - - // std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); - // classname = StringUtils::replace(classname,".", "/"); - // DEBUG("Look for " + classname); - // jclass cls = (m_javaenv)->FindClass(classname.c_str()); - // if (cls == 0) - // { - // char tmpbuf[255]; - // sprintf(tmpbuf, "Cant find <%s> at all!", classname.c_str()); - // DEBUG(tmpbuf); - // DEBUG(std::string("Can't Find CLASS <") + classname + std::string(">")); - // return false; - // } - // else - // DEBUG("CLASS FOUND"); - - // char strbuf[255]; - // sprintf(strbuf, ""); - // jstring jstr = (m_javaenv)->NewStringUTF(strbuf); - // jmethodID mid = (m_javaenv)->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V"); - - // vector<string> pargs = StringUtils::split(resource.getProperty(ResourceManager::KEY_ARGUMENTS), " \t\n\r", "\"\'"); - // for (int i=0; i<pargs.size(); i++) - // DEBUG("ARG:: <" + pargs[i] + ">"); - - // jobjectArray args; - - // if (pargs.size() > 0) - // { - // args = (m_javaenv)->NewObjectArray(pargs.size(), (m_javaenv)->FindClass("java/lang/String"), jstr); - // for (int i=0; i<pargs.size(); i++) - // { - // jstr = (m_javaenv)->NewStringUTF(pargs[i].c_str()); - // (m_javaenv)->SetObjectArrayElement(args, i, jstr); - // } - // } - // else - // { - // args = (m_javaenv)->NewObjectArray(0, (m_javaenv)->FindClass("java/lang/String"), jstr); - // } - - // if ((mid != 0) && (args != 0)) - // { - // m_javaenv->CallStaticVoidMethod(cls, mid, args); - // DEBUG("VM CALLED !!"); - // m_javavm->DestroyJavaVM(); - // DEBUG("VM DESTROYED !!"); - // return true; - // } - // else - // { - // DEBUG("Can't find method !"); - // return false; - // } - // } - bool SunJVMLauncher::setupVM11DLL(ResourceManager& resource, const string& origin) --- 366,369 ---- *************** *** 862,867 **** --- 809,859 ---- } + bool SunJVMLauncher::dllInstanciate(ResourceManager& resource, const std::string& origin) + { + return runVMDLL(resource, origin); + } + bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2) { return v1.VmVersion < v2.VmVersion; } + + bool SunJVMLauncher::callDLLStaticMethod(const std::string& clazz, const std::string& methodname, const std::string& signature) + { + std::string classname = StringUtils::replace(clazz,".", "/"); + DEBUG("Calling " + classname + "::" + methodname + signature); + DEBUG("Check if " + classname + " is available"); + jclass cls = (m_javaenv)->FindClass(classname.c_str()); + if (cls == 0) + { + DEBUG(std::string("Can't Find CLASS <") + classname + std::string("> (probably a classpath issue)")); + return false; + } + else + DEBUG("OK, class " + classname + " is available"); + + char strbuf[255]; + sprintf(strbuf, ""); + jstring jstr = (m_javaenv)->NewStringUTF(strbuf); + jmethodID mid = (m_javaenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); + + if (mid != 0) + { + DEBUG("Calling static method from " + classname); + m_javaenv->CallStaticVoidMethod(cls, mid); + return true; + } + else + { + DEBUG("Can't find method !"); + return false; + } + + } + + int SunJVMLauncher::destroyVM() + { + if (m_javavm != 0) + return m_javavm->DestroyJavaVM(); + return -1; + } Index: SunJVMLauncher.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SunJVMLauncher.h 1 Mar 2007 21:56:03 -0000 1.9 --- SunJVMLauncher.h 9 Apr 2007 17:18:17 -0000 1.10 *************** *** 78,82 **** * false otherwise. */ ! virtual bool run(ResourceManager& resource, const string& origin); --- 78,82 ---- * false otherwise. */ ! virtual bool run(ResourceManager& resource, const string& origin, bool justInstanciate = false); *************** *** 109,117 **** bool runExe(const string& exepath, bool forceFullClasspath, ResourceManager& resource, bool noConsole, const std::string& version, const string& origin); private: // bool runVM12DLL(ResourceManager& resource, const string& origin); // bool runVM11DLL(ResourceManager& resource, const string& origin); ! bool runVMDLL(ResourceManager& resource, const string& origin); bool setupVM12DLL(ResourceManager& resource, const string& origin); --- 109,123 ---- 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); + + int destroyVM(); + private: // bool runVM12DLL(ResourceManager& resource, const string& origin); // bool runVM11DLL(ResourceManager& resource, const string& origin); ! bool runVMDLL(ResourceManager& resource, const string& origin, bool justInstanciate=false); bool setupVM12DLL(ResourceManager& resource, const string& origin); Index: JavaMachineManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JavaMachineManager.h 18 Feb 2007 23:29:09 -0000 1.4 --- JavaMachineManager.h 9 Apr 2007 17:18:16 -0000 1.5 *************** *** 90,93 **** --- 90,94 ---- bool run(bool noConsole, bool preferSingleProcess); + SunJVMLauncher* runDLLFromRegistry(bool justInstanciate=false); protected: Index: JavaMachineManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JavaMachineManager.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** JavaMachineManager.cpp 1 Mar 2007 21:56:02 -0000 1.15 --- JavaMachineManager.cpp 9 Apr 2007 17:18:16 -0000 1.16 *************** *** 179,180 **** --- 179,205 ---- return true; } + + + + SunJVMLauncher* JavaMachineManager::runDLLFromRegistry(bool justInstanciate) + { + string vms = "DLL VM will be tried in the following order: "; + for (int i=0; i<m_registryVms.size(); i++) + { + vms += m_registryVms[i].VmVersion.toString(); + vms += ";"; + } + DEBUG(vms); + + for (int i=0; i<m_registryVms.size(); i++) + { + DEBUG("- Trying registry: " + m_registryVms[i].toString()); + + bool res = m_registryVms[i].run(m_resman, "registry", justInstanciate); + + if (res) + return &m_registryVms[i]; + } + + return NULL; + } |