Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4d6dd0395b60db276d325e2eec6d45e84c6c6ba7
[simgrid.git] / src / java / jxbt_utilities.h
1 /*
2  * $Id$
3  *
4  * Various JNI helper functions
5  *
6  * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved. 
7  *
8  * This program is free software; you can redistribute it and/or modify it 
9  * under the terms of the license (GNU LGPL) which comes with this package.
10  *
11  */
12
13 #ifndef JXBT_UTILITY_H
14 #define JXBT_UTILITY_H
15
16 #include <jni.h>
17
18 /* *********** */
19 /* JNI GETTERS */
20 /* *********** */
21
22 /* Search a class and throw an exception if not found */
23 jclass jxbt_get_class(JNIEnv * env, const char *name);
24
25 /* Search a method in a class and throw an exception if not found
26    (it's ok to to pass a NULL class: it's a noop) */
27 jmethodID jxbt_get_jmethod(JNIEnv * env, jclass class,
28                            const char *name, const char *signature);
29
30 /* Like the jxbt_get_class() but get a static method */
31 jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls,
32                                   const char *name, const char *signature);
33
34 /* Search a field in a class and throw an exception if not found
35    (it's ok to to pass a NULL class: it's a noop) */
36 jfieldID jxbt_get_jfield(JNIEnv * env, jclass class,
37                          const char *name, const char *signature);
38
39
40 /* Search a method in a class and throw an exception if not found
41    (it's ok to to pass a NULL class: it's a noop) */
42 jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname,
43                            const char *name, const char *signature);
44
45 /* Like the jxbt_get_smethod() but get a static method */
46 jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname,
47                                   const char *name, const char *signature);
48
49 /* Search a field in a class and throw an exception if not found
50    (it's ok to to pass a NULL class: it's a noop) */
51 jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname,
52                          const char *name, const char *signature);
53
54
55 /* ***************** */
56 /* EXCEPTION RAISING */
57 /* ***************** */
58
59 #define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
60     if (res != MSG_OK && res | allowed_exceptions) { \
61       xbt_die(bprintf("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res)); \
62     } else if (res == MSG_HOST_FAILURE) { \
63       jxbt_throw_host_failure(env, detail); \
64     } else if (res == MSG_TRANSFER_FAILURE) { \
65       jxbt_throw_transfer_failure(env,detail); \
66     } else if (res == MSG_TIMEOUT_FAILURE) { \
67       jxbt_throw_time_out_failure(env,detail); \
68    } } while (0)
69
70 /** Thrown on internal error of this layer, or on problem with JNI */
71 void jxbt_throw_jni(JNIEnv * env, const char *msg);
72 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
73 void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer);
74
75 /** Thrown on error in native MSG code */
76 void jxbt_throw_native(JNIEnv * env, char *msg);
77
78 /** Thrown if NULL gets used */
79 void jxbt_throw_null(JNIEnv * env, char *msg);
80
81 /** Thrown on illegal arguments */
82 void jxbt_throw_illegal(JNIEnv * env, char *msg);
83 /** Thrown when looking for an host from name does not lead to anything */
84 void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name);
85 /** Thrown when looking for an host from name does not lead to anything */
86 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
87 /** Thrown when a transfer failure accure while Sending task */
88 void jxbt_throw_transfer_failure(JNIEnv * env,char *detail);
89 /** Thrown when a host failure accures while Sending task*/
90 void jxbt_throw_host_failure(JNIEnv *env,char *details);
91 /** Thrown when a time out accures While Sending task */
92 void jxbt_throw_time_out_failure(JNIEnv *env,char *details);
93
94 #endif /* ! JXBT_UTILITY_H */