# HG changeset patch # User mas01mj # Date 1272302227 0 # Node ID 10d3692e0b061b388bb18f3f6cdc16a92e15107b # Parent 2741bbda39d73ccd186dc23896b2f026669b7299 * Initial commit of Java bindings. * Currently supports creation of db. More to come! diff -r 2741bbda39d7 -r 10d3692e0b06 bindings/java/AudioDB.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/java/AudioDB.h Mon Apr 26 17:17:07 2010 +0000 @@ -0,0 +1,53 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class AudioDB */ + +#ifndef _Included_AudioDB +#define _Included_AudioDB +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: AudioDB + * Method: audiodb_create + * Signature: (Ljava/lang/String;III)Z + */ +JNIEXPORT jboolean JNICALL Java_AudioDB_audiodb_1create + (JNIEnv *, jobject, jstring, jint, jint, jint); + +/* + * Class: AudioDB + * Method: audiodb_open + * Signature: (Ljava/lang/String;LAudioDB/Mode;)Z + */ +JNIEXPORT jboolean JNICALL Java_AudioDB_audiodb_1open + (JNIEnv *, jobject, jstring, jobject); + +/* + * Class: AudioDB + * Method: insert + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_AudioDB_insert + (JNIEnv *, jobject); + +/* + * Class: AudioDB + * Method: query + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_AudioDB_query + (JNIEnv *, jobject); + +/* + * Class: AudioDB + * Method: status + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_AudioDB_status + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff -r 2741bbda39d7 -r 10d3692e0b06 bindings/java/AudioDB.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/java/AudioDB.java Mon Apr 26 17:17:07 2010 +0000 @@ -0,0 +1,44 @@ +import java.io.File; + +public class AudioDB +{ + public native boolean audiodb_create(String path, int datasize, int ntracks, int datadim); + public native boolean audiodb_open(String path, Mode mode); + + public native void insert(); + public native void query(); + public native void status(); + + public enum Mode { O_RDONLY, O_RDRW } + + private File path; + + public AudioDB(File path) + { + this.path = path; + } + + public boolean create(int datasize, int ntracks, int datadim) + { + return audiodb_create(path.toString(), datasize, ntracks, datadim); + } + + public boolean open(Mode mode) + { + return audiodb_open(path.toString(), mode); + } + + static { + System.loadLibrary("AudioDB_JNI"); + } + + + public static void main(String args[]) + { + AudioDB testDB = new AudioDB(new File("test.adb")); + testDB.create(5, 5, 12); + testDB.open(Mode.O_RDRW); + } +} + + diff -r 2741bbda39d7 -r 10d3692e0b06 bindings/java/AudioDB_Mode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/java/AudioDB_Mode.h Mon Apr 26 17:17:07 2010 +0000 @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class AudioDB_Mode */ + +#ifndef _Included_AudioDB_Mode +#define _Included_AudioDB_Mode +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff -r 2741bbda39d7 -r 10d3692e0b06 bindings/java/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/java/Makefile Mon Apr 26 17:17:07 2010 +0000 @@ -0,0 +1,21 @@ +CFLAGS += -shared -fPIC -g -I$(JDK)/include -I$(JDK)/include/linux -I/usr/local/include/ + +.SUFFIXES: .java .class .o + +JDK=/usr/lib/jvm/java-6-openjdk + +OBJS = libAudioDB_JNI.o +CLASSES = AudioDB.class +NATIVE_LIB = libAudioDB_JNI.so + +build: $(CLASSES) $(NATIVE_LIB) + +.java.class: + $(JDK)/bin/javac $< + +.class.h: + $(JDK)/bin/javah -jni $(<:%.class=%) + +$(NATIVE_LIB): $(OBJS) + ld -fPIC -G $(OBJS) -laudioDB -o $@ + diff -r 2741bbda39d7 -r 10d3692e0b06 bindings/java/libAudioDB_JNI.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bindings/java/libAudioDB_JNI.c Mon Apr 26 17:17:07 2010 +0000 @@ -0,0 +1,45 @@ +#include "AudioDB.h" + +#include +#include "audioDB_API.h" + + +JNIEXPORT jboolean JNICALL Java_AudioDB_audiodb_1create (JNIEnv *env, jobject obj, jstring path, jint datasize, jint ntracks, jint datadim) +{ + char buf[256]; + const char *str; + str = (*env)->GetStringUTFChars(env, path, NULL); + if (str == NULL) + return; + + adb_t *handle; + handle = audiodb_create(str, datasize, ntracks, datadim); + if(!handle) + return JNI_FALSE; + + (*env)->ReleaseStringUTFChars(env, path, str); + return JNI_TRUE; +} + +JNIEXPORT jboolean JNICALL Java_AudioDB_audiodb_1open (JNIEnv *env, jobject obj, jstring path, jobject mode) +{ + jclass modeClass = (*env)->FindClass(env, "AudioDB$Mode"); + jmethodID getNameMethod = (*env)->GetMethodID(env, modeClass, "name", "()Ljava/lang/String;"); + jstring value = (jstring)(*env)->CallObjectMethod(env, mode, getNameMethod); + const char* openMode = (*env)->GetStringUTFChars(env, value, 0); + + return JNI_TRUE; +} + +JNIEXPORT void JNICALL Java_AudioDB_insert(JNIEnv *env, jobject obj) +{ +} + +JNIEXPORT void JNICALL Java_AudioDB_query(JNIEnv *env, jobject obj) +{ +} + +JNIEXPORT void JNICALL Java_AudioDB_status(JNIEnv *env, jobject obj) +{ +} +