1 /* Various JNI helper functions */
3 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
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. */
8 #ifndef JXBT_UTILITIES_HPP
9 #define JXBT_UTILITIES_HPP
17 /* Search a class and throw an exception if not found */
18 jclass jxbt_get_class(JNIEnv* env, const char* name);
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);
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);
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);
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);
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);
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);
38 #define jxbt_check_res(fun, res, allowed_exceptions, detail) \
40 if (res != MSG_OK && (res | allowed_exceptions)) { \
41 xbt_die("%s failed with error code %d, which is not an allowed exception. Please fix me.", fun, res); \
42 } else if (res == MSG_HOST_FAILURE) { \
43 jxbt_throw_host_failure(env, detail); \
44 } else if (res == MSG_TRANSFER_FAILURE) { \
45 jxbt_throw_transfer_failure(env, detail); \
46 } else if (res == MSG_TIMEOUT) { \
47 jxbt_throw_time_out_failure(env, detail); \
48 } else if (res == MSG_TASK_CANCELED) { \
49 jxbt_throw_task_cancelled(env, detail); \
53 /* Throws an exception according to its name */
54 void jxbt_throw_by_name(JNIEnv* env, const char* name, std::string msg);
55 /** Thrown on internal error of this layer, or on problem with JNI */
56 void jxbt_throw_jni(JNIEnv* env, std::string msg);
57 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
58 void jxbt_throw_notbound(JNIEnv* env, std::string kind, void* pointer);
59 /** Thrown if NULL gets used */
60 void jxbt_throw_null(JNIEnv* env, std::string msg);
62 /** Thrown on illegal arguments */
63 void jxbt_throw_illegal(JNIEnv* env, std::string msg);
64 /** Thrown when looking for an host from name does not lead to anything */
65 void jxbt_throw_host_not_found(JNIEnv* env, std::string invalid_name);
66 /** Thrown when looking for an host from name does not lead to anything */
67 void jxbt_throw_process_not_found(JNIEnv* env, std::string invalid_name);
68 /** Thrown when a transfer failure accure while Sending task */
69 void jxbt_throw_transfer_failure(JNIEnv* env, std::string detail);
70 /** Thrown when a host failure occurs while Sending a task*/
71 void jxbt_throw_host_failure(JNIEnv* env, std::string details);
72 /** Thrown when a timeout occurs while Sending a task */
73 void jxbt_throw_time_out_failure(JNIEnv* env, std::string details);
74 /**Thrown when a task is canceled */
75 void jxbt_throw_task_cancelled(JNIEnv* env, std::string details);
76 /** Thrown when looking for a storage from name does not lead to anything */
77 void jxbt_throw_storage_not_found(JNIEnv* env, std::string invalid_name);