[libinline-java-perl] 52/398: Initial revision
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:42:44 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.55
in repository libinline-java-perl.
commit 20205d6e0b7dbae662abf168a1e1abdced923352
Author: patrick <>
Date: Wed Apr 4 19:39:16 2001 +0000
Initial revision
---
Java/JNI.pm | 10 +++
Java/JNI.xs | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
Java/Makefile.PL | 14 ++++
Java/typemap | 23 ++++++
4 files changed, 259 insertions(+)
diff --git a/Java/JNI.pm b/Java/JNI.pm
new file mode 100644
index 0000000..3ac200e
--- /dev/null
+++ b/Java/JNI.pm
@@ -0,0 +1,10 @@
+package Inline::Java::JNI ;
+ at Inline::Java::JNI::ISA = qw(DynaLoader) ;
+
+
+use strict ;
+
+$Inline::Java::JNI::VERSION = '0.10' ;
+
+require DynaLoader ;
+Inline::Java::JNI->bootstrap($Inline::Java::JNI::VERSION) ;
diff --git a/Java/JNI.xs b/Java/JNI.xs
new file mode 100644
index 0000000..de93fed
--- /dev/null
+++ b/Java/JNI.xs
@@ -0,0 +1,212 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+
+/* Include the JNI header file */
+#include "jni.h"
+
+
+/* JNI structure */
+typedef struct {
+ JNIEnv *env ;
+ JavaVM *jvm ;
+ jclass ijs_class ;
+ jobject ijs ;
+ jboolean debug ;
+} InlineJavaJNIVM ;
+
+
+void debug_ex(InlineJavaJNIVM *this){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+}
+
+
+MODULE = Inline::Java::JNI PACKAGE = Inline::Java::JNI
+
+
+PROTOTYPES: DISABLE
+
+
+InlineJavaJNIVM *
+new(CLASS, classpath, debug)
+ char * CLASS
+ char * classpath
+ int debug
+
+ PREINIT:
+ JavaVMInitArgs vm_args ;
+ JavaVMOption options[2] ;
+ jint res ;
+ char * cp ;
+
+ CODE:
+ RETVAL = (InlineJavaJNIVM *)safemalloc(sizeof(InlineJavaJNIVM)) ;
+ if (RETVAL == NULL){
+ croak("Can't create InlineJavaJNIVM") ;
+ }
+ RETVAL->ijs = NULL ;
+ RETVAL->debug = debug ;
+
+ options[0].optionString = (RETVAL->debug ? "-verbose" : "-verbose:") ;
+ cp = (char *)malloc((strlen(classpath) + 128) * sizeof(char)) ;
+ sprintf(cp, "-Djava.class.path=%s", classpath) ;
+ options[1].optionString = cp ;
+
+ vm_args.version = JNI_VERSION_1_2 ;
+ vm_args.options = options ;
+ vm_args.nOptions = 2 ;
+ vm_args.ignoreUnrecognized = JNI_FALSE ;
+
+ /* Create the Java VM */
+ res = JNI_CreateJavaVM(&(RETVAL->jvm), (void **)&(RETVAL->env), &vm_args) ;
+ if (res < 0) {
+ croak("Can't create Java interpreter using JNI\n") ;
+ }
+
+ free(cp) ;
+
+ OUTPUT:
+ RETVAL
+
+
+void
+DESTROY(this)
+ InlineJavaJNIVM * this
+
+ CODE:
+ (*(this->jvm))->DestroyJavaVM(this->jvm) ;
+
+
+void
+create_ijs(this)
+ InlineJavaJNIVM * this
+
+ PREINIT:
+ jmethodID mid ;
+
+ CODE:
+ this->ijs_class = (*(this->env))->FindClass(this->env, "InlineJavaServer") ;
+ if (this->ijs_class == NULL){
+ croak("Can't find class InlineJavaServer") ;
+ }
+
+ mid = (*(this->env))->GetStaticMethodID(this->env, this->ijs_class, "jni_main", "(Z)LInlineJavaServer;") ;
+ if (mid == NULL) {
+ croak("Can't find method jni_main in class InlineJavaServer") ;
+ }
+
+ this->ijs = (*(this->env))->CallStaticObjectMethod(this->env, this->ijs_class, mid, this->debug) ;
+ if ((*(this->env))->ExceptionOccurred(this->env)){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+ croak("Exception occured") ;
+ }
+
+
+char *
+process_command(this, data)
+ InlineJavaJNIVM * this
+ char * data
+
+ PREINIT:
+ jmethodID mid ;
+ jstring cmd ;
+ jstring resp ;
+
+ CODE:
+ mid = (*(this->env))->GetMethodID(this->env, this->ijs_class, "ProcessCommand", "(Ljava/lang/String;)Ljava/lang/String;") ;
+ if (mid == NULL) {
+ croak("Can't find method ProcessCommand in class InlineJavaServer") ;
+ }
+
+ cmd = (*(this->env))->NewStringUTF(this->env, data) ;
+ if (cmd == NULL){
+ croak("Can't create java.lang.String") ;
+ }
+
+ resp = (*(this->env))->CallObjectMethod(this->env, this->ijs, mid, cmd) ;
+ if ((*(this->env))->ExceptionOccurred(this->env)){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+ croak("Exception occured") ;
+ }
+ RETVAL = (char *)((*(this->env))->GetStringUTFChars(this->env, resp, NULL)) ;
+
+ OUTPUT:
+ RETVAL
+
+ CLEANUP:
+ (*(this->env))->ReleaseStringUTFChars(this->env, resp, RETVAL) ;
+
+
+void
+report(this, module, classes, nb_classes)
+ InlineJavaJNIVM * this
+ char * module
+ char * classes
+ int nb_classes
+
+ PREINIT:
+ jmethodID mid ;
+ jclass class ;
+ jobject args ;
+ jstring arg ;
+ jstring resp ;
+ char * cl ;
+ char * ptr ;
+ int idx ;
+
+ CODE:
+ mid = (*(this->env))->GetMethodID(this->env, this->ijs_class, "Report", "([Ljava/lang/String;I)V") ;
+ if (mid == NULL) {
+ croak("Can't find method Report in class InlineJavaServer") ;
+ }
+
+ class = (*(this->env))->FindClass(this->env, "java/lang/String") ;
+ if (class == NULL){
+ croak("Can't find class java.lang.String") ;
+ }
+
+ idx = 0 ;
+ args = (*(this->env))->NewObjectArray(this->env, nb_classes + 1, class, NULL) ;
+ if (args == NULL){
+ croak("Can't create array of java.lang.String of length %i", nb_classes + 1) ;
+ }
+
+ arg = (*(this->env))->NewStringUTF(this->env, module) ;
+ if (arg == NULL){
+ croak("Can't create java.lang.String") ;
+ }
+ (*(this->env))->SetObjectArrayElement(this->env, args, idx++, arg) ;
+ if ((*(this->env))->ExceptionOccurred(this->env)){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+ croak("Exception occured") ;
+ }
+
+ cl = strdup(classes) ;
+ ptr = strtok(cl, " ") ;
+
+ idx = 1 ;
+ while (ptr != NULL){
+ arg = (*(this->env))->NewStringUTF(this->env, ptr) ;
+ if (arg == NULL){
+ croak("Can't create java.lang.String") ;
+ }
+ (*(this->env))->SetObjectArrayElement(this->env, args, idx, arg) ;
+ if ((*(this->env))->ExceptionOccurred(this->env)){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+ croak("Exception occured") ;
+ }
+
+ idx++ ;
+ ptr = strtok(NULL, " ") ;
+ }
+ free(cl) ;
+
+ (*(this->env))->CallVoidMethod(this->env, this->ijs, mid, args, 0) ;
+ if ((*(this->env))->ExceptionOccurred(this->env)){
+ (*(this->env))->ExceptionDescribe(this->env) ;
+ croak("Exception occured") ;
+ }
+
+
+
diff --git a/Java/Makefile.PL b/Java/Makefile.PL
new file mode 100644
index 0000000..6e2bd46
--- /dev/null
+++ b/Java/Makefile.PL
@@ -0,0 +1,14 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Inline::Java::JNI',
+ VERSION_FROM => 'JNI.pm',
+ INC => join(" ",
+ '-I/usr/java1.2/include',
+ '-I/usr/java1.2/include/solaris'
+ ),
+ LIBS => [
+ '-L/usr/java1.2/jre/lib/sparc -ljvm'
+ ],
+ clean => {FILES => '_Inline_test/'},
+) ;
diff --git a/Java/typemap b/Java/typemap
new file mode 100644
index 0000000..b470113
--- /dev/null
+++ b/Java/typemap
@@ -0,0 +1,23 @@
+TYPEMAP
+InlineJavaJNIVM * T_PTROBJ_IJVM
+
+
+OUTPUT
+
+T_PTROBJ_IJVM
+ sv_setref_pv($arg, \"Inline::Java::JNI\", (void *)$var) ;
+
+
+INPUT
+
+T_PTROBJ_IJVM
+ if (sv_derived_from($arg, \"Inline::Java::JNI\")) {
+ $var = ($type)SvIV((SV*)SvRV($arg)) ;
+ }
+ else{
+ if (SvOK($arg)){
+ croak(\"$var is not of type Inline::Java::JNI\") ;
+ }
+ }
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git
More information about the Pkg-perl-cvs-commits
mailing list