[Jsmooth-cvs] jsmooth/skeletons/commonjava JniSmooth.cpp, NONE, 1.1 JniSmooth.h, NONE, 1.1 JMethodC
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-05-18 21:34:26
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/commonjava In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5645/commonjava Modified Files: JMethodCaller.cpp Makefile.win ResourceManager.cpp ResourceManager.h SunJVMDLL.cpp SunJVMDLL.h SunJVMLauncher.cpp Added Files: JniSmooth.cpp JniSmooth.h Log Message: implements the JNI JSmooth functions Index: JMethodCaller.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/JMethodCaller.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JMethodCaller.cpp 28 Apr 2007 08:43:43 -0000 1.1 --- JMethodCaller.cpp 18 May 2007 21:33:59 -0000 1.2 *************** *** 35,38 **** --- 35,39 ---- { jvalue res; + res.l = 0; DEBUG("invoking " + m_clazz + ": " + m_methodname + ", " + getJavaSignature()); *************** *** 45,49 **** --- 46,57 ---- return res; } + jmethodID m = jvm.findMethod(cl, m_methodname, getJavaSignature(), false); + if (m == 0) + { + DEBUG("Can't find the method " + m_methodname + " / " + getJavaSignature()); + return res; + } + switch (m_returntype.TYPE) { Index: SunJVMDLL.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMDLL.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SunJVMDLL.cpp 13 May 2007 19:56:35 -0000 1.3 --- SunJVMDLL.cpp 18 May 2007 21:33:59 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- #include "JClassProxy.h" + #include "JniSmooth.h" SunJVMDLL::SunJVMDLL(const std::string& jvmdll, const Version& v) *************** *** 103,106 **** --- 104,109 ---- res = setupVM12DLL(CreateJavaVM, GetDefaultJavaVMInitArgs); + registerJniSmooth(); + DEBUG("Result code on DLL: " + StringUtils::toString(res)); if (res) *************** *** 226,234 **** jmethodID SunJVMDLL::findMethod(jclass& cls, const std::string& methodname, const std::string& signature, bool isStatic) { jmethodID mid; if (isStatic) ! mid = env()->GetStaticMethodID(cls, methodname.c_str(), signature.c_str()); else ! mid = env()->GetMethodID(cls, methodname.c_str(), signature.c_str()); return mid; --- 229,239 ---- jmethodID SunJVMDLL::findMethod(jclass& cls, const std::string& methodname, const std::string& signature, bool isStatic) { + 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; *************** *** 240,243 **** --- 245,267 ---- } + void SunJVMDLL::setIntField(jclass cls, jobject obj, const std::string& fieldName, int value) + { + jfieldID binding = env()->GetFieldID(cls, fieldName.c_str(), "I"); + env()->SetIntField(obj, binding, (jint)value); + } + + void SunJVMDLL::setLongField(jclass cls, jobject obj, const std::string& fieldName, jlong value) + { + jfieldID binding = env()->GetFieldID(cls, fieldName.c_str(), "J"); + env()->SetLongField(obj, binding, (jlong)value); + } + + void SunJVMDLL::setObjectField(jclass cls, jobject obj, const std::string& fieldName, const std::string& fieldclass, jobject value) + { + std::string fc = "L" + StringUtils::replace(fieldclass, "." , "/") + ";"; + jfieldID binding = env()->GetFieldID(cls, fieldName.c_str(), fc.c_str()); + env()->SetObjectField(obj, binding, value); + } + jstring SunJVMDLL::newUTFString(const std::string& str) { *************** *** 369,370 **** --- 393,418 ---- return env()->CallObjectMethodA(obj, methodid, arguments); } + + bool SunJVMDLL::registerMethod(const std::string& classname, const std::string& methodname, const std::string& signature, + void* fn) + { + jclass cc = this->findClass(classname); + if (cc == 0) + return false; + JNINativeMethod jnm; + jnm.name = (char*)methodname.c_str(); + jnm.signature = (char*)signature.c_str(); + jnm.fnPtr = fn; + + int res = env()->RegisterNatives(cc, &jnm, 1); + if (res != 0) + return false; + + return true; + } + + bool SunJVMDLL::registerJniSmooth() + { + registerNativeMethods(this); + return true; + } Index: ResourceManager.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ResourceManager.h 28 Apr 2007 08:43:43 -0000 1.14 --- ResourceManager.h 18 May 2007 21:33:59 -0000 1.15 *************** *** 60,63 **** --- 60,65 ---- HGLOBAL m_jarHandler; int m_jarSize; + HGLOBAL m_jnismoothHandler; + int m_jnismoothSize; std::vector<std::string> m_arguments; *************** *** 90,94 **** * @param jarId the resource id, stored under the category type, for the jar file */ ! ResourceManager(std::string category, int propsId, int jarId); /** --- 92,96 ---- * @param jarId the resource id, stored under the category type, for the jar file */ ! ResourceManager(std::string category, int propsId, int jarId, int jniId = -1); /** *************** *** 112,115 **** --- 114,119 ---- std::string saveJarInTempFile(); + std::string saveJnismoothInTempFile(); + /** Returns the name of the main class. The main class is the * class used to launch the java application. The static "public *************** *** 176,180 **** private: ! void saveTemp(std::string tempname); std::string idToResourceName(int id) const --- 180,184 ---- private: ! void saveTemp(std::string tempname, HGLOBAL data, int size); std::string idToResourceName(int id) const Index: SunJVMDLL.h =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMDLL.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SunJVMDLL.h 30 Apr 2007 20:54:32 -0000 1.2 --- SunJVMDLL.h 18 May 2007 21:33:59 -0000 1.3 *************** *** 78,81 **** --- 78,84 ---- bool setupVM11DLL(CreateJavaVM_t CreateJavaVM, GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs); + bool registerMethod(const std::string& classname, const std::string& methodname, const std::string& signature, void* fn); + bool registerJniSmooth(); + JNIEnv* env() { *************** *** 92,95 **** --- 95,102 ---- JavaVM* getJavaVM(); + void setIntField(jclass cls, jobject obj, const std::string& fieldName, int value); + void setLongField(jclass cls, jobject obj, const std::string& fieldName, jlong value); + void setObjectField(jclass cls, jobject obj, const std::string& fieldName, const std::string& fieldclass, jobject value); + jstring newUTFString(const std::string& str); jobject newObject(jclass clazz, jmethodID& methodid, jvalue arguments[]); --- NEW FILE: JniSmooth.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "JniSmooth.h" #include "common.h" #include "StringUtils.h" #include "FileUtils.h" #include "jni.h" #include "JMethodCaller.h" SunJVMDLL* jnismooth_dll = 0; JNIEXPORT jstring JNICALL testString (JNIEnv *env, jobject obj, jstring s) { jboolean copy = true; const char* str = jnismooth_dll->env()->GetStringUTFChars(s, ©); std::string result = StringUtils::toLowerCase(str); jnismooth_dll->env()->ReleaseStringUTFChars(s, str); return jnismooth_dll->newUTFString(result); } JNIEXPORT jstring JNICALL jnm_getExecutablePath(JNIEnv *env, jobject obj) { return jnismooth_dll->newUTFString(FileUtils::getExecutablePath()); } JNIEXPORT jstring JNICALL jnm_getExecutableName(JNIEnv *env, jobject obj) { return jnismooth_dll->newUTFString(FileUtils::getExecutableFileName()); } JNIEXPORT jboolean JNICALL jnm_deleteFileOnReboot(JNIEnv *env, jobject obj, jstring s) { jboolean copy = true; const char* str = jnismooth_dll->env()->GetStringUTFChars(s, ©); std::string filename = str; jnismooth_dll->env()->ReleaseStringUTFChars(s, str); if (!FileUtils::fileExists(filename)) { filename = StringUtils::replace(filename, "/", "\\"); if (!FileUtils::fileExists(filename)) { return JNI_FALSE; } } FileUtils::deleteOnReboot(filename); return JNI_TRUE; } JNIEXPORT jboolean JNICALL jnm_exitWindows(JNIEnv *env, jobject obj, jint s) { DWORD dwVersion = GetVersion(); if ( dwVersion < 0x80000000) { // Windows NT4/2000/XP HANDLE hToken; LUID tmpLuid; HANDLE handleProcess=GetCurrentProcess(); if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken)) return JNI_FALSE; if (!LookupPrivilegeValue(0, SE_SHUTDOWN_NAME, &tmpLuid)) return JNI_FALSE; TOKEN_PRIVILEGES NewState; LUID_AND_ATTRIBUTES luidattr; NewState.PrivilegeCount = 1; luidattr.Luid=tmpLuid; luidattr.Attributes=SE_PRIVILEGE_ENABLED; NewState.Privileges[0]=luidattr; if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0)) return JNI_FALSE; } if (ExitWindowsEx(s, 0)) return JNI_TRUE; return JNI_FALSE; } JNIEXPORT jboolean JNICALL jnm_shellexecute(JNIEnv *env, jobject obj, jstring action, jstring file, jstring parameters, jstring directory, jint showcmd) { jboolean copy = true; const char* s_action = (action != NULL)?jnismooth_dll->env()->GetStringUTFChars(action, ©):NULL; const char* s_file = (file != NULL)?jnismooth_dll->env()->GetStringUTFChars(file, ©):NULL; const char* s_parameters = (parameters != NULL)?jnismooth_dll->env()->GetStringUTFChars(parameters, ©):NULL; const char* s_directory = (directory != NULL)?jnismooth_dll->env()->GetStringUTFChars(directory, ©):NULL; bool res = ShellExecute(NULL, s_action, s_file, s_parameters, s_directory, showcmd); if (s_action != NULL) jnismooth_dll->env()->ReleaseStringUTFChars(action, s_action); if (s_file != NULL) jnismooth_dll->env()->ReleaseStringUTFChars(file, s_file); if (s_parameters != NULL) jnismooth_dll->env()->ReleaseStringUTFChars(parameters, s_parameters); if (s_directory != NULL) jnismooth_dll->env()->ReleaseStringUTFChars(directory, s_directory); return res?JNI_TRUE:JNI_FALSE; } JNIEXPORT jobject JNICALL jnm_getdriveinfo(JNIEnv *env, jobject obj, jobject file) { jclass dic = jnismooth_dll->findClass("jsmooth.DriveInfo"); if (dic == 0) { return NULL; } jmethodID construc = jnismooth_dll->findMethod(dic, "<init>", "()V", false); if (construc == 0) { return NULL; } JMethodCaller canonicalcaller("java.io.File", "java.lang.String getCanonicalPath()"); jvalue vals[0]; jvalue canonicalval = canonicalcaller.invoke(*jnismooth_dll, file, vals); jstring jcanstr = (jstring)canonicalval.l; jboolean copy = true; const char* str = jnismooth_dll->env()->GetStringUTFChars(jcanstr, ©); std::string canonicalfile = str; jnismooth_dll->env()->ReleaseStringUTFChars(jcanstr, str); // int driveType = GetDriveType(); jobject driveinfo = jnismooth_dll->env()->NewObject(dic, construc); if ((canonicalfile.length()>1) && (canonicalfile[1] == ':')) { std::string driveletter = canonicalfile[0] + std::string(":\\"); int drivetype = GetDriveType(driveletter.c_str()); jnismooth_dll->setIntField(dic, driveinfo, "m_driveType", drivetype); void * pGetDiskFreeSpaceEx = (void*)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); long freeBytes = 0, totalBytes = -1, totalFreeBytes = 0; if ((pGetDiskFreeSpaceEx != 0) && (drivetype > 1)) { unsigned __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes; if (GetDiskFreeSpaceEx(driveletter.c_str(), (_ULARGE_INTEGER*)&lpFreeBytesAvailable, (_ULARGE_INTEGER*)&lpTotalNumberOfBytes, (_ULARGE_INTEGER*)&lpTotalNumberOfFreeBytes)) { freeBytes = lpFreeBytesAvailable; totalBytes = lpTotalNumberOfBytes; totalFreeBytes = lpTotalNumberOfFreeBytes; } } else if (drivetype > 1) { DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters; if (GetDiskFreeSpace(driveletter.c_str(), &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters)) { freeBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwFreeClusters); totalBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwTotalClusters); totalFreeBytes = ((long)dwBytesPerSect * (long)dwSectPerClust * (long)dwFreeClusters); } } jnismooth_dll->setLongField(dic, driveinfo, "m_freeBytesForUser", freeBytes); jnismooth_dll->setLongField(dic, driveinfo, "m_totalFreeBytes", totalFreeBytes); jnismooth_dll->setLongField(dic, driveinfo, "m_totalBytes", totalBytes); if (drivetype > 1) { char volumename[MAX_PATH+1], filesystemname[MAX_PATH+1]; DWORD serialnumber, maxcomposize, systemflags; if (GetVolumeInformation( driveletter.c_str(), volumename, MAX_PATH, &serialnumber, &maxcomposize, &systemflags, filesystemname, MAX_PATH)) { jnismooth_dll->setIntField(dic, driveinfo, "m_serialNumber", serialnumber); jnismooth_dll->setIntField(dic, driveinfo, "m_maxComponentSize", maxcomposize); jnismooth_dll->setIntField(dic, driveinfo, "m_systemFlags", systemflags); jstring jvolumename = jnismooth_dll->newUTFString(volumename); jstring jfilesystemname = jnismooth_dll->newUTFString(filesystemname); jnismooth_dll->setObjectField(dic, driveinfo, "m_volumeName", "java.lang.String", (jobject)jvolumename); jnismooth_dll->setObjectField(dic, driveinfo, "m_fileSystemName", "java.lang.String", (jobject)jfilesystemname); } } } // jfieldID binding = broker->env()->GetFieldID(nat, "m_", "I"); // broker->env()->SetStaticBooleanField(nat, binding, JNI_TRUE); return driveinfo; } void registerNativeMethods(SunJVMDLL* broker) { jnismooth_dll = broker; jclass nat = broker->findClass("jsmooth.Native"); if (nat != 0) { if ( broker->registerMethod("jsmooth.Native", "getExecutablePath", "()Ljava/lang/String;", (void*)jnm_getExecutablePath) && broker->registerMethod("jsmooth.Native", "getExecutableName", "()Ljava/lang/String;", (void*)jnm_getExecutableName) && broker->registerMethod("jsmooth.Native", "deleteFileOnReboot", "(Ljava/lang/String;)Z", (void*)jnm_deleteFileOnReboot) && broker->registerMethod("jsmooth.Native", "exitWindows", "(I)Z", (void*)jnm_exitWindows) && broker->registerMethod("jsmooth.Native", "shellExecute", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Z", (void*)jnm_shellexecute) && broker->registerMethod("jsmooth.Native", "getDriveInfo", "(Ljava/io/File;)Ljsmooth/DriveInfo;", (void*)jnm_getdriveinfo) ) { jfieldID binding = broker->env()->GetStaticFieldID(nat, "s_bound", "Z"); broker->env()->SetStaticBooleanField(nat, binding, JNI_TRUE); } } } Index: Makefile.win =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/Makefile.win,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.win 30 Apr 2007 20:54:32 -0000 1.8 --- Makefile.win 18 May 2007 21:33:59 -0000 1.9 *************** *** 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 = -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 = 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)" Index: ResourceManager.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/ResourceManager.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ResourceManager.cpp 1 May 2007 19:40:16 -0000 1.23 --- ResourceManager.cpp 18 May 2007 21:33:59 -0000 1.24 *************** *** 33,37 **** char * const ResourceManager::KEY_EMBEDJAR = "embedjar"; ! ResourceManager::ResourceManager(std::string category, int propsId, int jarId) { m_resourceCategory = category; --- 33,37 ---- char * const ResourceManager::KEY_EMBEDJAR = "embedjar"; ! ResourceManager::ResourceManager(std::string category, int propsId, int jarId, int jniId) { m_resourceCategory = category; *************** *** 82,85 **** --- 82,89 ---- } + + m_jnismoothSize = this->getResourceSize(jniId); + m_jnismoothHandler = this->getResource(jniId); + // // Extract the java properties from the Property *************** *** 110,135 **** } ! std::string curdirmodifier = m_props.get(ResourceManager::KEY_CURRENTDIR); ! if (curdirmodifier.length()>0) ! { ! int pos = string::npos; ! if ( (pos=curdirmodifier.find("${EXECUTABLEPATH}")) != string::npos) ! { ! 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); ! } ! } ! else ! { ! m_currentDirectory = ""; ! } ! // printf("CURDIR SET TO: [%s]\n", m_currentDirectory.c_str()); } --- 114,139 ---- } ! std::string curdirmodifier = m_props.get(ResourceManager::KEY_CURRENTDIR); ! if (curdirmodifier.length()>0) ! { ! int pos = string::npos; ! if ( (pos=curdirmodifier.find("${EXECUTABLEPATH}")) != string::npos) ! { ! 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); ! } ! } ! else ! { ! m_currentDirectory = ""; ! } ! // printf("CURDIR SET TO: [%s]\n", m_currentDirectory.c_str()); } *************** *** 147,152 **** } ! void ResourceManager::saveTemp(std::string tempname) { HANDLE temp = CreateFile(tempname.c_str(), GENERIC_WRITE, --- 151,159 ---- } ! void ResourceManager::saveTemp(std::string tempname, HGLOBAL data, int size) { + if ((data == 0) || (size == 0)) + return; + HANDLE temp = CreateFile(tempname.c_str(), GENERIC_WRITE, *************** *** 160,164 **** { DWORD reallyWritten; ! WriteFile(temp, m_jarHandler, m_jarSize, &reallyWritten, NULL); // TODO: check the reallyWritten value for errors --- 167,171 ---- { DWORD reallyWritten; ! WriteFile(temp, data, size, &reallyWritten, NULL); // TODO: check the reallyWritten value for errors *************** *** 209,213 **** std::string tempfilename = FileUtils::createTempFileName(".jar"); DEBUG("Created temporary filename to hold the jar (" + tempfilename + ")"); ! saveTemp(tempfilename); return tempfilename; } --- 216,220 ---- std::string tempfilename = FileUtils::createTempFileName(".jar"); DEBUG("Created temporary filename to hold the jar (" + tempfilename + ")"); ! saveTemp(tempfilename, m_jarHandler, m_jarSize); return tempfilename; } *************** *** 329,334 **** if (resprop != NULL) { - int size = SizeofResource(NULL, resprop); - char buffer[size+1]; return LoadResource(NULL, resprop); } --- 336,339 ---- *************** *** 336,337 **** --- 341,356 ---- return 0; } + + + std::string ResourceManager::saveJnismoothInTempFile() + { + if (m_jnismoothHandler == 0) + return ""; + + std::string tempfilename = FileUtils::createTempFileName(".jar"); + DEBUG("Saving jnismoothjar in " + tempfilename); + + DEBUG("Created temporary filename to hold the jar (" + tempfilename + ")"); + saveTemp(tempfilename, m_jnismoothHandler, m_jnismoothSize); + return tempfilename; + } Index: SunJVMLauncher.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/commonjava/SunJVMLauncher.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** SunJVMLauncher.cpp 13 May 2007 19:56:35 -0000 1.29 --- SunJVMLauncher.cpp 18 May 2007 21:33:59 -0000 1.30 *************** *** 190,193 **** --- 190,198 ---- vm->addPathElement(embj); } + + std::string jnijar = resource.saveJnismoothInTempFile(); + if (jnijar != "") + vm->addPathElement(jnijar); + // // Define the classpath --- NEW FILE: JniSmooth.h --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __JNISMOOTH_H_ #define __JNISMOOTH_H_ #include <string> #include "SunJVMDLL.h" void registerNativeMethods(SunJVMDLL* broker); #endif |