X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3913bb7b7d28a6c8f383b7973f72a4fc7a1f4f01..57e7dcd49d4873f73dc0337e4f172bd169f77a44:/src/java/jmsg_host.c diff --git a/src/java/jmsg_host.c b/src/java/jmsg_host.c index e9b481b138..26edfa2f6e 100644 --- a/src/java/jmsg_host.c +++ b/src/java/jmsg_host.c @@ -1,88 +1,88 @@ -/* - * $Id$ - * - * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. - * - * This contains the implementation of the functions in relation with the java - * host instance. - */ - +/* Functions related to the java host instances. */ + +/* Copyright (c) 2007, 2009, 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "xbt/str.h" #include "jmsg.h" #include "jmsg_host.h" #include "jxbt_utilities.h" -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); +jobject jhost_new_instance(JNIEnv * env) +{ -jobject jhost_new_instance(JNIEnv* env) { - - jclass cls = jxbt_get_class(env,"simgrid/msg/Host"); - jmethodID constructor = jxbt_get_jmethod(env,cls,"", "()V"); - - if(!constructor) + jclass cls = jxbt_get_class(env, "simgrid/msg/Host"); + jmethodID constructor = jxbt_get_jmethod(env, cls, "", "()V"); + + if (!constructor) return NULL; - - return (*env)->NewObject(env,cls,constructor); + + return (*env)->NewObject(env, cls, constructor); } -jobject jhost_ref(JNIEnv* env,jobject jhost) { - return (*env)->NewGlobalRef(env,jhost); +jobject jhost_ref(JNIEnv * env, jobject jhost) +{ + return (*env)->NewGlobalRef(env, jhost); } -void jhost_unref(JNIEnv* env,jobject jhost) { - (*env)->DeleteGlobalRef(env,jhost); +void jhost_unref(JNIEnv * env, jobject jhost) +{ + (*env)->DeleteGlobalRef(env, jhost); } -void jhost_bind(jobject jhost,m_host_t host,JNIEnv* env) { - jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J"); +void jhost_bind(jobject jhost, m_host_t host, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); if (!id) return; - - (*env)->SetLongField(env,jhost,id,(jlong)(long)(host)); + + (*env)->SetLongField(env, jhost, id, (jlong) (long) (host)); } -m_host_t jhost_get_native(JNIEnv* env, jobject jhost) { - jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J"); +m_host_t jhost_get_native(JNIEnv * env, jobject jhost) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); - if(!id) + if (!id) return NULL; - return (m_host_t)(long)(*env)->GetLongField(env,jhost,id); + return (m_host_t) (long) (*env)->GetLongField(env, jhost, id); } -const char* jhost_get_name(jobject jhost,JNIEnv* env) { - m_host_t host = jhost_get_native(env,jhost); - return (const char*)host->name; +const char *jhost_get_name(jobject jhost, JNIEnv * env) +{ + m_host_t host = jhost_get_native(env, jhost); + return (const char *) host->name; } -void jhost_set_name(jobject jhost,jstring jname,JNIEnv* env) { - const char* name; - m_host_t host = jhost_get_native(env,jhost); +void jhost_set_name(jobject jhost, jstring jname, JNIEnv * env) +{ + const char *name; + m_host_t host = jhost_get_native(env, jhost); name = (*env)->GetStringUTFChars(env, jname, 0); - - if(host->name) + + if (host->name) free(host->name); - + host->name = xbt_strdup(name); - (*env)->ReleaseStringUTFChars(env, jname, name); + (*env)->ReleaseStringUTFChars(env, jname, name); } -jboolean jhost_is_valid(jobject jhost,JNIEnv* env) { - jfieldID id = jxbt_get_sfield(env,"simgrid/msg/Host","bind", "J"); +jboolean jhost_is_valid(jobject jhost, JNIEnv * env) +{ + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Host", "bind", "J"); - if(!id) + if (!id) return 0; - if ((*env)->GetLongField(env,jhost,id)) { + if ((*env)->GetLongField(env, jhost, id)) { return JNI_TRUE; } else { return JNI_FALSE; } } - -