You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/07/01 11:49:11 UTC
svn commit: r790093 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ main/native/include/
main/native/shared/ main/native/test/ test/org/apache/commons/runtime/
Author: mturk
Date: Wed Jul 1 09:49:11 2009
New Revision: 790093
URL: http://svn.apache.org/viewvc?rev=790093&view=rev
Log:
Add Descriptor context object
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/main/native/test/testcase.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=790093&r1=790092&r2=790093&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 Wed Jul 1 09:49:11 2009
@@ -46,6 +46,19 @@
*/
private final int IDFLAGS;
+ /* Descriptor's attached context.
+ * This is opaque data associated with {@code this} Descriptor.
+ * <p>
+ * It usually refrences the object that holds an reference to
+ * {@code this} descriptor, and it is used by native code to signal
+ * the conatainer object {@code this} Descriptor state change.
+ * </p>
+ * <p>
+ * <b>Unstable API</b>
+ * </p>
+ */
+ private Object CONTEXT;
+
/*
* Descriptor can be only created from native code.
* Suppress any instantiation except form internal classes.
@@ -176,6 +189,25 @@
}
/**
+ * Get the descriptor context object.
+ * This method is public, but it is intended for the internal use only.
+ */
+ public final Object getContext()
+ {
+ return CONTEXT;
+ }
+
+ /**
+ * Set the descriptor context object.
+ * This method is public, but it is intended for the internal use only.
+ * @param ctx context to set.
+ */
+ public final void setContext(Object ctx)
+ {
+ CONTEXT = ctx;
+ }
+
+ /**
* 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=790093&r1=790092&r2=790093&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 Wed Jul 1 09:49:11 2009
@@ -123,6 +123,14 @@
ACR_DECLARE(void *) ACR_DescriptorGetPtr(JNIEnv *env, jobject obj);
/**
+ * Get the context object from the Descriptor object.
+ * @param env Current JNI environment
+ * @param obj Java Descriptor object use.
+ * @return Underlying descriptor context object.
+ */
+ACR_DECLARE(jobject) ACR_DescriptorGetCtx(JNIEnv *env, jobject obj);
+
+/**
* Set the native pointer descriptor to the Descriptor object.
* @param env Current JNI environment
* @param obj Java Descriptor object use.
@@ -149,6 +157,15 @@
*/
ACR_DECLARE(int) ACR_DescriptorSetErr(JNIEnv *env, jobject obj, int err);
+/**
+ * Set the context object to the Descriptor object.
+ * @param env Current JNI environment
+ * @param obj Java Descriptor object use.
+ * @param err context object to set.
+ * @return ACR error code on failure.
+ */
+ACR_DECLARE(int) ACR_DescriptorSetCtx(JNIEnv *env, jobject obj, jobject ctx);
+
#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=790093&r1=790092&r2=790093&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Wed Jul 1 09:49:11 2009
@@ -89,6 +89,12 @@
"I"
};
+J_DECLARE_F_ID(0005) = {
+ NULL,
+ "CONTEXT",
+ "Ljava/lang/Object;"
+};
+
ACR_CLASS_LDEF(Descriptor)
{
int rv;
@@ -100,6 +106,7 @@
J_LOAD_IFIELD(0002);
J_LOAD_IFIELD(0003);
J_LOAD_IFIELD(0004);
+ J_LOAD_IFIELD(0005);
J_LOAD_METHOD(0000);
return ACR_SUCCESS;
@@ -345,3 +352,25 @@
}
}
+ACR_DECLARE(int) ACR_DescriptorSetCtx(ACR_JNISTDARGS, jobject ctx)
+{
+ if (_clazzn.i && J4MID(0000)) {
+ SET_IFIELD_O(0005, _O, ctx);
+ return ACR_SUCCESS;
+ }
+ else {
+ return ACR_ECLASSNOTFOUND;
+ }
+}
+
+ACR_DECLARE(jobject) ACR_DescriptorGetCtx(ACR_JNISTDARGS)
+{
+ if (_clazzn.i && J4MID(0000)) {
+ return GET_IFIELD_O(0005, _O);
+ }
+ else {
+ ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
+ return NULL;
+ }
+}
+
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=790093&r1=790092&r2=790093&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jul 1 09:49:11 2009
@@ -370,6 +370,11 @@
return n == e ? n : 0;
}
+ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test034)(ACR_JNISTDARGS, jobject d)
+{
+ jstring s = ACR_NewJavaStringA(_E, "My Context");
+ return ACR_DescriptorSetCtx(_E, d, s);
+}
ACR_JNI_EXPORT_DECLARE(jint, TestFile, ftest00)(ACR_JNISTDARGS, jint d)
{
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=790093&r1=790092&r2=790093&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 Wed Jul 1 09:49:11 2009
@@ -83,6 +83,7 @@
private static native String[] test031(String s);
private static native String[] test032(String s);
private static native int test033(int d);
+ private static native int test034(Descriptor p);
private static native String test100(String s);
@@ -573,6 +574,21 @@
Thread.sleep(200);
}
+ public void testDescriptorCtx()
+ throws Throwable
+ {
+ Descriptor d = test021(2303, 0);
+ assertNotNull("Descriptor", d);
+ test034(d);
+ assertEquals("Context", "My Context", (String)d.getContext());
+ d.close();
+ d = null;
+ System.gc();
+ // This should be enough for a gc
+ // from Pointer.finalize()
+ Thread.sleep(200);
+ }
+
public void testUtf16String()
throws Throwable
{