commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1086147 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/iofd.h include/acr/jnimacros.h shared/iofd.c
Date Mon, 28 Mar 2011 08:04:32 GMT
Author: mturk
Date: Mon Mar 28 08:04:31 2011
New Revision: 1086147

URL: http://svn.apache.org/viewvc?rev=1086147&view=rev
Log:
Add FileDescriptor setters

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
    commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h?rev=1086147&r1=1086146&r2=1086147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/iofd.h Mon Mar 28 08:04:31 2011
@@ -36,11 +36,18 @@ ACR_CLASS_DTOR(FileDescriptor);
 
 int
 AcrFileDescriptorGetFd(JNI_STDARGS);
+int
+AcrFileDescriptorSetFd(JNI_STDARGS, int fd);
 #if defined (WINDOWS)
 HANDLE
 AcrFileDescriptorGetHandle(JNI_STDARGS);
+int
+AcrFileDescriptorSetHandle(JNI_STDARGS, HANDLE fh);
 #endif
 
+jobject
+AcrNewFileDescriptor(JNI_STDENV, int fd, acr_osd_t fh);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h?rev=1086147&r1=1086146&r2=1086147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnimacros.h Mon Mar 28 08:04:31
2011
@@ -132,7 +132,7 @@
     (T)((ptrdiff_t)(*_E)->GetLongField(_E, (O), _f##I##n.i)
 
 #define SET_IFIELD_P(I, O, V)  \
-    (*_E)->SetLongField(_E, (O), _f##I##n.i, (jlong)((ptrdiff_t)(V)))
+    (*_E)->SetLongField(_E, (O), _f##I##n.i, P2J(V))
 
 #define CALL_VMETHOD0(I, O)  \
     (*_E)->CallVoidMethod(_E, (O), _m##I##n.i)

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c?rev=1086147&r1=1086146&r2=1086147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/iofd.c Mon Mar 28 08:04:31 2011
@@ -38,6 +38,12 @@ J_DECLARE_M_ID(0000) = {
     "()V"
 };
 
+J_DECLARE_M_ID(0001) = {
+    0,
+    "<init>",
+    "(I)V"
+};
+
 J_DECLARE_F_ID(0000) = {
     INVALID_FIELD_OFFSET,
     INVALID_FIELD_OFFSET,
@@ -63,6 +69,7 @@ ACR_CLASS_CTOR(FileDescriptor)
     if ((rv = AcrLoadClass(_E, &_clazzn, 0)) != 0)
         return rv;
     J_LOAD_METHOD(0000);
+    J_LOAD_METHOD(0001);
     J_LOAD_IFIELD(0000);
 #if defined(WINDOWS)
     J_LOAD_IFIELD(0001);
@@ -100,6 +107,28 @@ AcrFileDescriptorGetFd(JNI_STDARGS)
     return fd;
 }
 
+int
+AcrFileDescriptorSetFd(JNI_STDARGS, int fd)
+{
+    int rc = ACR_EBADF;
+
+    if (IS_JOBJECT_NULL(_E, _O))
+        return rc;
+    if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+        char *oa = *(char **)_O;
+        if (oa != 0) {
+            char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0000));
+            *((int *)fa) = fd;
+            rc = 0;
+        }
+    }
+    else if (CLAZZ_LOADED) {
+        SET_IFIELD_I(0000, _O, fd);
+        rc = 0;
+    }
+    return rc;
+}
+
 #if defined (WINDOWS)
 HANDLE
 AcrFileDescriptorGetHandle(JNI_STDARGS)
@@ -120,4 +149,46 @@ AcrFileDescriptorGetHandle(JNI_STDARGS)
     }
     return fh;
 }
+
+int
+AcrFileDescriptorSetHandle(JNI_STDARGS, HANDLE fh)
+{
+    int rc = ACR_EBADF;
+
+    if (IS_JOBJECT_NULL(_E, _O))
+        return rc;
+    if (J4FLD_OFF(0001) != INVALID_FIELD_OFFSET) {
+        char *oa = *(char **)_O;
+        if (oa != 0) {
+            char *fa = (oa + (ptrdiff_t)J4FLD_OFF(0000));
+            *((jlong *)fa) = P2J(fh);
+            rc = 0;
+        }
+    }
+    else if (CLAZZ_LOADED) {
+        SET_IFIELD_P(0000, _O, fh);
+        rc = 0;
+    }
+    return rc;
+}
 #endif
+
+jobject
+AcrNewFileDescriptor(JNI_STDENV, int fd, acr_osd_t fh)
+{
+    jobject fo;
+    if (!CLAZZ_LOADED) {
+        ACR_SET_OS_ERROR(ACR_EINIT);
+        return 0;
+    }
+    fo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), fd);
+#if defined (WINDOWS)
+    if (fo != 0) {
+        if (AcrFileDescriptorSetHandle(_E, fo, fh) != 0) {
+            (*_E)->DeleteLocalRef(_E, fo);
+            fo = 0;
+        }
+    }
+#endif
+    return fo;
+}



Mime
View raw message