1 /* Various JNI helper functions */
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
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. */
10 #define JXBT_UTILITY_H
18 /* Search a class and throw an exception if not found */
19 jclass jxbt_get_class(JNIEnv * env, const char *name);
21 /* Search a method in a class and throw an exception if not found
22 (it's ok to to pass a NULL class: it's a noop) */
23 jmethodID jxbt_get_jmethod(JNIEnv * env, jclass class,
24 const char *name, const char *signature);
26 /* Like the jxbt_get_class() but get a static method */
27 jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls,
28 const char *name, const char *signature);
30 /* Search a field in a class and throw an exception if not found
31 (it's ok to to pass a NULL class: it's a noop) */
32 jfieldID jxbt_get_jfield(JNIEnv * env, jclass class,
33 const char *name, const char *signature);
36 /* Search a method in a class and throw an exception if not found
37 (it's ok to to pass a NULL class: it's a noop) */
38 jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname,
39 const char *name, const char *signature);
41 /* Like the jxbt_get_smethod() but get a static method */
42 jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname,
43 const char *name, const char *signature);
45 /* Search a field in a class and throw an exception if not found
46 (it's ok to to pass a NULL class: it's a noop) */
47 jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname,
48 const char *name, const char *signature);
51 /* ***************** */
52 /* EXCEPTION RAISING */
53 /* ***************** */
55 #define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
56 if (res != MSG_OK && res | allowed_exceptions) { \
57 xbt_die(bprintf("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res)); \
58 } else if (res == MSG_HOST_FAILURE) { \
59 jxbt_throw_host_failure(env, detail); \
60 } else if (res == MSG_TRANSFER_FAILURE) { \
61 jxbt_throw_transfer_failure(env,detail); \
62 } else if (res == MSG_TIMEOUT) { \
63 jxbt_throw_time_out_failure(env,detail); \
64 } else if (res == MSG_TASK_CANCELLED){ \
65 jxbt_throw_task_cancelled(env,detail); \
68 /** Thrown on internal error of this layer, or on problem with JNI */
69 void jxbt_throw_jni(JNIEnv * env, const char *msg);
70 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
71 void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer);
73 /** Thrown on error in native MSG code */
74 void jxbt_throw_native(JNIEnv * env, char *msg);
76 /** Thrown if NULL gets used */
77 void jxbt_throw_null(JNIEnv * env, char *msg);
79 /** Thrown on illegal arguments */
80 void jxbt_throw_illegal(JNIEnv * env, char *msg);
81 /** Thrown when looking for an host from name does not lead to anything */
82 void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name);
83 /** Thrown when looking for an host from name does not lead to anything */
84 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
85 /** Thrown when a transfer failure accure while Sending task */
86 void jxbt_throw_transfer_failure(JNIEnv * env,char *detail);
87 /** Thrown when a host failure accures while Sending task*/
88 void jxbt_throw_host_failure(JNIEnv *env,char *details);
89 /** Thrown when a time out accures While Sending task */
90 void jxbt_throw_time_out_failure(JNIEnv *env,char *details);
91 /**Thrown when a task is canceled */
92 void jxbt_throw_task_cancelled(JNIEnv *env,char *details);
94 #endif /* ! JXBT_UTILITY_H */