4 * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package.
9 * This contains the implementation of the functions in relation with the java
15 #include "jmsg_host.h"
16 #include "jxbt_utilities.h"
18 jobject jhost_new_instance(JNIEnv* env) {
20 jclass cls = jxbt_get_class(env,"simgrid/msg/Host");
21 jmethodID constructor = jxbt_get_jmethod(env,cls,"<init>", "()V");
26 return (*env)->NewObject(env,cls,constructor);
29 jobject jhost_ref(JNIEnv* env,jobject jhost) {
30 return (*env)->NewGlobalRef(env,jhost);
33 void jhost_unref(JNIEnv* env,jobject jhost) {
34 (*env)->DeleteGlobalRef(env,jhost);
37 void jhost_bind(jobject jhost,m_host_t host,JNIEnv* env) {
38 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
43 (*env)->SetLongField(env,jhost,id,(jlong)(long)(host));
46 m_host_t jhost_get_native(JNIEnv* env, jobject jhost) {
47 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
52 return (m_host_t)(long)(*env)->GetLongField(env,jhost,id);
55 const char* jhost_get_name(jobject jhost,JNIEnv* env) {
56 m_host_t host = jhost_get_native(env,jhost);
57 return (const char*)host->name;
60 void jhost_set_name(jobject jhost,jstring jname,JNIEnv* env) {
62 m_host_t host = jhost_get_native(env,jhost);
64 name = (*env)->GetStringUTFChars(env, jname, 0);
69 host->name = xbt_strdup(name);
70 (*env)->ReleaseStringUTFChars(env, jname, name);
73 jboolean jhost_is_valid(jobject jhost,JNIEnv* env) {
74 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
79 if ((*env)->GetLongField(env,jhost,id)) {