changeset 698:10d3692e0b06

* Initial commit of Java bindings. * Currently supports creation of db. More to come!
author mas01mj
date Mon, 26 Apr 2010 17:17:07 +0000
parents 2741bbda39d7
children 9a7d829bc492
files bindings/java/AudioDB.h bindings/java/AudioDB.java bindings/java/AudioDB_Mode.h bindings/java/Makefile bindings/java/libAudioDB_JNI.c
diffstat 5 files changed, 176 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 <jni.h>
+/* 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
--- /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);
+	}
+}
+
+
--- /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 <jni.h>
+/* Header for class AudioDB_Mode */
+
+#ifndef _Included_AudioDB_Mode
+#define _Included_AudioDB_Mode
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /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 $@
+
--- /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 <jni.h>
+#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)
+{
+}
+