1 /* Functions related to the java file API. */
2 /* Copyright (c) 2012. The SimGrid Team.
3 * All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "jxbt_utilities.h"
10 void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream) {
11 (*env)->SetLongField(env, jfile, jfile_field_bind, (intptr_t)stream);
14 msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
16 (msg_file_t)(intptr_t)(*env)->GetLongField(env, jfile, jfile_field_bind);
20 JNIEXPORT void JNICALL
21 Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
22 jclass class_File = (*env)->FindClass(env, "org/simgrid/msg/File");
23 jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
24 xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
26 JNIEXPORT void JNICALL
27 Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, jobject jpath, jobject jmode) {
28 const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
29 const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
30 const char *mode = (*env)->GetStringUTFChars(env, jmode, 0);
33 file = MSG_file_open(storage, path, mode);
34 jfile_bind(env, jfile, file);
36 (*env)->ReleaseStringUTFChars(env, jstorage, storage);
37 (*env)->ReleaseStringUTFChars(env, jpath, path);
38 (*env)->ReleaseStringUTFChars(env, jmode, mode);
40 JNIEXPORT jlong JNICALL
41 Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize, jlong jnmemb) {
42 msg_file_t file = jfile_get_native(env, jfile);
44 n = MSG_file_read(NULL,(size_t)jsize, (size_t)jnmemb, file);
48 JNIEXPORT jlong JNICALL
49 Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize, jlong jnmemb) {
50 msg_file_t file = jfile_get_native(env, jfile);
52 n = MSG_file_write(NULL, (size_t)jsize, (size_t)jnmemb, file);
55 JNIEXPORT void JNICALL
56 Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) {
57 msg_file_t file = jfile_get_native(env, jfile);
60 jfile_bind(env, jfile, NULL);