Logo AND Algorithmique Numérique Distribuée

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