* src/vm/array.hpp: Implemented array access classes in C++.
[cacao.git] / src / native / vm / cldc1.1 / com_sun_cldc_io_j2me_socket_Protocol.cpp
index 9373b6b92f9650ab7300af230bbde22ab5f4e27e..856745cfba274719d69ecd1be6b05cc4ab1b7ea7 100644 (file)
 
 #include "vm/types.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_j2me_socket_Protocol.h"
@@ -63,7 +62,8 @@ JNIEXPORT jint JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *e
 
        // The hostname byte-array is a NULL terminated C-string.
        // XXX Not GC safe.
-       char* name = (char*) &(LLNI_array_data((java_handle_bytearray_t*) hostname));
+       ByteArray ba(hostname);
+       char* name = (char*) ba.get_raw_data_ptr();
 
        /* get the host */
 
@@ -106,7 +106,8 @@ JNIEXPORT jint JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf(JNIEnv
 {
        // Get pointer to the buffer.
        // XXX Not GC safe.
-       void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) b, off));
+       ByteArray ba(b);
+       void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
 
        // Receive from the socket.
        ssize_t result = recv(handle, buf, len, 0);
@@ -157,7 +158,8 @@ JNIEXPORT jint JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf(JNIEnv
 {
        // Get pointer to the buffer.
        // XXX Not GC safe.
-       void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) b, off));
+       ByteArray ba(b);
+       void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
        
        // Send the given byte to the socket.
        ssize_t result = send(handle, buf, len, 0);
@@ -238,16 +240,12 @@ static JNINativeMethod methods[] = {
  
 *******************************************************************************/
  
-// FIXME
-extern "C" {
 void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
 {
-       utf *u;
-       u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
+       utf* u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }