Merged with new-trap-decoding branch at rev a792088a3f04 (branch closed).
[cacao.git] / src / native / vm / cldc1.1 / com_sun_cldc_io_ResourceInputStream.cpp
index a262ca46fadd8fc70b4940ee97bbfef50b447392..30efeaa2cc45d069883695cc8182088208cc76f6 100644 (file)
 #include <errno.h>
 #include <zlib.h>
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
+#include "native/jni.hpp"
+#include "native/native.hpp"
 
 #if defined(ENABLE_JNI_HEADERS)
 # include "native/include/com_sun_cldc_io_ResourceInputStream.h"
 #endif
 
-#include "threads/lock-common.h"
+#include "threads/mutex.hpp"
 
-#include "vm/builtin.h"
+#include "vm/array.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/javaobjects.hpp"
 #include "vm/string.hpp"
 #include "vm/types.h"
 #include "vm/vm.hpp" /* REMOVE ME: temporarily */
-#include "vm/zip.h"
+#include "vm/zip.hpp"
 
 
 static java_handle_t* zip_read_resource(list_classpath_entry *lce, utf *name)
@@ -188,13 +187,15 @@ extern "C" {
  */
 JNIEXPORT jobject JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, jstring name)
 {
-       list_classpath_entry *lce;
        char *filename;
        s4 filenamelen;
        char *path;
        utf *uname;
        java_handle_t* descriptor;
-       
+
+       // Get current list of classpath entries.
+       SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
+
        /* get the classname as char string (do it here for the warning at
        the end of the function) */
 
@@ -202,23 +203,23 @@ JNIEXPORT jobject JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *
        filenamelen = utf_bytes(uname) + strlen("0");
        filename = MNEW(char, filenamelen);
        utf_copy(filename, uname);
-       
+
        /* walk through all classpath entries */
 
-       for (lce = (list_classpath_entry*) list_first(list_classpath_entries); lce != NULL;
-                lce = (list_classpath_entry*) list_next(list_classpath_entries, lce)) {
-                       
+       for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
+               list_classpath_entry* lce = *it;
+
 #if defined(ENABLE_ZLIB)
                if (lce->type == CLASSPATH_ARCHIVE) {
 
                        /* enter a monitor on zip/jar archives */
-                       LOCK_MONITOR_ENTER(lce);
+                       lce->mutex->lock();
 
                        /* try to get the file in current archive */
                        descriptor = zip_read_resource(lce, uname);
 
                        /* leave the monitor */
-                       LOCK_MONITOR_EXIT(lce);
+                       lce->mutex->unlock();
                        
                        if (descriptor != NULL) { /* file exists */
                                break;
@@ -303,8 +304,9 @@ JNIEXPORT jint JNICALL Java_com_sun_cldc_io_ResourceInputStream_readBytes(JNIEnv
 {
        /* get pointer to the buffer */
        // XXX Not GC safe.
-       void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) byteArray, off));
-       
+       ByteArray ba(byteArray);
+       void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
+
        com_sun_cldchi_jvm_FileDescriptor fd(jobj);
 
        int64_t filep      = fd.get_pointer();
@@ -376,16 +378,12 @@ static JNINativeMethod methods[] = {
  
 *******************************************************************************/
  
-// FIXME
-extern "C" {
 void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
  
-       u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }