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/09/12 12:45:35 UTC

svn commit: r814138 - in /commons/sandbox/runtime/trunk/src: main/native/ main/native/include/ main/native/shared/ test/org/apache/commons/runtime/

Author: mturk
Date: Sat Sep 12 10:45:34 2009
New Revision: 814138

URL: http://svn.apache.org/viewvc?rev=814138&view=rev
Log:
Add callback support

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/callback.c   (with props)
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_env.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_object.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Sat Sep 12 10:45:34 2009
@@ -81,6 +81,7 @@
 COMMON_OBJS=\
 	$(SRCDIR)/shared/buildmark.$(OBJ) \
 	$(SRCDIR)/shared/bzip2.$(OBJ) \
+	$(SRCDIR)/shared/callback.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
 	$(SRCDIR)/shared/constp.$(OBJ) \
 	$(SRCDIR)/shared/crc32.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat Sep 12 10:45:34 2009
@@ -71,6 +71,7 @@
 COMMON_OBJS=\
 	$(SRCDIR)/shared/buildmark.$(OBJ) \
 	$(SRCDIR)/shared/bzip2.$(OBJ) \
+	$(SRCDIR)/shared/callback.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
 	$(SRCDIR)/shared/constp.$(OBJ) \
 	$(SRCDIR)/shared/crc32.$(OBJ) \

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h?rev=814138&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h Sat Sep 12 10:45:34 2009
@@ -0,0 +1,105 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_CALLBACK_H
+#define _ACR_CALLBACK_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_callback.h
+ * @brief
+ *
+ * ACR Callback from Native to Java API.
+ *
+ */
+
+typedef enum {
+    ACR_CALLBACK_NORMAL,
+    ACR_CALLBACK_SYNC
+} acr_callback_type_e;
+
+typedef struct acr_callback_t acr_callback_t;
+
+/**
+ * Callback handler function prototype.
+ * The handler function must check for data validity.
+ */
+typedef int (acr_callback_handler_fn_t)(JNIEnv *, acr_callback_t *,
+                                        void *, int);
+
+struct acr_callback_t {
+    size_t                     size;       /* Length of 'this' structure      */
+    acr_callback_type_e        type;       /* Type of this callback           */
+    acr_callback_handler_fn_t *handler;    /* Native handler callback         */
+    void                      *ctx;        /* Context data pointer            */
+    void                     **refd;       /* Generic 'reference to' pointer  */
+    jobject                    thiz;       /* Pointer to 'this' Java object   */
+    jobject                    data;       /* handler provided Java object    */
+    jint                       counter;    /* Reference or invocation counter */
+    char                       context[1]; /* Variable size context storage   */
+};
+
+/**
+ * Create and initialize a new Callback.
+ * @param env Current JNI environment
+ * @param refd Opaque data stored as reference inside callback.
+ * @param size Additional context size.
+ * @param type Callback type.
+ * @param handler Callback function pointer.
+ */
+ACR_DECLARE(acr_callback_t *) ACR_CallbackCreate(JNIEnv *_E, void *refd,
+                                                 size_t size,
+                                                 acr_callback_type_e type,
+                                                 acr_callback_handler_fn_t *handler);
+
+/**
+ * Create and attach a new Callback to Java object.
+ * @param env Current JNI environment
+ * @param obj Java Object representing callback instance.
+ * @param size Additional context size.
+ * @param type Callback type.
+ */
+ACR_DECLARE(acr_callback_t *) ACR_CallbackAttach(JNIEnv *env, jobject obj,
+                                                 size_t size,
+                                                 acr_callback_type_e type);
+/**
+ * Free the memory associated with this Callback.
+ * @param env Current JNI environment
+ * @param cb Callback to free.
+ */
+ACR_DECLARE(int) ACR_CallbackFree(JNIEnv *env, acr_callback_t *cb);
+
+/**
+ * Run the callback.
+ * @param env Current JNI environment
+ * @param cb Callback to run.
+ * @param ctx Arbitrary data passed to the handler.
+ * @param val Arbitrary value to pass to callback method.
+ * @param rv Return value from the callback method.
+ */
+ACR_DECLARE(int) ACR_CallbackRun(JNIEnv *_E, acr_callback_t *cb,
+                                 void *ctx, int val, int *rv);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_CALLBACK_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h
------------------------------------------------------------------------------
    svn:eol-style = native

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=814138&r1=814137&r2=814138&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 Sep 12 10:45:34 2009
@@ -63,7 +63,7 @@
  * The handler function must check for data validity.
  * Consecutive invocations will always contain NULL data.
  */
-typedef int (acr_descriptor_handler_fn_t)(JNIEnv *, jobject,
+typedef int (acr_descriptor_handler_fn_t)(JNIEnv *, void *,
                                           acr_descriptor_cb_type_e,
                                           acr_descriptor_cb_t *);
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_env.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_env.h?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_env.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_env.h Sat Sep 12 10:45:34 2009
@@ -62,5 +62,5 @@
 }
 #endif
 
-#endif /* _ACR_VM_H */
+#endif /* _ACR_ENV_H */
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Sat Sep 12 10:45:34 2009
@@ -425,6 +425,7 @@
 #define ACR_EISNULL         (ACR_OS_START_ERROR + 100)
 #define ACR_EINVALSIZ       (ACR_OS_START_ERROR + 101)
 #define ACR_ECLASSNOTFOUND  (ACR_OS_START_ERROR + 102)
+#define ACR_ENOJNIENV       (ACR_OS_START_ERROR + 103)
 
 /**
  * @defgroup ACR_STATUS_IS Status Value Tests

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_object.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_object.h?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_object.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_object.h Sat Sep 12 10:45:34 2009
@@ -81,6 +81,16 @@
  */
 ACR_DECLARE(void) ACR_ObjectFinalize(JNIEnv *env, jobject o);
 
+/**
+ * Get Object's method ID.
+ * @param env Current JNI environment.
+ * @param o Object to use..
+ * @param name Method name.
+ * @param sig JNI method signature.
+ */
+ACR_DECLARE(jmethodID) ACR_ObjectGetMethod(ACR_JNISTDARGS, const char *name,
+                                           const char *sig);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Sat Sep 12 10:45:34 2009
@@ -483,8 +483,11 @@
 #define CALL_METHOD0(T, I, O)  \
         (*_E)->Call##T##Method(_E, (O), _m##I##n.i)
 
-#define CALL_METHOD1(T, I, O, V)  \
-        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (V))
+#define CALL_METHOD1(T, I, O, A)  \
+        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A))
+
+#define CALL_METHOD2(T, I, O, A1, A2)  \
+        (*_E)->Call##T##Method(_E, (O), _m##I##n.i, (A1), (A2))
 
 #define SET_SARRAY_A(A, I, V)                               \
     if ((A) && (V)) {                                       \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h Sat Sep 12 10:45:34 2009
@@ -50,15 +50,6 @@
     const char  *s;
 } JAVA_F_ID;
 
-typedef struct acr_callback_t {
-    jobject     object;
-    jmethodID   method;
-    jint        counter;
-    const char  *name;
-    const char  *msig;
-    void        *opaque;
-} acr_callback_t;
-
 #define JSSIZE_MAX  1048576
 
 /* Standard Java classes */

Added: commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/callback.c?rev=814138&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Sat Sep 12 10:45:34 2009
@@ -0,0 +1,252 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_memory.h"
+#include "acr_error.h"
+#include "acr_descriptor.h"
+#include "acr_object.h"
+#include "acr_pointer.h"
+#include "acr_callback.h"
+#include "acr_tlsd.h"
+#include "acr_vm.h"
+
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    ACR_CLASS_PATH "Callback"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "callback",
+    "(Ljava/lang/Object;I)I"
+};
+
+ACR_CLASS_LDEF(Callback)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_METHOD(0000);
+
+    return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(Callback)
+{
+    ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(acr_callback_t *) ACR_CallbackCreate(JNIEnv *_E, void *refd,
+                                                 size_t size,
+                                                 acr_callback_type_e type,
+                                                 acr_callback_handler_fn_t *handler)
+{
+
+    acr_callback_t *cb = ACR_Calloc(_E, THROW_NMARK,
+                                    sizeof(acr_callback_t) + size);
+    if (cb == NULL)
+        return NULL;
+    cb->type    = type;
+    cb->handler = handler;
+    cb->size    = sizeof(acr_callback_t) + size;
+    if (size)
+        cb->ctx  = &cb->context[0];
+    if (refd)
+        cb->refd = &refd;
+    return cb;
+}
+
+ACR_DECLARE(acr_callback_t *) ACR_CallbackAttach(ACR_JNISTDARGS, size_t size,
+                                                 acr_callback_type_e type)
+{
+
+    acr_callback_t *cb = ACR_Calloc(_E, THROW_NMARK,
+                                    sizeof(acr_callback_t) + size);
+    if (cb == NULL)
+        return NULL;
+    if (IS_VALID_HANDLE(_E) && IS_VALID_HANDLE(_O)) {
+        cb->thiz = (*_E)->NewWeakGlobalRef(_E, _O);
+        if (cb->thiz == NULL)
+            goto cleanup;
+    }
+    cb->type    = type;
+    cb->size    = sizeof(acr_callback_t) + size;
+    if (size)
+        cb->ctx = &cb->context[0];
+    return cb;
+
+cleanup:
+    if (IS_VALID_HANDLE(_E) && cb->thiz)
+        (*_E)->DeleteWeakGlobalRef(_E, cb->thiz);
+    ACR_Free(INVALID_MEMORY_VALUE, THROW_NMARK, cb);
+    return NULL;
+}
+
+ACR_DECLARE(int) ACR_CallbackFree(JNIEnv *_E, acr_callback_t *cb)
+{
+
+    if (cb == NULL)
+        return ACR_EISNULL;
+    if (_E == NULL && cb->thiz)
+        _E = ACR_GetJNIEnv();
+    if (IS_VALID_HANDLE(_E)) {
+        if (cb->thiz)
+            (*_E)->DeleteWeakGlobalRef(_E, cb->thiz);
+    }
+    ACR_Free(_E, THROW_NMARK, cb);
+    return 0;
+}
+
+ACR_DECLARE(int) ACR_CallbackRun(JNIEnv *_E, acr_callback_t *cb,
+                                 void *ctx, int val, int *rv)
+{
+    int rc = ACR_ECLASSNOTFOUND;
+
+    if (cb == NULL) {
+        return ACR_EINVAL;
+    }
+    if (cb->handler) {
+        /* This is native callback
+         */
+        if (cb->type == ACR_CALLBACK_SYNC) {
+            /* TODO: Syncronize the access to the callback hander.
+             *       We would need the thread lock for that.
+             *       Implement if API would require such feature.
+             */
+        }
+        /* Execute the handler
+         */
+        *rv = (*cb->handler)(_E, cb, ctx, val);
+        if (cb->type == ACR_CALLBACK_SYNC) {
+        }
+        rc = ACR_SUCCESS;
+    }
+    if (cb->thiz == NULL) {
+        return rc;
+    }
+    if (_E == NULL)
+        _E = ACR_GetJNIEnv();
+    if (IS_VALID_HANDLE(_E)) {
+        jobject o = (*_E)->NewLocalRef(_E, cb->thiz);
+        if (o == NULL) {
+            /* Object was garbage collected.
+             * TODO: Check for appropriate errno.
+             */
+            return ACR_DETACH;
+        }
+        if (cb->type == ACR_CALLBACK_SYNC) {
+            /* Syncronize the access to the callback object
+             */
+            if ((*_E)->MonitorEnter(_E, o)) {
+                /* Object locking failed */
+                return ACR_ENOLOCK;
+            }
+        }
+        /* Execute the callback method
+         */
+        *rv = CALL_METHOD2(Int, 0000, o, cb->data, val);
+        if (cb->type == ACR_CALLBACK_SYNC) {
+            /* Unlock */
+            (*_E)->MonitorExit(_E, o);
+        }
+        (*_E)->DeleteLocalRef(_E, o);
+
+        return 0;
+    }
+    else {
+        /* Failed obtaining JNIEnv.
+         */
+        return ACR_ENOJNIENV;
+    }
+}
+
+#ifdef ACR_ENABLE_TEST
+ACR_JNI_EXPORT_DECLARE(int, TestCallback, test00)(ACR_JNISTDARGS, jobject o, jint d)
+{
+    acr_callback_t *cb;
+
+    if ((cb = ACR_CallbackAttach(_E, o, 0, ACR_CALLBACK_SYNC))) {
+        int i;
+        fputc('\n', stdout);
+        for (i = 0; i < 10; i++) {
+            int rv;
+            int rc;
+
+            rc = ACR_CallbackRun(NULL, cb, NULL, i, &rv);
+            if (rc) {
+                fprintf(stderr, "CallbackRun failed with %d\n", rc);
+                fflush(stderr);
+                break;
+            }
+            else {
+                fprintf(stdout, "CallbackRun (%d) return %d\n", i, rv);
+                fflush(stdout);
+                if (rv < 0)
+                    break;
+            }
+        }
+        return ACR_CallbackFree(NULL, cb);
+    }
+    return 1;
+}
+
+static int test_handler(JNIEnv *_E, acr_callback_t *cb,
+                        void *ctx, int val)
+{
+    return val;
+}
+
+ACR_JNI_EXPORT_DECLARE(int, TestCallback, test01)(ACR_JNISTDARGS, jint d)
+{
+    acr_callback_t *cb;
+
+    if ((cb = ACR_CallbackCreate(_E, NULL, 0, ACR_CALLBACK_SYNC, test_handler))) {
+        int i;
+        fputc('\n', stdout);
+        for (i = 0; i < 5; i++) {
+            int rv;
+            int rc;
+
+            rc = ACR_CallbackRun(NULL, cb, NULL, i, &rv);
+            if (rc) {
+                fprintf(stderr, "CallbackRun failed with %d\n", rc);
+                fflush(stderr);
+                break;
+            }
+            else {
+                fprintf(stdout, "[native] CallbackRun (%d) return %d\n", i, rv);
+                fflush(stdout);
+                if (rv < 0)
+                    break;
+            }
+        }
+        return ACR_CallbackFree(NULL, cb);
+    }
+    return 1;
+}
+
+#endif

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sat Sep 12 10:45:34 2009
@@ -373,6 +373,7 @@
 ACR_CLASS_LDEC(Descriptor);
 ACR_CLASS_LDEC(AbstractPointer);
 ACR_CLASS_LDEC(ConstPointer);
+ACR_CLASS_LDEC(Callback);
 ACR_CLASS_LDEC(DirectBuffer);
 ACR_CLASS_LDEC(MbString);
 ACR_CLASS_LDEC(Group);
@@ -389,6 +390,7 @@
     ACR_CLASS_LRUN(Descriptor);
     ACR_CLASS_LRUN(AbstractPointer);
     ACR_CLASS_LRUN(ConstPointer);
+    ACR_CLASS_LRUN(Callback);
     ACR_CLASS_LRUN(DirectBuffer);
     ACR_CLASS_LRUN(MbString);
     ACR_CLASS_LRUN(Group);
@@ -411,6 +413,7 @@
     ACR_CLASS_URUN(Descriptor);
     ACR_CLASS_URUN(AbstractPointer);
     ACR_CLASS_URUN(ConstPointer);
+    ACR_CLASS_URUN(Callback);
     ACR_CLASS_URUN(DirectBuffer);
     ACR_CLASS_URUN(MbString);
     ACR_CLASS_URUN(Group);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Sep 12 10:45:34 2009
@@ -382,6 +382,8 @@
             return "The given argument size is invalid";
         case ACR_ECLASSNOTFOUND:
             return "The specified Java Class was not found";
+        case ACR_ENOJNIENV:
+            return "JNI Environment was not provided";
         default:
             return "Error string not specified yet";
     }

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=814138&r1=814137&r2=814138&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Sat Sep 12 10:45:34 2009
@@ -47,6 +47,7 @@
         suite.addTest(TestSemaphore.suite());
         suite.addTest(TestSharedMemory.suite());
         suite.addTest(TestMemoryMap.suite());
+        suite.addTest(TestCallback.suite());
         return suite;
     }
 

Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java?rev=814138&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java Sat Sep 12 10:45:34 2009
@@ -0,0 +1,86 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.exception.*;
+import junit.framework.*;
+
+/**
+ * Callback tests
+ */
+public class TestCallback extends TestCase
+{
+
+    private static native int test00(Object o, int d);
+    private static native int test01(int d);
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(TestCallback.class);
+        return suite;
+    }
+
+    class MyData {
+        public int val;
+        public MyData()
+        {
+            val = 0;
+        }
+        public void myMethod()
+        {
+            val++;
+        }
+    }
+    class MyCallback implements Callback {
+        public int counter;
+        public MyCallback() {
+            counter = 0;
+        }
+        public int callback(Object o, int val) {
+            counter++;
+            if (o != null) {
+                MyData d = (MyData)o;
+                d.myMethod();
+            }
+            if (counter > 5)
+                return -1;
+            else
+                return counter;
+        }
+    }
+    protected void setUp()
+        throws Exception
+    {
+        System.loadLibrary("acr");
+    }
+
+    public void testSimpleCallback()
+        throws Exception
+    {
+        MyCallback cb = new MyCallback();
+        int rc = test00(cb, 0);
+        assertEquals("Callback result", 0, rc);
+    }
+
+    public void testNativeCallback()
+        throws Exception
+    {
+        int rc = test01(0);
+        assertEquals("Callback result", 0, rc);
+    }
+
+}
+

Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native