1 /* Functions related to the java file API. */
3 /* Copyright (c) 2012-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "jxbt_utilities.h"
12 void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t fd) {
13 env->SetLongField(jfile, jfile_field_bind, (intptr_t)fd);
16 msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
17 return (msg_file_t)(intptr_t)env->GetLongField(jfile, jfile_field_bind);
20 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
21 jclass class_File = env->FindClass("org/simgrid/msg/File");
22 jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
23 xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
26 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jpath) {
27 const char *path = env->GetStringUTFChars((jstring) jpath, 0);
30 file = MSG_file_open(path, NULL);
31 jfile_bind(env, jfile, file);
33 env->ReleaseStringUTFChars((jstring) jpath, path);
36 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize) {
37 msg_file_t file = jfile_get_native(env, jfile);
38 return (jlong)MSG_file_read(file, (sg_size_t)jsize);
41 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize) {
42 msg_file_t file = jfile_get_native(env, jfile);
43 return (jlong)MSG_file_write(file, (sg_size_t)jsize);
46 JNIEXPORT void JNICALL Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) {
47 msg_file_t file = jfile_get_native(env, jfile);
50 jfile_bind(env, jfile, NULL);