Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make SIMIX_context_self() useless and use Context::self() instead
[simgrid.git] / src / bindings / java / jmsg_host.cpp
index 22c54da..d889f51 100644 (file)
@@ -1,11 +1,12 @@
 /* Functions related to the java host instances.                            */
 
-/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2018. 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 "simgrid/plugins/energy.h"
+#include "simgrid/plugins/load.h"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Storage.hpp"
 
@@ -16,8 +17,6 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 
-extern "C" {
-
 static jmethodID jhost_method_Host_constructor;
 static jfieldID jhost_field_Host_bind;
 static jfieldID jhost_field_Host_name;
@@ -123,7 +122,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc
       return nullptr;
     }
     /* Sets the host name */
-    jobject jname = env->NewStringUTF(host->getCname());
+    jobject jname = env->NewStringUTF(host->get_cname());
     env->SetObjectField(jhost, jhost_field_Host_name, jname);
     /* Bind & store it */
     jhost_bind(jhost, host, env);
@@ -238,7 +237,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
 
   int index = 0;
   jobjectArray jtable;
-  std::unordered_map<std::string, msg_storage_t> mounted_storages = host->getMountedStorages();
+  std::unordered_map<std::string, msg_storage_t> mounted_storages = host->get_mounted_storages();
   int count  = mounted_storages.size();
   jclass cls = env->FindClass("org/simgrid/msg/Storage");
 
@@ -250,7 +249,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
   }
 
   for (auto const& elm : mounted_storages) {
-    jname    = env->NewStringUTF(elm.second->getCname());
+    jname    = env->NewStringUTF(elm.second->get_cname());
     jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname);
     env->SetObjectArrayElement(jtable, index, jstorage);
     index++;
@@ -315,7 +314,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas
     jobject jhost   = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
 
     if (not jhost) {
-      jstring jname = env->NewStringUTF(host->getCname());
+      jstring jname = env->NewStringUTF(host->get_cname());
       jhost         = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
     }
 
@@ -328,7 +327,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname)
 {
   const char *name = env->GetStringUTFChars((jstring) jname, 0);
-  MSG_mailbox_set_async(name);
+  sg_mailbox_set_receiver(name);
   env->ReleaseStringUTFChars((jstring) jname, name);
 }
 
@@ -374,4 +373,45 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env,
   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_getLoad(JNIEnv* env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_load(host);
 }
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_current_load(host);
+}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_computed_flops(host);
+}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_avg_load(host);
+}
\ No newline at end of file