X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a92d7b716f51a53dea7f59db8524d4add713b910..5cfd78ee13dfd9c06ca703c402d2d8e62cbfec3f:/src/bindings/java/jmsg_storage.cpp diff --git a/src/bindings/java/jmsg_storage.cpp b/src/bindings/java/jmsg_storage.cpp index e38230cd64..bf28cdc805 100644 --- a/src/bindings/java/jmsg_storage.cpp +++ b/src/bindings/java/jmsg_storage.cpp @@ -1,20 +1,21 @@ /* Java bindings of the Storage API. */ -/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2012-2019. 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/msg.h" +#include "simgrid/plugins/file_system.h" -#include "jmsg.h" +#include "include/xbt/signal.hpp" +#include "jmsg.hpp" #include "jmsg_storage.h" -#include "jxbt_utilities.h" +#include "jxbt_utilities.hpp" +#include "simgrid/s4u/Storage.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java); -SG_BEGIN_DECL() - static jmethodID jstorage_method_Storage_constructor; static jfieldID jstorage_field_Storage_bind; static jfieldID jstorage_field_Storage_name; @@ -56,7 +57,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j /* 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); @@ -69,7 +70,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j } env->ReleaseStringUTFChars(jname, name); - if (java_storage_map.find(storage->key) == java_storage_map.end()) { + if (java_storage_map.find(storage) == java_storage_map.end()) { /* Instantiate a new java storage */ jstorage = jstorage_new_instance(env); @@ -93,16 +94,16 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j /* the native storage data field is set with the global reference to the * java storage returned by this function */ - java_storage_map.insert({storage->key, jstorage}); + java_storage_map.insert({storage, jstorage}); } else - jstorage = java_storage_map.at(storage->key); + jstorage = java_storage_map.at(storage); /* return the global reference to the java storage instance */ return (jobject)jstorage; } JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv * env,jobject jstorage) { - msg_storage_t storage = jstorage_get_native(env, jstorage); + const_sg_storage_t storage = jstorage_get_native(env, jstorage); if (not storage) { jxbt_throw_notbound(env, "storage", jstorage); @@ -113,7 +114,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv * env,jobjec } JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jobject jstorage) { - msg_storage_t storage = jstorage_get_native(env, jstorage); + const_sg_storage_t storage = jstorage_get_native(env, jstorage); if (not storage) { jxbt_throw_notbound(env, "storage", jstorage); @@ -124,7 +125,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jo } JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jobject jstorage) { - msg_storage_t storage = jstorage_get_native(env, jstorage); + const_sg_storage_t storage = jstorage_get_native(env, jstorage); if (not storage) { jxbt_throw_notbound(env, "storage", jstorage); @@ -135,7 +136,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jo } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env, jobject jstorage, jobject jname) { - msg_storage_t storage = jstorage_get_native(env, jstorage); + const_sg_storage_t storage = jstorage_get_native(env, jstorage); if (not storage) { jxbt_throw_notbound(env, "storage", jstorage); @@ -164,17 +165,15 @@ Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0); - char *value = xbt_strdup(value_java); - MSG_storage_set_property_value(storage, name, value); + storage->set_property(name, std::string(value_java)); env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); - } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getHost(JNIEnv * env,jobject jstorage) { - msg_storage_t storage = jstorage_get_native(env, jstorage); + const_sg_storage_t storage = jstorage_get_native(env, jstorage); if (not storage) { jxbt_throw_notbound(env, "storage", jstorage); @@ -215,8 +214,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc for (index = 0; index < count; index++) { storage = xbt_dynar_get_as(table,index,msg_storage_t); - if (java_storage_map.find(storage->key) != java_storage_map.end()) { - jstorage = java_storage_map.at(storage->key); + if (java_storage_map.find(storage) != java_storage_map.end()) { + jstorage = java_storage_map.at(storage); } else { jname = env->NewStringUTF(MSG_storage_get_name(storage)); jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname); @@ -227,5 +226,3 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc xbt_dynar_free(&table); return jtable; } - -SG_END_DECL()