Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
537167dbf35b21c97facc6a7c804d0c503bdfbe0
[simgrid.git] / src / bindings / java / jxbt_utilities.hpp
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_UTILITIES_HPP
9 #define JXBT_UTILITIES_HPP
10
11 #include <jni.h>
12 #include <stdint.h>
13 #include <string>
14
15 extern "C" {
16
17 /* Search a class and throw an exception if not found */
18 jclass jxbt_get_class(JNIEnv * env, const char *name);
19
20 /* 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) */
21 jmethodID jxbt_get_jmethod(JNIEnv * env, jclass cls, const char *name, const char *signature);
22
23 /* Like the jxbt_get_class() but get a static method */
24 jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls, const char *name, const char *signature);
25
26 /* 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) */
27 jfieldID jxbt_get_jfield(JNIEnv * env, jclass cls, const char *name, const char *signature);
28
29 /* 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) */
30 jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname, const char *name, const char *signature);
31
32 /* Like the jxbt_get_smethod() but get a static method */
33 jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname, const char *name, const char *signature);
34
35 /* 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) */
36 jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, const char *name, const char *signature);
37
38 #define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
39     if (res != MSG_OK && (res | allowed_exceptions)) { \
40       xbt_die("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res); \
41     } else if (res == MSG_HOST_FAILURE) { \
42       jxbt_throw_host_failure(env, detail); \
43     } else if (res == MSG_TRANSFER_FAILURE) { \
44       jxbt_throw_transfer_failure(env,detail); \
45     } else if (res == MSG_TIMEOUT) { \
46       jxbt_throw_time_out_failure(env,detail); \
47     } else if (res == MSG_TASK_CANCELED){ \
48       jxbt_throw_task_cancelled(env,detail); \
49    } } while (0)
50
51 /* Throws an exception according to its name */
52 void jxbt_throw_by_name(JNIEnv* env, const char* name, std::string msg);
53 /** Thrown on internal error of this layer, or on problem with JNI */
54 void jxbt_throw_jni(JNIEnv* env, 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, std::string kind, void* pointer);
57 /** Thrown if NULL gets used */
58 void jxbt_throw_null(JNIEnv* env, std::string msg);
59
60 /** Thrown on illegal arguments */
61 void jxbt_throw_illegal(JNIEnv* env, std::string msg);
62 /** Thrown when looking for an host from name does not lead to anything */
63 void jxbt_throw_host_not_found(JNIEnv* env, std::string invalid_name);
64 /** Thrown when looking for an host from name does not lead to anything */
65 void jxbt_throw_process_not_found(JNIEnv* env, std::string invalid_name);
66 /** Thrown when a transfer failure accure while Sending task */
67 void jxbt_throw_transfer_failure(JNIEnv* env, std::string detail);
68 /** Thrown when a host failure occurs while Sending a task*/
69 void jxbt_throw_host_failure(JNIEnv* env, std::string details);
70 /** Thrown when a timeout occurs while Sending a task */
71 void jxbt_throw_time_out_failure(JNIEnv* env, std::string details);
72 /**Thrown when a task is canceled */
73 void jxbt_throw_task_cancelled(JNIEnv* env, 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, std::string invalid_name);
76 }
77 #endif