jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname, const char *name, const char *signature) { jclass cls; jmethodID id; cls = jxbt_get_class(env, classname); if (!cls) return 0; id = (*env)->GetStaticMethodID(env, cls, name, signature); if (!id) { char *m = bprintf("Cannot find static method %s(%s) in %s", name, signature, classname); jxbt_throw_jni(env, m); free(m); return 0; } return id; }
jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname, const char *name, const char *signature) { jclass cls; jmethodID id; cls = jxbt_get_class(env, classname); if (not cls) return 0; id = env->GetMethodID(cls, name, signature); if (not id) { jxbt_throw_jni(env, std::string("Cannot find method") + name + "(" + signature + ") in " + classname); return 0; } return id; }
jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, const char *name, const char *signature) { jclass cls = jxbt_get_class(env, classname); jfieldID id; if (not cls) return 0; id = env->GetFieldID(cls, name, signature); if (not id) { jxbt_throw_jni(env, std::string("Cannot find field") + signature + " " + name + " in " + classname); return 0; } return id; }
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) { int index; jobjectArray jtable; jobject jhost; jstring jname; msg_host_t host; xbt_dynar_t table = MSG_hosts_as_dynar(); 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) (MSG_host_get_data(host)); if (!jhost) { jname = (*env)->NewStringUTF(env, MSG_host_get_name(host)); jhost = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); /* FIXME: leak of jname ? */ } (*env)->SetObjectArrayElement(env, jtable, index, jhost); } xbt_dynar_free(&table); return jtable; }
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jclass cls_arg) { int index; jobjectArray jtable; jobject jstorage; jstring jname; msg_storage_t storage; xbt_dynar_t table = MSG_storages_as_dynar(); int count = xbt_dynar_length(table); jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage"); if (!cls) { return NULL; } jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL); if (!jtable) { jxbt_throw_jni(env, "Storages table allocation failed"); return NULL; } for (index = 0; index < count; index++) { storage = xbt_dynar_get_as(table,index,msg_storage_t); jstorage = (jobject) (xbt_lib_get_level(storage, JAVA_STORAGE_LEVEL)); if (!jstorage) { jname = (*env)->NewStringUTF(env, MSG_storage_get_name(storage)); jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname); } (*env)->SetObjectArrayElement(env, jtable, index, jstorage); } xbt_dynar_free(&table); return jtable; }
jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, const char *name, const char *signature) { jclass cls = jxbt_get_class(env, classname); jfieldID id; if (!cls) return 0; id = (*env)->GetFieldID(env, cls, name, signature); if (!id) { char *m = bprintf("Cannot find field %s %s in %s", signature, name, classname); jxbt_throw_jni(env, m); free(m); return 0; } return id; }
jobject jhost_new_instance(JNIEnv * env) { jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); return env->NewObject(cls, jhost_method_Host_constructor); }
jobject jas_new_instance(JNIEnv * env) { jclass cls = jxbt_get_class(env, "org/simgrid/msg/As"); return env->NewObject(cls, jas_method_As_constructor); }
jobject jstorage_new_instance(JNIEnv * env) { jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage"); return env->NewObject(cls, jstorage_method_Storage_constructor); }