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(env, jfile, jfile_field_bind, (intptr_t)fd);
16 msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
18 (msg_file_t)(intptr_t)(*env)->GetLongField(env, jfile, jfile_field_bind);
22 JNIEXPORT void JNICALL
23 Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
24 jclass class_File = (*env)->FindClass(env, "org/simgrid/msg/File");
25 jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
26 xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
28 JNIEXPORT void JNICALL
29 Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jpath) {
30 const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
33 file = MSG_file_open(path, NULL);
34 jfile_bind(env, jfile, file);
36 (*env)->ReleaseStringUTFChars(env, jpath, path);
38 JNIEXPORT jlong JNICALL
39 Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize) {
40 msg_file_t file = jfile_get_native(env, jfile);
41 return (jlong)MSG_file_read(file, (sg_size_t)jsize);
44 JNIEXPORT jlong JNICALL
45 Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize) {
46 msg_file_t file = jfile_get_native(env, jfile);
47 return (jlong)MSG_file_write(file, (sg_size_t)jsize);
49 JNIEXPORT void JNICALL
50 Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) {
51 msg_file_t file = jfile_get_native(env, jfile);
54 jfile_bind(env, jfile, NULL);