Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Port JavaContext to C++
[simgrid.git] / src / bindings / java / jxbt_utilities.h
1 /* Various JNI helper functions                                             */
2
3 /* Copyright (c) 2007-2014. The SimGrid Team.
4  * All rights 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 #ifndef JXBT_UTILITY_H
10 #define JXBT_UTILITY_H
11
12 #include <jni.h>
13 #include <stdint.h>
14
15 /* *********** */
16 /* JNI GETTERS */
17 /* *********** */
18
19 SG_BEGIN_DECL()
20
21 /* Search a class and throw an exception if not found */
22 jclass jxbt_get_class(JNIEnv * env, const char *name);
23
24 /* Search a method in a class and throw an exception if not found
25    (it's ok to to pass a NULL class: it's a noop) */
26 jmethodID jxbt_get_jmethod(JNIEnv * env, jclass cls,
27                            const char *name, const char *signature);
28
29 /* Like the jxbt_get_class() but get a static method */
30 jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls,
31                                   const char *name, const char *signature);
32
33 /* Search a field in a class and throw an exception if not found
34    (it's ok to to pass a NULL class: it's a noop) */
35 jfieldID jxbt_get_jfield(JNIEnv * env, jclass cls,
36                          const char *name, const char *signature);
37
38
39 /* Search a method in a class and throw an exception if not found
40    (it's ok to to pass a NULL class: it's a noop) */
41 jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname,
42                            const char *name, const char *signature);
43
44 /* Like the jxbt_get_smethod() but get a static method */
45 jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname,
46                                   const char *name, const char *signature);
47
48 /* Search a field in a class and throw an exception if not found
49    (it's ok to to pass a NULL class: it's a noop) */
50 jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname,
51                          const char *name, const char *signature);
52
53
54 /* ***************** */
55 /* EXCEPTION RAISING */
56 /* ***************** */
57
58 #define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
59     if (res != MSG_OK && (res | allowed_exceptions)) { \
60       xbt_die("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res); \
61     } else if (res == MSG_HOST_FAILURE) { \
62       jxbt_throw_host_failure(env, detail); \
63     } else if (res == MSG_TRANSFER_FAILURE) { \
64       jxbt_throw_transfer_failure(env,detail); \
65     } else if (res == MSG_TIMEOUT) { \
66       jxbt_throw_time_out_failure(env,detail); \
67     } else if (res == MSG_TASK_CANCELED){ \
68       jxbt_throw_task_cancelled(env,detail); \
69    } } while (0)
70
71 /* Throws an exception according to its name */
72 void jxbt_throw_by_name(JNIEnv * env, const char *name, char *msg);
73 /** Thrown on internal error of this layer, or on problem with JNI */
74 void jxbt_throw_jni(JNIEnv * env, const char *msg);
75 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
76 void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer);
77
78 /** Thrown on error in native MSG code */
79 void jxbt_throw_native(JNIEnv * env, char *msg);
80
81 /** Thrown if NULL gets used */
82 void jxbt_throw_null(JNIEnv * env, char *msg);
83
84 /** Thrown on illegal arguments */
85 void jxbt_throw_illegal(JNIEnv * env, char *msg);
86 /** Thrown when looking for an host from name does not lead to anything */
87 void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name);
88 /** Thrown when looking for an host from name does not lead to anything */
89 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
90 /** Thrown when a transfer failure accure while Sending task */
91 void jxbt_throw_transfer_failure(JNIEnv * env, char *detail);
92 /** Thrown when a host failure occurs while Sending a task*/
93 void jxbt_throw_host_failure(JNIEnv * env, char *details);
94 /** Thrown when a timeout occurs while Sending a task */
95 void jxbt_throw_time_out_failure(JNIEnv * env, char *details);
96 /**Thrown when a task is canceled */
97 void jxbt_throw_task_cancelled(JNIEnv * env, char *details);
98 /** Thrown when looking for a storage from name does not lead to anything */
99 void jxbt_throw_storage_not_found(JNIEnv * env, const char *invalid_name);
100 #endif                          /* ! JXBT_UTILITY_H */
101
102 SG_END_DECL()