Author: mturk Date: Sat Apr 25 18:11:33 2009 New Revision: 768570 URL: http://svn.apache.org/viewvc?rev=768570&view=rev Log: Add errno method to the Descriptor
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=768570&r1=768569&r2=768570&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java Sat Apr 25 18:11:33 2009 @@ -34,6 +34,8 @@ */ public abstract class Descriptor implements Closeable { + private int IERRNUM; + /* * Descriptor can be only created from native code. * Suppress any instantiation except form internal classes. @@ -110,6 +112,17 @@ } /** + * Error number of the last operation performed on this descriptor. + * + * @return {...@code int} representation of error number. + * @see org.apache.commons.runtime.io.Status + */ + public final int errno() + { + return IERRNUM; + } + + /** * Check if the underlying Operating system descriptor is closed. * @return {...@code true} if descriptor is closed {...@code false} otherwise. */ Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=768570&r1=768569&r2=768570&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Sat Apr 25 18:11:33 2009 @@ -103,6 +103,15 @@ */ ACR_DECLARE(int) ACR_DescriptorSetInt(JNIEnv *env, jobject obj, int val); +/** + * Set the error number to the Descriptor object. + * @param env Current JNI environment + * @param obj Java Descriptor object use. + * @param err Error value to set. + * @return ACR error code on failure. + */ +ACR_DECLARE(int) ACR_DescriptorSetErr(JNIEnv *env, jobject obj, int err); + #ifdef __cplusplus } #endif Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=768570&r1=768569&r2=768570&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Sat Apr 25 18:11:33 2009 @@ -76,6 +76,12 @@ IFIELD_PTR }; +J_DECLARE_F_ID(0003) = { + NULL, + "IERRNUM", + "I" +}; + ACR_CLASS_LDEF(Descriptor) { int rv; @@ -85,6 +91,7 @@ J_LOAD_IFIELD(0000); J_LOAD_IFIELD(0001); J_LOAD_IFIELD(0002); + J_LOAD_IFIELD(0003); J_LOAD_METHOD(0000); return ACR_SUCCESS; @@ -111,11 +118,15 @@ ACR_JNI_EXPORT_DECLARE(jobject, Descriptor, nulld0)(ACR_JNISTDARGS) { + jobject nd; UNREFERENCED_O; if (!_clazzn.i) { initd0(_E); } - return ACR_DescriptorCreate(_E, -1, NULL, NULL); + nd = ACR_DescriptorCreate(_E, -1, NULL, NULL); + SET_IFIELD_I(0003, nd, ACR_EBADF); + + return nd; } ACR_JNI_EXPORT_DECLARE(void, Descriptor, close0)(ACR_JNISTDARGS) @@ -307,3 +318,19 @@ return ACR_ECLASSNOTFOUND; } } + +ACR_DECLARE(int) ACR_DescriptorSetErr(ACR_JNISTDARGS, int e) +{ + if (_clazzn.i && J4MID(0000)) { + SET_IFIELD_I(0003, _O, e); +#ifdef _JNI_CHECK_EXCEPTIONS + if ((*_E)->ExceptionCheck(_E)) { + return ACR_EGENERAL; + } +#endif + return ACR_SUCCESS; + } + else { + return ACR_ECLASSNOTFOUND; + } +} Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=768570&r1=768569&r2=768570&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Sat Apr 25 18:11:33 2009 @@ -22,6 +22,7 @@ import java.io.File; import junit.framework.*; +import org.apache.commons.runtime.io.Status; /** * Native Test. * The native methods are compiled only when @@ -327,6 +328,15 @@ assertTrue("Closed", d.isClosed()); } + public void testDescriptorNullErrno() + throws Throwable + { + Descriptor d = Descriptor.NULL; + assertNotNull("Descriptor", d); + assertTrue("Closed", d.isClosed()); + assertEquals("Errno", Status.EBADF, d.errno()); + } + public void testDescriptorCb() throws Throwable {