X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ef33b9c0c2c0e9c15c27fce82515a23e8aadc0ed..16673e04b393c2d8c031d0d77ec318ac2c711f4e:/src/bindings/java/jmsg_file.cpp diff --git a/src/bindings/java/jmsg_file.cpp b/src/bindings/java/jmsg_file.cpp index c716c996f1..5d43d22617 100644 --- a/src/bindings/java/jmsg_file.cpp +++ b/src/bindings/java/jmsg_file.cpp @@ -1,51 +1,53 @@ -/* Functions related to the java file API. */ +/* Java bindings of the file API. */ -/* Copyright (c) 2012-2014. 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 "jmsg_file.h" -#include "jxbt_utilities.h" +#include "jxbt_utilities.hpp" void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t fd) { - env->SetLongField(jfile, jfile_field_bind, (intptr_t)fd); + env->SetLongField(jfile, jfile_field_bind, reinterpret_cast(fd)); } msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) { - return (msg_file_t)(intptr_t)env->GetLongField(jfile, jfile_field_bind); + return reinterpret_cast(env->GetLongField(jfile, jfile_field_bind)); } JNIEXPORT void JNICALL Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) { jclass class_File = env->FindClass("org/simgrid/msg/File"); jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J"); - xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class."); + xbt_assert((jfile_field_bind != nullptr), "Can't find 'bind' field in File class."); } JNIEXPORT void JNICALL Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jpath) { const char *path = env->GetStringUTFChars((jstring) jpath, 0); - msg_file_t file; - - file = MSG_file_open(path, NULL); + msg_file_t file = MSG_file_open(path, nullptr); jfile_bind(env, jfile, file); - env->ReleaseStringUTFChars((jstring) jpath, path); + env->ReleaseStringUTFChars(static_cast(jpath), path); } JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize) { msg_file_t file = jfile_get_native(env, jfile); - return (jlong)MSG_file_read(file, (sg_size_t)jsize); + return static_cast(MSG_file_read(file, static_cast(jsize))); } JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize) { msg_file_t file = jfile_get_native(env, jfile); - return (jlong)MSG_file_write(file, (sg_size_t)jsize); + return static_cast(MSG_file_write(file, static_cast(jsize))); +} + +JNIEXPORT void JNICALL Java_org_simgrid_msg_File_seek(JNIEnv *env, jobject jfile, jlong offset, jlong origin) { + msg_file_t file = jfile_get_native(env, jfile); + MSG_file_seek(file, static_cast(offset), static_cast(origin)); } JNIEXPORT void JNICALL Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) { msg_file_t file = jfile_get_native(env, jfile); MSG_file_close(file); - jfile_bind(env, jfile, NULL); + jfile_bind(env, jfile, nullptr); }