Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused type definitions.
[simgrid.git] / src / bindings / java / jxbt_utilities.hpp
1 /* Various JNI helper functions                                             */
2
3 /* Copyright (c) 2007-2019. 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_UTILITIES_HPP
9 #define JXBT_UTILITIES_HPP
10
11 #include <cstdint>
12 #include <jni.h>
13 #include <string>
14
15 /* Search a class and throw an exception if not found */
16 jclass jxbt_get_class(JNIEnv* env, const char* name);
17
18 /* 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) */
19 jmethodID jxbt_get_jmethod(JNIEnv* env, jclass cls, const char* name, const char* signature);
20
21 /* Like the jxbt_get_class() but get a static method */
22 jmethodID jxbt_get_static_jmethod(JNIEnv* env, jclass cls, const char* name, const char* signature);
23
24 /* 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) */
25 jfieldID jxbt_get_jfield(JNIEnv* env, jclass cls, const char* name, const char* signature);
26
27 /* 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) */
28 jmethodID jxbt_get_smethod(JNIEnv* env, const char* classname, const char* name, const char* signature);
29
30 /* Like the jxbt_get_smethod() but get a static method */
31 jmethodID jxbt_get_static_smethod(JNIEnv* env, const char* classname, const char* name, const char* signature);
32
33 /* 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) */
34 jfieldID jxbt_get_sfield(JNIEnv* env, const char* classname, const char* name, const char* signature);
35
36 #define jxbt_check_res(fun, res, allowed_exceptions, detail)                                                           \
37   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     }                                                                                                                  \
49   } while (0)
50
51 /* Throws an exception according to its name */
52 void jxbt_throw_by_name(JNIEnv* env, const char* name, const std::string& msg);
53 /** Thrown on internal error of this layer, or on problem with JNI */
54 void jxbt_throw_jni(JNIEnv* env, const std::string& msg);
55 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
56 void jxbt_throw_notbound(JNIEnv* env, const std::string& kind, void* pointer);
57 /** Thrown if NULL gets used */
58 void jxbt_throw_null(JNIEnv* env, const std::string& msg);
59
60 /** Thrown on illegal arguments */
61 void jxbt_throw_illegal(JNIEnv* env, const std::string& msg);
62 /** Thrown when looking for a host from name does not lead to anything */
63 void jxbt_throw_host_not_found(JNIEnv* env, const std::string& invalid_name);
64 /** Thrown when looking for a host from name does not lead to anything */
65 void jxbt_throw_process_not_found(JNIEnv* env, const std::string& invalid_name);
66 /** Thrown when a transfer failure accure while Sending task */
67 void jxbt_throw_transfer_failure(JNIEnv* env, const std::string& detail);
68 /** Thrown when a host failure occurs while Sending a task*/
69 void jxbt_throw_host_failure(JNIEnv* env, const std::string& details);
70 /** Thrown when a timeout occurs while Sending a task */
71 void jxbt_throw_time_out_failure(JNIEnv* env, const std::string& details);
72 /**Thrown when a task is canceled */
73 void jxbt_throw_task_cancelled(JNIEnv* env, const std::string& details);
74 /** Thrown when looking for a storage from name does not lead to anything */
75 void jxbt_throw_storage_not_found(JNIEnv* env, const std::string& invalid_name);
76
77 #endif