+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) {
+ jclass class_Host = (*env)->FindClass(env, "org/simgrid/msg/Host");
+ jhost_method_Host_constructor = (*env)->GetMethodID(env, class_Host, "<init>", "()V");
+ //FIXME: Don't use jxbt_get_sfield directly, it is slower.
+ jhost_field_Host_bind = jxbt_get_jfield(env,class_Host, "bind", "J");
+ jhost_field_Host_name = jxbt_get_jfield(env, class_Host, "name", "Ljava/lang/String;");
+ if (!class_Host || !jhost_field_Host_name || !jhost_method_Host_constructor || !jhost_field_Host_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_Host_getByName(JNIEnv * env, jclass cls,
+ jstring jname) {
+ m_host_t host; /* native host */
+ jobject jhost; /* global reference to the java host instance returned */
+
+ /* get the C string from the java string */
+ const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+ if (name == NULL) {
+ jxbt_throw_null(env,bprintf("No host can have a null name"));
+ return NULL;
+ }
+ XBT_DEBUG("Looking for host '%s'",name);
+ /* get the host by name (the hosts are created during the grid resolution) */
+ host = MSG_get_host_by_name(name);
+ XBT_DEBUG("MSG gave %p as native host", host);
+
+ if (!host) { /* invalid name */
+ jxbt_throw_host_not_found(env, name);
+ (*env)->ReleaseStringUTFChars(env, jname, name);