commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1203851 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/callback.h modules/openssl/password.c shared/callback.c
Date Fri, 18 Nov 2011 21:26:49 GMT
Author: mturk
Date: Fri Nov 18 21:26:49 2011
New Revision: 1203851

URL: http://svn.apache.org/viewvc?rev=1203851&view=rev
Log:
Simplify native callback and axe all non java code

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/callback.h
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c
    commons/sandbox/runtime/trunk/src/main/native/shared/callback.c

Modified: 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=1203851&r1=1203850&r2=1203851&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/callback.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/callback.h Fri Nov 18 21:26:49
2011
@@ -39,20 +39,10 @@ enum {
 };
 
 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      */
     int                        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 */
@@ -63,18 +53,6 @@ ACR_CLASS_CTOR(Callback);
 ACR_CLASS_DTOR(Callback);
 
 /**
- * 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_callback_t *
-AcrCallbackCreate(JNI_STDENV, void *refd, size_t size, int 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.
@@ -84,8 +62,8 @@ AcrCallbackCreate(JNI_STDENV, void *refd
  * @param handler Callback function pointer.
  */
 acr_callback_t *
-AcrCallbackAttach(JNI_STDARGS, jobject refd, size_t size,
-                  int type, acr_callback_handler_fn_t *handler);
+AcrCallbackAttach(JNI_STDARGS, jobject refd, size_t size, int type);
+
 /**
  * Free the memory associated with this Callback.
  * @param env Current JNI environment
@@ -103,7 +81,7 @@ AcrCallbackFree(JNI_STDENV, acr_callback
  * @param rv Return value from the callback method.
  */
 int
-AcrCallbackRun(JNI_STDENV, acr_callback_t *cb, void *ctx, int val, int *rv);
+AcrCallbackRun(JNI_STDENV, acr_callback_t *cb,  jobject ctx, int val, int *rv);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c?rev=1203851&r1=1203850&r2=1203851&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c Fri Nov 18 21:26:49
2011
@@ -153,7 +153,7 @@ ACR_SSL_EXPORT(jlong, SSLPasswordCallbac
     pc = ACR_TALLOC(ssl_pass_cb_t);
     if (pc == 0)
         return 0;
-    pc->cb = AcrCallbackAttach(env, obj, 0, 0, ACR_CALLBACK_NORMAL, 0);
+    pc->cb = AcrCallbackAttach(env, obj, 0, 0, ACR_CALLBACK_NORMAL);
     if (pc->cb == 0) {
         AcrFree(pc);
         return 0;

Modified: 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=1203851&r1=1203850&r2=1203851&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Fri Nov 18 21:26:49 2011
@@ -53,32 +53,13 @@ ACR_CLASS_DTOR(Callback)
 }
 
 acr_callback_t *
-AcrCallbackCreate(JNI_STDENV, void *refd,
-                  size_t size, int type, acr_callback_handler_fn_t *handler)
+AcrCallbackAttach(JNI_STDARGS, jobject refd, size_t size, int type)
 {
 
     acr_callback_t *cb = ACR_EALLOC(acr_callback_t, size);
     if (cb == 0)
         return 0;
-    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_callback_t *
-AcrCallbackAttach(JNI_STDARGS, jobject refd, size_t size, int type,
-                  acr_callback_handler_fn_t *handler)
-{
-
-    acr_callback_t *cb = ACR_EALLOC(acr_callback_t, size);
-    if (cb == 0)
-        return 0;
-    if (IS_VALID_HANDLE(env) && IS_VALID_HANDLE(obj)) {
+    if (IS_VALID_HANDLE(obj)) {
         cb->thiz = (*env)->NewWeakGlobalRef(env, obj);
         if (cb->thiz == 0)
             goto cleanup;
@@ -89,14 +70,13 @@ AcrCallbackAttach(JNI_STDARGS, jobject r
         }
     }
     cb->type    = type;
-    cb->handler = handler;
     cb->size    = sizeof(acr_callback_t) + size;
     if (size)
         cb->ctx = &cb->context[0];
     return cb;
 
 cleanup:
-    if (IS_VALID_HANDLE(env) && cb->thiz)
+    if (cb->thiz)
         (*env)->DeleteWeakGlobalRef(env, cb->thiz);
     AcrFree(cb);
     return NULL;
@@ -119,86 +99,67 @@ AcrCallbackFree(JNI_STDENV, acr_callback
 }
 
 int
-AcrCallbackRun(JNI_STDENV, acr_callback_t *cb, void *ctx, int val, int *rv)
+AcrCallbackRun(JNI_STDENV, acr_callback_t *cb,  jobject ctx, int val, int *rv)
 {
     int unused;
     int rc = ACR_ECLASSNOTFOUND;
+    jobject r = 0;
+    jobject o;
 
     
     if (cb == 0)
         return ACR_EINVAL;
     if (rv == 0)
         rv = &unused;
-    if (env == 0 && cb->thiz) {
+    if (cb->thiz == 0) {
+        /* Either invalid or already handled */
+        return rc;
+    }
+    if (env == 0) {
         /* Get JNIEnv only if needed
          */
         env = AcrGetJNIEnv();
         if (IS_INVALID_HANDLE(env))
             return ACR_ENOJNIENV;
     }
-    if (cb->handler != 0) {
-        /* This is native callback
+    o = (*env)->NewLocalRef(env, cb->thiz);
+    if (o == 0) {
+        /* Object was garbage collected.
+         * TODO: Check for appropriate errno.
          */
-        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
+        return ACR_DETACH;
+    }
+    if (cb->data != 0)
+        ctx = r = (*env)->NewLocalRef(env, cb->data);
+    if (cb->type == ACR_CALLBACK_SYNC) {
+        /* Syncronize the access to the callback object
          */
-        *rv = (*cb->handler)(env, cb, &ctx, val);
-        if (cb->type == ACR_CALLBACK_SYNC) {
+        if ((*env)->MonitorEnter(env, o)) {
+            /* Object locking failed */
+            return ACR_ENOLOCK;
         }
-        rc = 0;
-    }
-    if (cb->thiz == 0) {
-        /* Either invalid or already handled */
-        return rc;
     }
-    else {
-        jobject d = 0;
-        jobject o = (*env)->NewLocalRef(env, cb->thiz);
-        if (o == 0) {
-            /* Object was garbage collected.
-             * TODO: Check for appropriate errno.
-             */
-            return ACR_DETACH;
-        }
-        if (ctx == 0 && cb->data)
-            d = (*env)->NewLocalRef(env, cb->data);
-        else
-            d = (jobject)ctx;
-        if (cb->type == ACR_CALLBACK_SYNC) {
-            /* Syncronize the access to the callback object
-             */
-            if ((*env)->MonitorEnter(env, o)) {
-                /* Object locking failed */
-                return ACR_ENOLOCK;
-            }
-        }
-        rc = 0;
-        (*env)->ExceptionClear(env);
-        /* Execute the callback method
+    rc = 0;
+    (*env)->ExceptionClear(env);
+    /* Execute the callback method
+     */
+    *rv = CALL_METHOD2(Int, 0000, o, ctx, val);
+    if ((*env)->ExceptionCheck(env)) {
+        /* Clear exceptions generated in java handler method.
+         * There is a good chance that the callee of our
+         * method will throw its own exception in such cases.
          */
-        *rv = CALL_METHOD2(Int, 0000, o, d, val);
-        if ((*env)->ExceptionCheck(env)) {
-            /* Clear exceptions generated in java handler method.
-             * There is a good chance that the callee of our
-             * method will throw its own exception in such cases.
-             */
-            rc = ACR_EFAULT;
-            (*env)->ExceptionClear(env);
-        }
-        if (cb->type == ACR_CALLBACK_SYNC) {
-            /* Unlock */
-            (*env)->MonitorExit(env, o);
-        }
-        if (ctx == 0 && d)
-            (*env)->DeleteLocalRef(env, d);
-        (*env)->DeleteLocalRef(env, o);
-
-        return rc;
+        rc = ACR_EFAULT;
+        (*env)->ExceptionClear(env);
     }
+    if (cb->type == ACR_CALLBACK_SYNC) {
+        /* Unlock */
+        (*env)->MonitorExit(env, o);
+    }
+    if (r != 0)
+        (*env)->DeleteLocalRef(env, r);
+    (*env)->DeleteLocalRef(env, o);
+
+    return rc;
 }
 



Mime
View raw message