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 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
20 jobject jhost_new_instance(JNIEnv* env) {
22 jclass cls = jxbt_get_class(env,"simgrid/msg/Host");
23 jmethodID constructor = jxbt_get_jmethod(env,cls,"<init>", "()V");
28 return (*env)->NewObject(env,cls,constructor);
31 jobject jhost_ref(JNIEnv* env,jobject jhost) {
32 return (*env)->NewGlobalRef(env,jhost);
35 void jhost_unref(JNIEnv* env,jobject jhost) {
36 (*env)->DeleteGlobalRef(env,jhost);
39 void jhost_bind(jobject jhost,m_host_t host,JNIEnv* env) {
40 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
45 (*env)->SetLongField(env,jhost,id,(jlong)(long)(host));
48 m_host_t jhost_get_native(JNIEnv* env, jobject jhost) {
49 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
54 return (m_host_t)(long)(*env)->GetLongField(env,jhost,id);
57 const char* jhost_get_name(jobject jhost,JNIEnv* env) {
58 m_host_t host = jhost_get_native(env,jhost);
59 return (const char*)host->name;
62 void jhost_set_name(jobject jhost,jstring jname,JNIEnv* env) {
64 m_host_t host = jhost_get_native(env,jhost);
66 name = (*env)->GetStringUTFChars(env, jname, 0);
71 host->name = xbt_strdup(name);
72 (*env)->ReleaseStringUTFChars(env, jname, name);
75 jboolean jhost_is_valid(jobject jhost,JNIEnv* env) {
76 jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J");
81 if ((*env)->GetLongField(env,jhost,id)) {