A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #237 from oar-team/upstream
[simgrid.git]
/
src
/
bindings
/
java
/
jmsg_host.cpp
diff --git
a/src/bindings/java/jmsg_host.cpp
b/src/bindings/java/jmsg_host.cpp
index
1169daf
..
22c54da
100644
(file)
--- a/
src/bindings/java/jmsg_host.cpp
+++ b/
src/bindings/java/jmsg_host.cpp
@@
-7,15
+7,16
@@
#include "simgrid/plugins/energy.h"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/plugins/energy.h"
#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Storage.hpp"
-#include "jmsg.h"
+#include "jmsg.h
pp
"
#include "jmsg_host.h"
#include "jmsg_host.h"
-#include "jxbt_utilities.h"
#include "jmsg_storage.h"
#include "jmsg_storage.h"
+#include "jxbt_utilities.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
-SG_BEGIN_DECL()
+extern "C" {
static jmethodID jhost_method_Host_constructor;
static jfieldID jhost_field_Host_bind;
static jmethodID jhost_method_Host_constructor;
static jfieldID jhost_field_Host_bind;
@@
-55,25
+56,25
@@
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jcla
/* get the C string from the java string */
if (jname == nullptr) {
/* get the C string from the java string */
if (jname == nullptr) {
- jxbt_throw_null(env,
bprintf("No host can have a null name")
);
+ jxbt_throw_null(env,
"No host can have a null name"
);
return nullptr;
}
const char *name = env->GetStringUTFChars(jname, 0);
/* get the host by name (the hosts are created during the grid resolution) */
msg_host_t host = MSG_host_by_name(name);
return nullptr;
}
const char *name = env->GetStringUTFChars(jname, 0);
/* get the host by name (the hosts are created during the grid resolution) */
msg_host_t host = MSG_host_by_name(name);
- if (
!host) {
/* invalid name */
+ if (
not host) {
/* invalid name */
jxbt_throw_host_not_found(env, name);
env->ReleaseStringUTFChars(jname, name);
return nullptr;
}
env->ReleaseStringUTFChars(jname, name);
jxbt_throw_host_not_found(env, name);
env->ReleaseStringUTFChars(jname, name);
return nullptr;
}
env->ReleaseStringUTFChars(jname, name);
- if (
!host->extension(JAVA_HOST_LEVEL)) {
/* native host not associated yet with java host */
+ if (
not host->extension(JAVA_HOST_LEVEL)) {
/* native host not associated yet with java host */
/* Instantiate a new java host */
jobject jhost = jhost_new_instance(env);
/* Instantiate a new java host */
jobject jhost = jhost_new_instance(env);
- if (
!
jhost) {
+ if (
not
jhost) {
jxbt_throw_jni(env, "java host instantiation failed");
return nullptr;
}
jxbt_throw_jni(env, "java host instantiation failed");
return nullptr;
}
@@
-81,7
+82,7
@@
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jcla
/* get a global reference to the newly created host */
jhost = jhost_ref(env, jhost);
/* get a global reference to the newly created host */
jhost = jhost_ref(env, jhost);
- if (
!
jhost) {
+ if (
not
jhost) {
jxbt_throw_jni(env, "new global ref allocation failed");
return nullptr;
}
jxbt_throw_jni(env, "new global ref allocation failed");
return nullptr;
}
@@
-103,13
+104,13
@@
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc
msg_host_t host = MSG_host_self();
msg_host_t host = MSG_host_self();
- if (
!
host->extension(JAVA_HOST_LEVEL)) {
+ if (
not
host->extension(JAVA_HOST_LEVEL)) {
/* the native host not yet associated with the java host instance */
/* instanciate a new java host instance */
jhost = jhost_new_instance(env);
/* the native host not yet associated with the java host instance */
/* instanciate a new java host instance */
jhost = jhost_new_instance(env);
- if (
!
jhost) {
+ if (
not
jhost) {
jxbt_throw_jni(env, "java host instantiation failed");
return nullptr;
}
jxbt_throw_jni(env, "java host instantiation failed");
return nullptr;
}
@@
-117,12
+118,12
@@
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc
/* get a global reference to the newly created host */
jhost = jhost_ref(env, jhost);
/* get a global reference to the newly created host */
jhost = jhost_ref(env, jhost);
- if (
!
jhost) {
+ if (
not
jhost) {
jxbt_throw_jni(env, "global ref allocation failed");
return nullptr;
}
/* Sets the host name */
jxbt_throw_jni(env, "global ref allocation failed");
return nullptr;
}
/* Sets the host name */
- jobject jname = env->NewStringUTF(host->
c
name());
+ jobject jname = env->NewStringUTF(host->
getC
name());
env->SetObjectField(jhost, jhost_field_Host_name, jname);
/* Bind & store it */
jhost_bind(jhost, host, env);
env->SetObjectField(jhost, jhost_field_Host_name, jname);
/* Bind & store it */
jhost_bind(jhost, host, env);
@@
-141,7
+142,7
@@
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost)
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
- MSG_host_off(host);
+ MSG_host_off(host);
}
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
}
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
@@
-154,7
+155,7
@@
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass c
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return -1;
}
jxbt_throw_notbound(env, "host", jhost);
return -1;
}
@@
-165,7
+166,7
@@
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobje
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return -1;
}
jxbt_throw_notbound(env, "host", jhost);
return -1;
}
@@
-176,14
+177,14
@@
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env,
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) {
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) {
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return nullptr;
}
const char *name = env->GetStringUTFChars((jstring) jname, 0);
const char *property = MSG_host_get_property_value(host, name);
jxbt_throw_notbound(env, "host", jhost);
return nullptr;
}
const char *name = env->GetStringUTFChars((jstring) jname, 0);
const char *property = MSG_host_get_property_value(host, name);
- if (
!
property) {
+ if (
not
property) {
return nullptr;
}
return nullptr;
}
@@
-198,7
+199,7
@@
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue) {
msg_host_t host = jhost_get_native(env, jhost);
Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue) {
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return;
}
jxbt_throw_notbound(env, "host", jhost);
return;
}
@@
-216,7
+217,7
@@
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject
{
msg_host_t host = jhost_get_native(env, jhost);
{
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
@@
-230,35
+231,30
@@
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
jobject jstorage;
jstring jname;
jobject jstorage;
jstring jname;
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
int index = 0;
jobjectArray jtable;
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
int index = 0;
jobjectArray jtable;
-
xbt_dict_t dict = MSG_host_get_mounted_storage_list(host
);
- int count
= xbt_dict_length(dict
);
+
std::unordered_map<std::string, msg_storage_t> mounted_storages = host->getMountedStorages(
);
+ int count
= mounted_storages.size(
);
jclass cls = env->FindClass("org/simgrid/msg/Storage");
jtable = env->NewObjectArray((jsize) count, cls, nullptr);
jclass cls = env->FindClass("org/simgrid/msg/Storage");
jtable = env->NewObjectArray((jsize) count, cls, nullptr);
- if (
!
jtable) {
- jxbt_throw_jni(env, "Storages table allocation failed");
- return nullptr;
+ if (
not
jtable) {
+
jxbt_throw_jni(env, "Storages table allocation failed");
+
return nullptr;
}
}
- xbt_dict_cursor_t cursor=nullptr;
- const char* mount_name;
- const char* storage_name;
-
- xbt_dict_foreach(dict,cursor,mount_name,storage_name) {
- jname = env->NewStringUTF(storage_name);
+ for (auto const& elm : mounted_storages) {
+ jname = env->NewStringUTF(elm.second->getCname());
jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname);
env->SetObjectArrayElement(jtable, index, jstorage);
index++;
}
jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname);
env->SetObjectArrayElement(jtable, index, jstorage);
index++;
}
- xbt_dict_free(&dict);
return jtable;
}
return jtable;
}
@@
-266,7
+262,7
@@
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIE
{
msg_host_t host = jhost_get_native(env, jhost);
{
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
@@
-290,7
+286,7
@@
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getStorageContent(JNIEn
{
msg_host_t host = jhost_get_native(env, jhost);
{
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
@@
-304,12
+300,12
@@
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas
int count = xbt_dynar_length(table);
jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
int count = xbt_dynar_length(table);
jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
- if (
!
cls)
+ if (
not
cls)
return nullptr;
jobjectArray jtable = env->NewObjectArray((jsize)count, cls, nullptr);
return nullptr;
jobjectArray jtable = env->NewObjectArray((jsize)count, cls, nullptr);
- if (
!
jtable) {
+ if (
not
jtable) {
jxbt_throw_jni(env, "Hosts table allocation failed");
return nullptr;
}
jxbt_throw_jni(env, "Hosts table allocation failed");
return nullptr;
}
@@
-318,8
+314,8
@@
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas
msg_host_t host = xbt_dynar_get_as(table, index, msg_host_t);
jobject jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
msg_host_t host = xbt_dynar_get_as(table, index, msg_host_t);
jobject jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
- if (
!
jhost) {
- jstring jname = env->NewStringUTF(host->
c
name());
+ if (
not
jhost) {
+ jstring jname = env->NewStringUTF(host->
getC
name());
jhost = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
}
jhost = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
}
@@
-336,11
+332,16
@@
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, j
env->ReleaseStringUTFChars((jstring) jname, name);
}
env->ReleaseStringUTFChars((jstring) jname, name);
}
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_updateAllEnergyConsumptions(JNIEnv* env, jclass cls)
+{
+ sg_host_energy_update_all();
+}
+
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost)
{
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost)
{
msg_host_t host = jhost_get_native(env, jhost);
- if (
!
host) {
+ if (
not
host) {
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
jxbt_throw_notbound(env, "host", jhost);
return 0;
}
@@
-366,12
+367,11
@@
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jo
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost)
{
msg_host_t host = jhost_get_native(env, jhost);
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost)
{
msg_host_t host = jhost_get_native(env, jhost);
- return MSG_host_get_
current_power_peak
(host);
+ return MSG_host_get_
speed
(host);
}
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate)
{
msg_host_t host = jhost_get_native(env, jhost);
return MSG_host_get_power_peak_at(host, pstate);
}
}
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate)
{
msg_host_t host = jhost_get_native(env, jhost);
return MSG_host_get_power_peak_at(host, pstate);
}
-
-SG_END_DECL()
+}