[Jsmooth-cvs] jsmooth/skeletons/commonjava Makefile.win, 1.5, 1.6 Properties.cpp, 1.6, 1.7 Properti
Status: Beta
Brought to you by:
reyes
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv12205/skeletons/commonjava Modified Files: Makefile.win Properties.cpp Properties.h ResourceManager.cpp ResourceManager.h SunJVMLauncher.cpp SunJVMLauncher.h Log Message: Windows service wrapper update Index: Properties.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/Properties.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Properties.h 1 Mar 2007 21:56:03 -0000 1.5 --- Properties.h 12 Apr 2007 20:01:50 -0000 1.6 *************** *** 79,82 **** --- 79,84 ---- string get(const string& key) const; + bool contains(const string& key) const; + /** * Adds a new property. Index: ResourceManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ResourceManager.h 1 Mar 2007 21:56:03 -0000 1.12 --- ResourceManager.h 12 Apr 2007 20:01:50 -0000 1.13 *************** *** 137,140 **** --- 137,142 ---- */ std::string getProperty(const std::string& key) const; + std::string getProperty(const std::string& key, const std::string& def) const; + bool getBooleanProperty(const std::string& key) const; /** *************** *** 165,169 **** void setUserArguments(std::vector<std::string> arguments); void addUserArgument(std::string argument); ! private: void saveTemp(std::string tempname); --- 167,174 ---- void setUserArguments(std::vector<std::string> arguments); void addUserArgument(std::string argument); ! ! int getResourceSize(int id); ! HGLOBAL getResource(int id); ! private: void saveTemp(std::string tempname); Index: SunJVMLauncher.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SunJVMLauncher.h 9 Apr 2007 17:18:17 -0000 1.10 --- SunJVMLauncher.h 12 Apr 2007 20:01:50 -0000 1.11 *************** *** 49,52 **** --- 49,61 ---- std::string RuntimeLibPath; + enum { + JVM_NOT_LAUNCHED=0, + JVM_PROCESS_LAUNCHED, + JVM_DLL_INSTANCIATED + }; + + int Status; + + protected: JavaVM *m_javavm; *************** *** 80,84 **** virtual bool run(ResourceManager& resource, const string& origin, bool justInstanciate = false); - /** * Runs the JVM as a process and launches the application. The --- 89,92 ---- *************** *** 100,115 **** std::string toString() const; - Version guessVersionByProcess(const string& exepath); ! // int operator<(const SunJVMLauncher& other) const; ! ! friend bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2); ! 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(); --- 108,120 ---- std::string toString() const; Version guessVersionByProcess(const string& exepath); ! friend bool operator < (const SunJVMLauncher& v1, const SunJVMLauncher& v2); ! 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(); *************** *** 117,122 **** 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); --- 122,125 ---- Index: Makefile.win =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/Makefile.win,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.win 1 Mar 2007 21:56:02 -0000 1.5 --- Makefile.win 12 Apr 2007 20:01:50 -0000 1.6 *************** *** 12,16 **** LIBS = -L"$(MINGW)/lib" INCS = -I"../util-core" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" ! CXXINCS = -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)" --- 12,16 ---- LIBS = -L"$(MINGW)/lib" INCS = -I"../util-core" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" ! CXXINCS = -g -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.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ResourceManager.cpp 6 Apr 2007 16:27:10 -0000 1.20 --- ResourceManager.cpp 12 Apr 2007 20:01:50 -0000 1.21 *************** *** 162,167 **** // m_deleteOnFinalize.push_back(s); FileUtils::deleteOnReboot(s); ! } ! } --- 162,166 ---- // m_deleteOnFinalize.push_back(s); FileUtils::deleteOnReboot(s); ! } } *************** *** 176,179 **** --- 175,195 ---- } + std::string ResourceManager::getProperty(const std::string& key, const std::string& def) const + { + if (m_props.contains(key)) + return m_props.get(key); + else + return def; + } + + bool ResourceManager::getBooleanProperty(const std::string& key) const + { + std::string prop = getProperty(key); + if (StringUtils::parseInt(prop)==1) + return true; + + return false; + } + std::string ResourceManager::saveJarInTempFile() { *************** *** 279,280 **** --- 295,322 ---- } } + + int ResourceManager::getResourceSize(int id) + { + std::string propid = idToResourceName(id); + HRSRC resprop = FindResource(NULL, propid.c_str(), m_resourceCategory.c_str()); + if (resprop != NULL) + { + return SizeofResource(NULL, resprop); + } + else + return 0; + } + + HGLOBAL ResourceManager::getResource(int id) + { + std::string propid = idToResourceName(id); + HRSRC resprop = FindResource(NULL, propid.c_str(), m_resourceCategory.c_str()); + if (resprop != NULL) + { + int size = SizeofResource(NULL, resprop); + char buffer[size+1]; + return LoadResource(NULL, resprop); + } + else + return 0; + } Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** SunJVMLauncher.cpp 9 Apr 2007 17:18:16 -0000 1.24 --- SunJVMLauncher.cpp 12 Apr 2007 20:01:50 -0000 1.25 *************** *** 470,532 **** } - // bool SunJVMLauncher::runVM11DLL(ResourceManager& resource, const string& origin) - // { - // if (setupVM11DLL(resource, origin) == false) - // { - // DEBUG("CAN'T LOAD DLL "); - // return false; - // } - - // std::string classname = resource.getProperty(string(ResourceManager::KEY_MAINCLASSNAME)); - // classname = StringUtils::replace(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 "+ classname +" 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", "\"\'"); - // 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(); - // return true; - // } - // else - // { - // DEBUG("Can't find method !"); - // return false; - // } - // } - bool SunJVMLauncher::runVM11proc(ResourceManager& resource, bool noConsole, const string& origin) { --- 470,473 ---- *************** *** 821,828 **** 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) { --- 762,781 ---- bool SunJVMLauncher::callDLLStaticMethod(const std::string& clazz, const std::string& methodname, const std::string& signature) { + JNIEnv *env = new JNIEnv(); + jint result = m_javavm->AttachCurrentThread((void**)&env, 0); + DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); + + // if (result != 0) + // { + // DEBUG("Can't attach the thread to the VM!"); + // return false; + // } + + JNIEnv* jenv = env; + std::string classname = StringUtils::replace(clazz,".", "/"); DEBUG("Calling " + classname + "::" + methodname + signature); DEBUG("Check if " + classname + " is available"); ! jclass cls = (jenv)->FindClass(classname.c_str()); if (cls == 0) { *************** *** 835,845 **** 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; } --- 788,840 ---- char strbuf[255]; sprintf(strbuf, ""); ! jstring jstr = (jenv)->NewStringUTF(strbuf); ! jmethodID mid = (jenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); if (mid != 0) { DEBUG("Calling static method from " + classname); ! jenv->CallStaticVoidMethod(cls, mid); ! return true; ! } ! else ! { ! DEBUG("Can't find method !"); ! return false; ! } ! ! } ! ! bool SunJVMLauncher::callDLLStaticMethodInt(const std::string& clazz, const std::string& methodname, const std::string& signature, int value) ! { ! JNIEnv *env = new JNIEnv(); ! jint result = m_javavm->AttachCurrentThread((void**)&env, 0); ! DEBUG("Attached thread to the VM: " + StringUtils::toString(result)); ! ! JNIEnv* jenv = env; ! ! std::string classname = StringUtils::replace(clazz,".", "/"); ! DEBUG("Calling " + classname + "::" + methodname + signature); ! DEBUG("Check if " + classname + " is available"); ! jclass cls = (jenv)->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 = (jenv)->NewStringUTF(strbuf); ! jmethodID mid = (jenv)->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); ! ! if (mid != 0) ! { ! DEBUG("Calling static method " + methodname + " from " + classname + " (" + StringUtils::toString((int)cls) + "," + StringUtils::toString((int)mid) +")" ); ! jvalue args[5]; ! args[0].i = value; ! jint val = value; ! jenv->CallStaticVoidMethod(cls, mid, (jint)value); return true; } Index: Properties.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/Properties.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Properties.cpp 1 Mar 2007 21:56:03 -0000 1.6 --- Properties.cpp 12 Apr 2007 20:01:50 -0000 1.7 *************** *** 76,79 **** --- 76,87 ---- } + bool Properties::contains(const string& key) const + { + map<string, string>::const_iterator i = m_data.find(key); + if (i == m_data.end()) + return false; + return true; + } + string Properties::unescape(const string& val) { |