-/* Functions related to the java host instances. */
+/* Java bindings of the NetZones. */
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2007-2017. 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 <xbt/dict.h>
-#include <xbt/dynar.h>
-
#include "simgrid/s4u/NetZone.hpp"
-#include <simgrid/s4u/host.hpp>
+#include "simgrid/s4u/host.hpp"
-#include "simgrid/msg.h"
#include "jmsg_as.h"
#include "jmsg_host.h"
#include "jxbt_utilities.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+SG_BEGIN_DECL()
+
static jmethodID jas_method_As_constructor;
static jfieldID jas_field_As_bind;
-jobject jas_new_instance(JNIEnv * env) {
+jobject jnetzone_new_instance(JNIEnv* env)
+{
jclass cls = jxbt_get_class(env, "org/simgrid/msg/As");
return env->NewObject(cls, jas_method_As_constructor);
}
-jobject jas_ref(JNIEnv * env, jobject jas) {
+jobject jnetzone_ref(JNIEnv* env, jobject jas)
+{
return env->NewGlobalRef(jas);
}
-void jas_unref(JNIEnv * env, jobject jas) {
+void jnetzone_unref(JNIEnv* env, jobject jas)
+{
env->DeleteGlobalRef(jas);
}
-void jas_bind(jobject jas, simgrid::s4u::NetZone* netzone, JNIEnv* env)
+void jnetzone_bind(jobject jas, simgrid::s4u::NetZone* netzone, JNIEnv* env)
{
env->SetLongField(jas, jas_field_As_bind, (jlong)(uintptr_t)(netzone));
}
-simgrid::s4u::NetZone* jas_get_native(JNIEnv* env, jobject jas)
+simgrid::s4u::NetZone* jnetzone_get_native(JNIEnv* env, jobject jas)
{
return (simgrid::s4u::NetZone*)(uintptr_t)env->GetLongField(jas, jas_field_As_bind);
}
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
- simgrid::s4u::NetZone* as = jas_get_native(env, jas);
+ simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
return env->NewStringUTF(as->name());
}
jobjectArray jtable;
jobject tmp_jas;
simgrid::s4u::NetZone* tmp_as;
- simgrid::s4u::NetZone* self_as = jas_get_native(env, jas);
+ simgrid::s4u::NetZone* self_as = jnetzone_get_native(env, jas);
xbt_dict_t dict = self_as->children();
int count = xbt_dict_length(dict);
char *key;
xbt_dict_foreach(dict,cursor,key,tmp_as) {
- tmp_jas = jas_new_instance(env);
+ tmp_jas = jnetzone_new_instance(env);
if (!tmp_jas) {
jxbt_throw_jni(env, "java As instantiation failed");
return nullptr;
}
- tmp_jas = jas_ref(env, tmp_jas);
+ tmp_jas = jnetzone_ref(env, tmp_jas);
if (!tmp_jas) {
jxbt_throw_jni(env, "new global ref allocation failed");
return nullptr;
}
- jas_bind(tmp_jas, tmp_as, env);
+ jnetzone_bind(tmp_jas, tmp_as, env);
env->SetObjectArrayElement(jtable, index, tmp_jas);
index++;
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) {
- simgrid::s4u::NetZone* as = jas_get_native(env, jas);
+ simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
if (!as) {
jxbt_throw_notbound(env, "as", jas);
jobject jhost;
jstring jname;
msg_host_t host;
- simgrid::s4u::NetZone* as = jas_get_native(env, jas);
+ simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
xbt_dynar_t table = as->hosts();
int count = xbt_dynar_length(table);
xbt_dynar_free(&table);
return jtable;
}
+
+SG_END_DECL()