Logo AND Algorithmique Numérique Distribuée

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