diff options
| author | krasimir <krasimir@chalmers.se> | 2015-09-03 13:52:32 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2015-09-03 13:52:32 +0000 |
| commit | 3328dd1f8dc784021e6bc0350cabc93b44b582c4 (patch) | |
| tree | 20be3a100fe3274c942aafaf58e7ea159ad0e982 /src/runtime/java/jsg.c | |
| parent | c322e686a0f59ae633918853c1c434fc11fc49ae (diff) | |
Java API for opening/closing SG databases
Diffstat (limited to 'src/runtime/java/jsg.c')
| -rw-r--r-- | src/runtime/java/jsg.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/runtime/java/jsg.c b/src/runtime/java/jsg.c new file mode 100644 index 000000000..8f790505e --- /dev/null +++ b/src/runtime/java/jsg.c @@ -0,0 +1,79 @@ +#include <jni.h> +#include <sg/sg.h> +#include "jni_utils.h" + +JNIEXPORT jobject JNICALL +Java_org_grammaticalframework_sg_SG_openSG(JNIEnv *env, jclass cls, jstring path) +{ + GuPool* tmp_pool = gu_local_pool(); + + // Create an exception frame that catches all errors. + GuExn* err = gu_exn(tmp_pool); + + const char *fpath = (*env)->GetStringUTFChars(env, path, 0); + + // Read the PGF grammar. + SgSG* sg = sg_open(fpath, err); + + (*env)->ReleaseStringUTFChars(env, path, fpath); + + if (!gu_ok(err)) { + GuString msg; + if (gu_exn_caught(err, SgError)) { + msg = (GuString) gu_exn_caught_data(err); + } else { + msg = "The database cannot be opened"; + } + throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg); + gu_pool_free(tmp_pool); + return NULL; + } + + gu_pool_free(tmp_pool); + + jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(J)V"); + return (*env)->NewObject(env, cls, constrId, p2l(sg)); +} + +JNIEXPORT void JNICALL +Java_org_grammaticalframework_sg_SG_close(JNIEnv *env, jobject self) +{ + GuPool* tmp_pool = gu_local_pool(); + + // Create an exception frame that catches all errors. + GuExn* err = gu_exn(tmp_pool); + + sg_close(get_ref(env, self), err); + if (!gu_ok(err)) { + GuString msg; + if (gu_exn_caught(err, SgError)) { + msg = (GuString) gu_exn_caught_data(err); + } else { + msg = "The database cannot be closed"; + } + throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg); + gu_pool_free(tmp_pool); + return; + } + + gu_pool_free(tmp_pool); +} + +JNIEXPORT jobject JNICALL +Java_org_grammaticalframework_sg_SG_queryTriple(JNIEnv *env, jobject self, + jobject subj, + jobject pred, + jobject obj) +{ + return NULL; +} + +JNIEXPORT jboolean JNICALL +Java_org_grammaticalframework_sg_TripleResult_hasNext(JNIEnv *env, jobject self) +{ +} + +JNIEXPORT void JNICALL +Java_org_grammaticalframework_sg_TripleResult_close(JNIEnv *env, jobject self) +{ +} |
