X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0c3ec6c8dcf39a172bb979cd5d0291067599c3ae..9532edf044eed31bcf6de22916c8824e18f373ad:/src/bindings/java/jmsg_as.c diff --git a/src/bindings/java/jmsg_as.c b/src/bindings/java/jmsg_as.c index 3fae715ba2..a3daec624b 100644 --- a/src/bindings/java/jmsg_as.c +++ b/src/bindings/java/jmsg_as.c @@ -1,10 +1,10 @@ /* Functions related to the java host instances. */ -/* Copyright (c) 2007-2012. The SimGrid Team. +/* Copyright (c) 2007-2014. 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. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/str.h" #include "xbt/dict.h" @@ -81,7 +81,6 @@ Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) { 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"); @@ -94,7 +93,7 @@ Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) { } jas_bind(tmp_jas, tmp_as, env); - (*env)->SetObjectArrayElement(env, jtable, index, jas); + (*env)->SetObjectArrayElement(env, jtable, index, tmp_jas); index++; } @@ -123,3 +122,53 @@ Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) { return jproperty; } +JNIEXPORT jobject JNICALL +Java_org_simgrid_msg_As_getModel(JNIEnv * env, jobject jas) { + msg_as_t as = jas_get_native(env, jas); + return (*env)->NewStringUTF(env, MSG_environment_as_get_model(as)); +} + +JNIEXPORT jobjectArray JNICALL +Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas) +{ + int index; + jobjectArray jtable; + jobject jhost; + jstring jname; + msg_host_t host; + msg_as_t as = jas_get_native(env, jas); + + xbt_dynar_t table = MSG_environment_as_get_hosts(as); + int count = xbt_dynar_length(table); + + jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); + + if (!cls) { + return NULL; + } + + jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); + + if (!jtable) { + jxbt_throw_jni(env, "Hosts table allocation failed"); + return NULL; + } + + for (index = 0; index < count; index++) { + + host = xbt_dynar_get_as(table,index,msg_host_t); + + jhost = (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL); + if (!jhost) { + jname = (*env)->NewStringUTF(env, MSG_host_get_name(host)); + + jhost = Java_org_simgrid_msg_Host_getByName(env, cls, jname); + + /* FIXME: leak of jname ? */ + } + + (*env)->SetObjectArrayElement(env, jtable, index, jhost); + } + xbt_dynar_free(&table); + return jtable; +}