Binding java in progress...

This commit is contained in:
Mikaël Ates 2010-12-14 16:24:34 +01:00
parent a50253579f
commit eb315b32cb
4 changed files with 47 additions and 39 deletions

View File

@ -1,9 +1,9 @@
#! /usr/bin/env python
#
# Lasso - A free implementation of the Liberty Alliance specifications.
# Cryptic - A free implementation of the Liberty Alliance specifications.
#
# Copyright (C) 2004-2007 Entr'ouvert
# http://lasso.entrouvert.org
# Copyright (C) 2009-2010 Entr'ouvert
# http://cryptic.entrouvert.org
#
# Authors: See AUTHORS file in top-level directory.
#

View File

@ -293,12 +293,17 @@ protected static native void destroy(long cptr);
##################################"
def generate_JNI_functions(self, m, fd):
import sys
print >> sys.stderr, '%s %s' %(m.name,m.return_type)
##################################"
#if m.return_type.startswith('Cryptic'):
if m.name.endswith('_new'):
##################################"
jtype = 'long'
else:
jtype = self.JNI_return_type(m.return_type)
name = self.JNI_function_name(m)
print >> fd, ' public static native %s %s(%s);' % (jtype,name, generate_arg_list3(self,m.args))
print >> fd, ' public static native %s %s(%s);' % (jtype, name, generate_arg_list3(self,m.args))
def JNI_member_function_prefix(self,c,m):
#############################"
@ -521,7 +526,10 @@ protected static native void destroy(long cptr);
# print >> fd, '''static PyObject*
#%s(PyObject *self, PyObject *args)
#{''' % name
##################################"
#if m.return_type.startswith('Cryptic'):
if m.name.endswith('_new'):
##################################"
jtype = 'jlong'
else:
jtype = self.jni_return_type(m.return_type)
@ -599,7 +607,10 @@ protected static native void destroy(long cptr);
# Return
if m.return_type:
##################################"
#if m.return_type.startswith('Cryptic'):
if m.name.endswith('_new'):
##################################"
print >> fd, ' r_value = (jlong)(ptrdiff_t) return_value;'
else:
options = {}
@ -849,6 +860,9 @@ protected static native void destroy(long cptr);
print >> fd, ' static public %s %s(%s) {' % (class_name, name, generate_arg_list(self,m.args))
print >> fd, ' return (%s) CrypticJNI.%s(%s);' % (class_name, self.JNI_function_name(m),generate_arg_list2(m.args))
print >> fd, ' }'
#print >> fd, ' public %s(%s) {' % (class_name, generate_arg_list(self,m.args))
#print >> fd, ' super(CrypticJNI.%s(%s));' % (self.JNI_function_name(m),generate_arg_list2(m.args))
#print >> fd, ' }'
print >> fd, ' /* Setters and getters */'
for m in c.members:
type, name, options = m

View File

@ -99,8 +99,8 @@ static jint extractInt(JNIEnv *env, jobject arg);
static int
bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr)
{
bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr) {
g_error_if_fail(env);
if (bn) {
char *hex = BN_bn2hex(bn);
*jstr = (*env)->NewStringUTF(env, hex);
@ -109,22 +109,19 @@ bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr)
} else {
*jstr = NULL;
}
return 1;
return 1;
}
static int
get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) {
g_error_if_fail(env);
jsize i;
jclass cls;
g_error_if_fail (env);
int size = 0;
while(list[size] != NULL) size++;
cls = get_jclass_by_name(env, "java/lang/String");
cryptic_return_val_if_fail(cls, 0);
cryptic_return_val_if_fail(create_object_array(env, "java/lang/String", size, jarr), 0);
for (i=0; i<size; i++) {
jobject item;
@ -136,22 +133,21 @@ get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) {
static int
jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn) {
g_error_if_fail(env);
const char *local_str = NULL;
int r;
cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0);
if (local_str) {
if(local_str[0] == '-'){
r = BN_hex2bn(bn, local_str);
BN_set_negative(*bn,1);
}else{
r = BN_hex2bn(bn, local_str);
}
if (local_str[0] == '-') {
r = BN_hex2bn(bn, local_str);
BN_set_negative(*bn,1);
} else {
r = BN_hex2bn(bn, local_str);
}
release_local_string(env, jstr, local_str);
if (r<0 || *bn == NULL) {
return 0;
}
if (r<0 || *bn == NULL) {
return 0;
}
} else {
*bn = NULL;
}
@ -160,22 +156,22 @@ jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn) {
static int
set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr) {
g_error_if_fail(env);
jobject element = NULL;
jsize size = 0;
jsize i = 0;
g_error_if_fail (list && env);
if (jarr) {
if (! get_array_size(env, jarr, &size)){
if (! get_array_size(env, jarr, &size)) {
return 0;
}
list = NULL;
list = (BIGNUM***) g_malloc0(sizeof(BIGNUM***));
list[0] = NULL;
list[0] = (BIGNUM**) g_malloc0(size*sizeof(BIGNUM**));
for (i=0; i<size; i++){
for (i=0; i<size; i++) {
list[0][i] = NULL;
if (! get_array_element(env, jarr, i, &element)){
if (! get_array_element(env, jarr, i, &element)) {
return 0;
}
jstring_to_bignum(env,element,&list[0][i]);
@ -187,23 +183,21 @@ set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr) {
static int
int_to_jint(JNIEnv *env, int i, jint *ji)
{
return 1;
g_error_if_fail(env);
return 1;
}
static int
get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
g_error_if_fail(env);
jsize i;
jclass cls;
g_error_if_fail (env);
int size = 0;
while(&list[size] != NULL) size++;
cls = get_jclass_by_name(env, "java/lang/Interger");
cls = get_jclass_by_name(env, "java/lang/Integer");
cryptic_return_val_if_fail(cls, 0);
cryptic_return_val_if_fail(create_object_array(env, "java/lang/Interger", size, jarr), 0);
cryptic_return_val_if_fail(create_object_array(env, "java/lang/Integer", size, jarr), 0);
for (i=0; i<size; i++) {
jint item;
int_to_jint(env,list[i],&item);
@ -214,6 +208,7 @@ get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
static int
jint_to_int(JNIEnv *env, jint ji, int *i) {
g_error_if_fail(env);
return 1;
}
@ -222,10 +217,9 @@ set_list_of_int(JNIEnv *env, int **list, jobjectArray jarr) {
jobject element = NULL;
jsize size = 0;
jsize i = 0;
g_error_if_fail (list && env);
if (jarr) {
if (! get_array_size(env, jarr, &size)){
if (! get_array_size(env, jarr, &size)) {
return 0;
}
list = NULL;
@ -520,7 +514,7 @@ create_class_name(char *dest, const char *typename) {
ret = strstr(typename, "Cryptic");
if (ret) {
typename = ret+5;
typename = ret+7;
}
strncpy(dest+sizeof(CRYPTIC_ROOT)-1, typename,50);
dest[sizeof(CRYPTIC_ROOT)+49] = 0;

View File

@ -1,7 +1,7 @@
# Lasso - A free implementation of the Liberty Alliance specifications.
# Cryptic - A free implementation of the Liberty Alliance specifications.
#
# Copyright (C) 2004-2007 Entr'ouvert
# http://lasso.entrouvert.org
# Copyright (C) 2009-2010 Entr'ouvert
# http://cryptic.entrouvert.org
#
# Authors: See AUTHORS file in top-level directory.
#