Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix compilation problem with tracing
[simgrid.git] / src / jmsg_file.c
1 /* Functions related to the java file API.                            */
2 /* Copyright (c) 2012. The SimGrid Team.
3  * All rights reserved.                                                     */
4
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. */
7 #include "jmsg_file.h"
8 #include "jxbt_utilities.h"
9 void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream) {
10   (*env)->SetLongField(env, jfile, jfile_field_bind, (jlong) (long) (stream));
11 }
12
13 msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
14         msg_file_t file = (msg_file_t)(*env)->GetLongField(env, jfile, jfile_field_bind);
15         return file;
16 }
17
18 JNIEXPORT void JNICALL
19 Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
20         jclass class_File = (*env)->FindClass(env, "org/simgrid/msg/File");
21         jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
22         xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
23 }
24 JNIEXPORT void JNICALL
25 Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, jobject jpath, jobject jmode) {
26
27         const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
28         const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
29         const char *mode = (*env)->GetStringUTFChars(env, jmode, 0);
30
31         msg_file_t file = MSG_file_open(storage, path, mode);
32
33         jfile_bind(env, jfile, file);
34
35         (*env)->ReleaseStringUTFChars(env, jstorage, storage);
36         (*env)->ReleaseStringUTFChars(env, jpath, path);
37         (*env)->ReleaseStringUTFChars(env, jmode, mode);
38 }
39 JNIEXPORT jlong JNICALL
40 Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize, jlong jnmemb) {
41         msg_file_t file = jfile_get_native(env, jfile);
42
43         size_t n = MSG_file_read(NULL,(size_t)jsize, (size_t)jnmemb, file);
44
45         return (jlong)n;
46 }
47
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);
51
52         size_t n = MSG_file_write(NULL, (size_t)jsize, (size_t)jnmemb, file);
53
54         return (jlong)n;
55 }
56 JNIEXPORT void JNICALL
57 Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile) {
58         msg_file_t file = jfile_get_native(env, jfile);
59
60         MSG_file_close(file);
61         jfile_bind(env, jfile, NULL);
62 }
63