JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv * env, jclass cls) { msg_as_t as = MSG_environment_get_routing_root(); jobject jas = jas_new_instance(env); if (!jas) { jxbt_throw_jni(env, "java As instantiation failed"); return nullptr; } jas = jas_ref(env, jas); if (!jas) { jxbt_throw_jni(env, "new global ref allocation failed"); return nullptr; } jas_bind(jas, as, env); return (jobject) jas; }
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("org/simgrid/msg/As"); if (!cls) { return NULL; } jtable = env->NewObjectArray((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) { 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(jtable, index, tmp_jas); index++; }