From: Paul Bédaride Date: Thu, 6 Jun 2013 19:51:32 +0000 (+0200) Subject: Add missing files X-Git-Tag: v3_9_90~282 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/05faa61eee4ea71225b78d004f67f73a7269ab7b?ds=sidebyside Add missing files --- diff --git a/src/bindings/java/jmsg_as.c b/src/bindings/java/jmsg_as.c new file mode 100644 index 0000000000..3fae715ba2 --- /dev/null +++ b/src/bindings/java/jmsg_as.c @@ -0,0 +1,125 @@ +/* Functions related to the java host instances. */ + +/* Copyright (c) 2007-2012. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "xbt/str.h" +#include "xbt/dict.h" +#include "msg/msg.h" +#include "jmsg_as.h" +#include "jxbt_utilities.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); + +static jmethodID jas_method_As_constructor; +static jfieldID jas_field_As_bind; + +jobject jas_new_instance(JNIEnv * env) { + jclass cls = jxbt_get_class(env, "org/simgrid/msg/As"); + return (*env)->NewObject(env, cls, jas_method_As_constructor); +} + +jobject jas_ref(JNIEnv * env, jobject jas) { + return (*env)->NewGlobalRef(env, jas); +} + +void jas_unref(JNIEnv * env, jobject jas) { + (*env)->DeleteGlobalRef(env, jas); +} + +void jas_bind(jobject jas, msg_as_t as, JNIEnv * env) { + (*env)->SetLongField(env, jas, jas_field_As_bind, (jlong) (long) (as)); +} + +msg_as_t jas_get_native(JNIEnv * env, jobject jas) { + return (msg_as_t) (long) (*env)->GetLongField(env, jas, jas_field_As_bind); +} + +JNIEXPORT void JNICALL +Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) { + jclass class_As = (*env)->FindClass(env, "org/simgrid/msg/As"); + jas_method_As_constructor = (*env)->GetMethodID(env, class_As, "", "()V"); + jas_field_As_bind = jxbt_get_jfield(env,class_As, "bind", "J"); + if (!class_As || !jas_method_As_constructor || !jas_field_As_bind) { + jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug.")); + } +} + +JNIEXPORT jobject JNICALL +Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) { + msg_as_t as = jas_get_native(env, jas); + return (*env)->NewStringUTF(env, MSG_environment_as_get_name(as)); +} + +JNIEXPORT jobjectArray JNICALL +Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) { + int index = 0; + jobjectArray jtable; + jobject tmp_jas; + msg_as_t tmp_as; + msg_as_t self_as = jas_get_native(env, jas); + + xbt_dict_t dict = MSG_environment_as_get_routing_sons(self_as); + int count = xbt_dict_length(dict); + jclass cls = (*env)->FindClass(env, "org/simgrid/msg/As"); + + if (!cls) { + return NULL; + } + + jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); + + if (!jtable) { + jxbt_throw_jni(env, "Hosts table allocation failed"); + return NULL; + } + + xbt_dict_cursor_t cursor=NULL; + char *key; + + xbt_dict_foreach(dict,cursor,key,tmp_as) { + printf("Son: %s\n", key); + tmp_jas = jas_new_instance(env); + if (!tmp_jas) { + jxbt_throw_jni(env, "java As instantiation failed"); + return NULL; + } + tmp_jas = jas_ref(env, tmp_jas); + if (!tmp_jas) { + jxbt_throw_jni(env, "new global ref allocation failed"); + return NULL; + } + jas_bind(tmp_jas, tmp_as, env); + + (*env)->SetObjectArrayElement(env, jtable, index, jas); + index++; + + } + return jtable; +} + +JNIEXPORT jobject JNICALL +Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) { + msg_as_t as = jas_get_native(env, jas); + + if (!as) { + jxbt_throw_notbound(env, "as", jas); + return NULL; + } + const char *name = (*env)->GetStringUTFChars(env, jname, 0); + + const char *property = MSG_environment_as_get_property_value(as, name); + if (!property) { + return NULL; + } + + jobject jproperty = (*env)->NewStringUTF(env, property); + + (*env)->ReleaseStringUTFChars(env, jname, name); + + return jproperty; +} + diff --git a/src/bindings/java/jmsg_as.h b/src/bindings/java/jmsg_as.h new file mode 100644 index 0000000000..6961d4aec4 --- /dev/null +++ b/src/bindings/java/jmsg_as.h @@ -0,0 +1,46 @@ +/* Functions related to the java As instances. */ + +/* Copyright (c) 2007-2012. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + + +#ifndef MSG_JAS_H +#define MSG_JAS_H +#include +#include "msg/msg.h" + +/* Functions related to the java host instances. */ + +/* Copyright (c) 2007-2012. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "msg/msg.h" +#include "jmsg.h" +#include "jmsg_host.h" + +jobject jas_new_instance(JNIEnv * env); +jobject jas_ref(JNIEnv * env, jobject jas); +void jas_unref(JNIEnv * env, jobject jas); +void jas_bind(jobject jas, msg_as_t as, JNIEnv * env); +msg_as_t jas_get_native(JNIEnv * env, jobject jas); + +JNIEXPORT void JNICALL +Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls); + +JNIEXPORT jobject JNICALL +Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas); + +JNIEXPORT jobjectArray JNICALL +Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas); + +JNIEXPORT jobject JNICALL +Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jhost, jobject jname); + + +#endif /*!MSG_JAS_H */ diff --git a/src/bindings/java/org/simgrid/msg/As.java b/src/bindings/java/org/simgrid/msg/As.java new file mode 100644 index 0000000000..9e62f4f48b --- /dev/null +++ b/src/bindings/java/org/simgrid/msg/As.java @@ -0,0 +1,40 @@ +/* + * Bindings to the MSG hosts + * + * Copyright 2006-2012 The SimGrid Team + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ +package org.simgrid.msg; + +public class As { + + private long bind; + + protected As() { + }; + + + public long getBind() { return bind; } + + public String toString (){ + return this.getName(); + } + public native String getName(); + + public native As[] getSons(); + + public native String getProperty(String name); + + /** + * Class initializer, to initialize various JNI stuff + */ + public static native void nativeInit(); + static { + nativeInit(); + } +}