Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename TimeoutFailureException to TimeoutException
[simgrid.git] / src / java / jmsg_task.c
1 /*
2  * $Id$
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved. 
5  *
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.
8  *
9  * This contains the implementation of the functions in relation with the java
10  * task instance. 
11  */
12
13 #include "jmsg.h"
14 #include "jmsg_task.h"
15 #include "jxbt_utilities.h"
16
17 jobject jtask_new_global_ref(jobject jtask, JNIEnv * env)
18 {
19   return (*env)->NewGlobalRef(env, jtask);
20 }
21
22 void jtask_delete_global_ref(jobject jtask, JNIEnv * env)
23 {
24   (*env)->DeleteGlobalRef(env, jtask);
25 }
26
27 void jtask_bind(jobject jtask, m_task_t task, JNIEnv * env)
28 {
29   jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J");
30
31   if (!id)
32     return;
33
34   (*env)->SetLongField(env, jtask, id, (jlong) (long) (task));
35 }
36
37 m_task_t jtask_to_native_task(jobject jtask, JNIEnv * env)
38 {
39   jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J");
40
41   if (!id)
42     return NULL;
43
44   return (m_task_t) (long) (*env)->GetLongField(env, jtask, id);
45 }
46
47 jboolean jtask_is_valid(jobject jtask, JNIEnv * env)
48 {
49   jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Task", "bind", "J");
50
51   if (!id)
52     return JNI_FALSE;
53
54   return (*env)->GetLongField(env, jtask, id) ? JNI_TRUE : JNI_FALSE;
55 }