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 13:13:22 UTC
svn commit: r814144 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/Callback.java native/include/acr_callback.h
native/shared/callback.c
Author: mturk
Date: Sat Sep 12 11:13:22 2009
New Revision: 814144
URL: http://svn.apache.org/viewvc?rev=814144&view=rev
Log:
Pass the data as local reference
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Callback.java
commons/sandbox/runtime/trunk/src/main/native/include/acr_callback.h
commons/sandbox/runtime/trunk/src/main/native/shared/callback.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Callback.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Callback.java?rev=814144&r1=814143&r2=814144&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Callback.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Callback.java Sat Sep 12 11:13:22 2009
@@ -37,7 +37,7 @@
public interface Callback
{
/**
- * Callback method.
+ * Callback method executed from Native code.
* <p>
* If {@code callback} returns {@code zero} the operation continues.
* If negative value is returned the operation breaks. If positive
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=814144&r1=814143&r2=814144&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 Sat Sep 12 11:13:22 2009
@@ -74,11 +74,12 @@
* Create and attach a new Callback to Java object.
* @param env Current JNI environment
* @param obj Java Object representing callback instance.
+ * @param refd Java Object representing additional data passed to the callback.
* @param size Additional context size.
* @param type Callback type.
*/
ACR_DECLARE(acr_callback_t *) ACR_CallbackAttach(JNIEnv *env, jobject obj,
- size_t size,
+ jobject refd, size_t size,
acr_callback_type_e type);
/**
* Free the memory associated with this Callback.
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=814144&r1=814143&r2=814144&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/callback.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/callback.c Sat Sep 12 11:13:22 2009
@@ -80,7 +80,8 @@
return cb;
}
-ACR_DECLARE(acr_callback_t *) ACR_CallbackAttach(ACR_JNISTDARGS, size_t size,
+ACR_DECLARE(acr_callback_t *) ACR_CallbackAttach(ACR_JNISTDARGS, jobject refd,
+ size_t size,
acr_callback_type_e type)
{
@@ -92,6 +93,11 @@
cb->thiz = (*_E)->NewWeakGlobalRef(_E, _O);
if (cb->thiz == NULL)
goto cleanup;
+ if (IS_VALID_HANDLE(refd)) {
+ cb->data = (*_E)->NewWeakGlobalRef(_E, refd);
+ if (cb->data == NULL)
+ goto cleanup;
+ }
}
cb->type = type;
cb->size = sizeof(acr_callback_t) + size;
@@ -151,6 +157,7 @@
if (_E == NULL)
_E = ACR_GetJNIEnv();
if (IS_VALID_HANDLE(_E)) {
+ jobject d = NULL;
jobject o = (*_E)->NewLocalRef(_E, cb->thiz);
if (o == NULL) {
/* Object was garbage collected.
@@ -158,6 +165,10 @@
*/
return ACR_DETACH;
}
+ if (ctx == NULL && cb->data)
+ d = (*_E)->NewLocalRef(_E, cb->data);
+ else
+ d = (jobject)ctx;
if (cb->type == ACR_CALLBACK_SYNC) {
/* Syncronize the access to the callback object
*/
@@ -168,11 +179,13 @@
}
/* Execute the callback method
*/
- *rv = CALL_METHOD2(Int, 0000, o, cb->data, val);
+ *rv = CALL_METHOD2(Int, 0000, o, d, val);
if (cb->type == ACR_CALLBACK_SYNC) {
/* Unlock */
(*_E)->MonitorExit(_E, o);
}
+ if (ctx == NULL && d)
+ (*_E)->DeleteLocalRef(_E, d);
(*_E)->DeleteLocalRef(_E, o);
return 0;
@@ -189,7 +202,7 @@
{
acr_callback_t *cb;
- if ((cb = ACR_CallbackAttach(_E, o, 0, ACR_CALLBACK_SYNC))) {
+ if ((cb = ACR_CallbackAttach(_E, o, NULL, 0, ACR_CALLBACK_SYNC))) {
int i;
fputc('\n', stdout);
for (i = 0; i < 10; i++) {