4 * Various JNI helper functions
6 * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package.
13 #ifndef JXBT_UTILITY_H
14 #define JXBT_UTILITY_H
22 /* Search a class and throw an exception if not found */
23 jclass jxbt_get_class(JNIEnv * env, const char *name);
25 /* Search a method in a class and throw an exception if not found
26 (it's ok to to pass a NULL class: it's a noop) */
27 jmethodID jxbt_get_jmethod(JNIEnv * env, jclass class,
28 const char *name, const char *signature);
30 /* Like the jxbt_get_class() but get a static method */
31 jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls,
32 const char *name, const char *signature);
34 /* Search a field in a class and throw an exception if not found
35 (it's ok to to pass a NULL class: it's a noop) */
36 jfieldID jxbt_get_jfield(JNIEnv * env, jclass class,
37 const char *name, const char *signature);
40 /* Search a method in a class and throw an exception if not found
41 (it's ok to to pass a NULL class: it's a noop) */
42 jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname,
43 const char *name, const char *signature);
45 /* Like the jxbt_get_smethod() but get a static method */
46 jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname,
47 const char *name, const char *signature);
49 /* Search a field in a class and throw an exception if not found
50 (it's ok to to pass a NULL class: it's a noop) */
51 jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname,
52 const char *name, const char *signature);
55 /* ***************** */
56 /* EXCEPTION RAISING */
57 /* ***************** */
59 #define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
60 if (res != MSG_OK && res | allowed_exceptions) { \
61 xbt_die(bprintf("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res)); \
62 } else if (res == MSG_HOST_FAILURE) { \
63 jxbt_throw_host_failure(env, detail); \
64 } else if (res == MSG_TRANSFER_FAILURE) { \
65 jxbt_throw_transfer_failure(env,detail); \
66 } else if (res == MSG_TIMEOUT) { \
67 jxbt_throw_time_out_failure(env,detail); \
68 } else if (res == MSG_TASK_CANCELLED){ \
69 jxbt_throw_task_cancelled(env,detail); \
72 /** Thrown on internal error of this layer, or on problem with JNI */
73 void jxbt_throw_jni(JNIEnv * env, const char *msg);
74 /** Thrown when using an object not bound to a native one where it should, or reverse (kinda JNI issue) */
75 void jxbt_throw_notbound(JNIEnv * env, const char *kind, void *pointer);
77 /** Thrown on error in native MSG code */
78 void jxbt_throw_native(JNIEnv * env, char *msg);
80 /** Thrown if NULL gets used */
81 void jxbt_throw_null(JNIEnv * env, char *msg);
83 /** Thrown on illegal arguments */
84 void jxbt_throw_illegal(JNIEnv * env, char *msg);
85 /** Thrown when looking for an host from name does not lead to anything */
86 void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name);
87 /** Thrown when looking for an host from name does not lead to anything */
88 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
89 /** Thrown when a transfer failure accure while Sending task */
90 void jxbt_throw_transfer_failure(JNIEnv * env,char *detail);
91 /** Thrown when a host failure accures while Sending task*/
92 void jxbt_throw_host_failure(JNIEnv *env,char *details);
93 /** Thrown when a time out accures While Sending task */
94 void jxbt_throw_time_out_failure(JNIEnv *env,char *details);
95 /**Thrown when a task is canceled */
96 void jxbt_throw_task_cancelled(JNIEnv *env,char *details);
98 #endif /* ! JXBT_UTILITY_H */