amc: Make GError argument order more consistent

This commit is contained in:
Sebastian Dröge 2015-03-28 15:21:02 +01:00
parent 448867f0aa
commit 6c7b64f90c
2 changed files with 75 additions and 71 deletions

View file

@ -42,7 +42,7 @@ static gboolean started_java_vm = FALSE;
static pthread_key_t current_jni_env; static pthread_key_t current_jni_env;
jclass jclass
gst_amc_jni_get_class (JNIEnv * env, const gchar * name, GError ** err) gst_amc_jni_get_class (JNIEnv * env, GError ** err, const gchar * name)
{ {
jclass tmp, ret = NULL; jclass tmp, ret = NULL;
@ -50,8 +50,8 @@ gst_amc_jni_get_class (JNIEnv * env, const gchar * name, GError ** err)
tmp = (*env)->FindClass (env, name); tmp = (*env)->FindClass (env, name);
if ((*env)->ExceptionCheck (env) || !tmp) { if ((*env)->ExceptionCheck (env) || !tmp) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to find class %s", name); GST_LIBRARY_ERROR_FAILED, "Failed to find class %s", name);
goto done; goto done;
} }
@ -69,75 +69,78 @@ done:
} }
jmethodID jmethodID
gst_amc_jni_get_method_id (JNIEnv * env, jclass klass, const gchar * name, gst_amc_jni_get_method_id (JNIEnv * env, GError ** err, jclass klass,
const gchar * signature, GError ** err) const gchar * name, const gchar * signature)
{ {
jmethodID ret; jmethodID ret;
ret = (*env)->GetMethodID (env, klass, name, signature); ret = (*env)->GetMethodID (env, klass, name, signature);
if ((*env)->ExceptionCheck (env) || !ret) { if ((*env)->ExceptionCheck (env) || !ret) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get method ID %s (%s)", name, signature); GST_LIBRARY_ERROR_FAILED, "Failed to get method ID %s (%s)", name,
signature);
} }
return ret; return ret;
} }
jmethodID jmethodID
gst_amc_jni_get_static_method_id (JNIEnv * env, jclass klass, gst_amc_jni_get_static_method_id (JNIEnv * env, GError ** err, jclass klass,
const gchar * name, const gchar * signature, GError ** err) const gchar * name, const gchar * signature)
{ {
jmethodID ret; jmethodID ret;
ret = (*env)->GetStaticMethodID (env, klass, name, signature); ret = (*env)->GetStaticMethodID (env, klass, name, signature);
if ((*env)->ExceptionCheck (env) || !ret) { if ((*env)->ExceptionCheck (env) || !ret) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get static method ID %s (%s)", name, signature); GST_LIBRARY_ERROR_FAILED, "Failed to get static method ID %s (%s)",
name, signature);
} }
return ret; return ret;
} }
jfieldID jfieldID
gst_amc_jni_get_field_id (JNIEnv * env, jclass klass, const gchar * name, gst_amc_jni_get_field_id (JNIEnv * env, GError ** err, jclass klass,
const gchar * type, GError ** err) const gchar * name, const gchar * type)
{ {
jfieldID ret; jfieldID ret;
ret = (*env)->GetFieldID (env, klass, name, type); ret = (*env)->GetFieldID (env, klass, name, type);
if ((*env)->ExceptionCheck (env) || !ret) { if ((*env)->ExceptionCheck (env) || !ret) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get field ID %s (%s)", name, type); GST_LIBRARY_ERROR_FAILED, "Failed to get field ID %s (%s)", name, type);
} }
return ret; return ret;
} }
jfieldID jfieldID
gst_amc_jni_get_static_field_id (JNIEnv * env, jclass klass, const gchar * name, gst_amc_jni_get_static_field_id (JNIEnv * env, GError ** err, jclass klass,
const gchar * type, GError ** err) const gchar * name, const gchar * type)
{ {
jfieldID ret; jfieldID ret;
ret = (*env)->GetStaticFieldID (env, klass, name, type); ret = (*env)->GetStaticFieldID (env, klass, name, type);
if ((*env)->ExceptionCheck (env) || !ret) { if ((*env)->ExceptionCheck (env) || !ret) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get static field ID %s (%s)", name, type); GST_LIBRARY_ERROR_FAILED, "Failed to get static field ID %s (%s)", name,
type);
} }
return ret; return ret;
} }
jobject jobject
gst_amc_jni_new_object (JNIEnv * env, jclass klass, jmethodID constructor, gst_amc_jni_new_object (JNIEnv * env, GError ** err, jclass klass,
GError ** err, ...) jmethodID constructor, ...)
{ {
jobject tmp; jobject tmp;
va_list args; va_list args;
va_start (args, err); va_start (args, constructor);
tmp = (*env)->NewObjectV (env, klass, constructor, args); tmp = (*env)->NewObjectV (env, klass, constructor, args);
va_end (args); va_end (args);
if ((*env)->ExceptionCheck (env) || !tmp) { if ((*env)->ExceptionCheck (env) || !tmp) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to create object"); GST_LIBRARY_ERROR_FAILED, "Failed to create object");
return NULL; return NULL;
} }
@ -145,19 +148,19 @@ gst_amc_jni_new_object (JNIEnv * env, jclass klass, jmethodID constructor,
} }
jobject jobject
gst_amc_jni_new_object_from_static (JNIEnv * env, jclass klass, gst_amc_jni_new_object_from_static (JNIEnv * env, GError ** err, jclass klass,
jmethodID method, GError ** err, ...) jmethodID method, ...)
{ {
jobject tmp; jobject tmp;
va_list args; va_list args;
va_start (args, err); va_start (args, method);
tmp = (*env)->CallStaticObjectMethodV (env, klass, method, args); tmp = (*env)->CallStaticObjectMethodV (env, klass, method, args);
va_end (args); va_end (args);
if ((*env)->ExceptionCheck (env) || !tmp) { if ((*env)->ExceptionCheck (env) || !tmp) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to create object"); GST_LIBRARY_ERROR_FAILED, "Failed to create object");
return NULL; return NULL;
} }
@ -203,15 +206,15 @@ gst_amc_jni_object_local_unref (JNIEnv * env, jobject object)
} }
jstring jstring
gst_amc_jni_string_from_gchar (JNIEnv * env, const gchar * string, gst_amc_jni_string_from_gchar (JNIEnv * env, GError ** err,
GError ** err) const gchar * string)
{ {
jstring ret; jstring ret;
ret = (*env)->NewStringUTF (env, string); ret = (*env)->NewStringUTF (env, string);
if ((*env)->ExceptionCheck (env)) { if ((*env)->ExceptionCheck (env)) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to call Java method"); GST_LIBRARY_ERROR_FAILED, "Failed to call Java method");
ret = NULL; ret = NULL;
} }
@ -606,8 +609,8 @@ create_failed:
} }
static void static void
gst_amc_jni_set_error_string (JNIEnv * env, GQuark domain, gint code, gst_amc_jni_set_error_string (JNIEnv * env, GError ** err, GQuark domain,
GError ** err, const gchar * message) gint code, const gchar * message)
{ {
jthrowable exception; jthrowable exception;
@ -642,8 +645,8 @@ gst_amc_jni_set_error_string (JNIEnv * env, GQuark domain, gint code,
} }
G_GNUC_PRINTF (5, 6) G_GNUC_PRINTF (5, 6)
void gst_amc_jni_set_error (JNIEnv * env, GQuark domain, gint code, void gst_amc_jni_set_error (JNIEnv * env, GError ** err, GQuark domain,
GError ** err, const gchar * format, ...) gint code, const gchar * format, ...)
{ {
gchar *message; gchar *message;
va_list var_args; va_list var_args;
@ -652,7 +655,7 @@ G_GNUC_PRINTF (5, 6)
message = g_strdup_vprintf (format, var_args); message = g_strdup_vprintf (format, var_args);
va_end (var_args); va_end (var_args);
gst_amc_jni_set_error_string (env, domain, code, err, message); gst_amc_jni_set_error_string (env, err, domain, code, message);
g_free (message); g_free (message);
} }
@ -700,8 +703,8 @@ gboolean gst_amc_jni_call_static_##_name##_method (JNIEnv *env, GError ** err, j
va_start(args, value); \ va_start(args, value); \
*value = (*env)->CallStatic##_jname##MethodV(env, klass, methodID, args); \ *value = (*env)->CallStatic##_jname##MethodV(env, klass, methodID, args); \
if ((*env)->ExceptionCheck (env)) { \ if ((*env)->ExceptionCheck (env)) { \
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \ gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \
err, "Failed to call static Java method"); \ "Failed to call static Java method"); \
ret = FALSE; \ ret = FALSE; \
} \ } \
va_end(args); \ va_end(args); \
@ -728,8 +731,8 @@ gst_amc_jni_call_static_void_method (JNIEnv * env, GError ** err, jclass klass,
(*env)->CallStaticVoidMethodV (env, klass, methodID, args); (*env)->CallStaticVoidMethodV (env, klass, methodID, args);
if ((*env)->ExceptionCheck (env)) { if ((*env)->ExceptionCheck (env)) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to call static Java method"); GST_LIBRARY_ERROR_FAILED, "Failed to call static Java method");
ret = FALSE; ret = FALSE;
} }
va_end (args); va_end (args);
@ -744,8 +747,8 @@ gboolean gst_amc_jni_call_##_name##_method (JNIEnv *env, GError ** err, jobject
va_start(args, value); \ va_start(args, value); \
*value = (*env)->Call##_jname##MethodV(env, obj, methodID, args); \ *value = (*env)->Call##_jname##MethodV(env, obj, methodID, args); \
if ((*env)->ExceptionCheck (env)) { \ if ((*env)->ExceptionCheck (env)) { \
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \ gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \
err, "Failed to call Java method"); \ "Failed to call Java method"); \
ret = FALSE; \ ret = FALSE; \
} \ } \
va_end(args); \ va_end(args); \
@ -772,8 +775,8 @@ gst_amc_jni_call_void_method (JNIEnv * env, GError ** err, jobject obj,
(*env)->CallVoidMethodV (env, obj, methodID, args); (*env)->CallVoidMethodV (env, obj, methodID, args);
if ((*env)->ExceptionCheck (env)) { if ((*env)->ExceptionCheck (env)) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to call Java method"); GST_LIBRARY_ERROR_FAILED, "Failed to call Java method");
ret = FALSE; ret = FALSE;
} }
va_end (args); va_end (args);
@ -787,8 +790,8 @@ gboolean gst_amc_jni_get_##_name##_field (JNIEnv *env, GError ** err, jobject ob
\ \
*value = (*env)->Get##_jname##Field(env, obj, fieldID); \ *value = (*env)->Get##_jname##Field(env, obj, fieldID); \
if ((*env)->ExceptionCheck (env)) { \ if ((*env)->ExceptionCheck (env)) { \
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \ gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \
err, "Failed to get Java field"); \ "Failed to get Java field"); \
ret = FALSE; \ ret = FALSE; \
} \ } \
return ret; \ return ret; \
@ -811,8 +814,8 @@ gboolean gst_amc_jni_get_static_##_name##_field (JNIEnv *env, GError ** err, jcl
\ \
*value = (*env)->GetStatic##_jname##Field(env, klass, fieldID); \ *value = (*env)->GetStatic##_jname##Field(env, klass, fieldID); \
if ((*env)->ExceptionCheck (env)) { \ if ((*env)->ExceptionCheck (env)) { \
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \ gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, \
err, "Failed to get static Java field"); \ "Failed to get static Java field"); \
ret = FALSE; \ ret = FALSE; \
} \ } \
return ret; \ return ret; \
@ -842,23 +845,24 @@ gst_amc_jni_get_buffer_array (JNIEnv * env, GError ** err, jobject array,
buffer = (*env)->GetObjectArrayElement (env, array, i); buffer = (*env)->GetObjectArrayElement (env, array, i);
if ((*env)->ExceptionCheck (env) || !buffer) { if ((*env)->ExceptionCheck (env) || !buffer) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get buffer %d", i); GST_LIBRARY_ERROR_FAILED, "Failed to get buffer %d", i);
goto error; goto error;
} }
(*buffers)[i].object = gst_amc_jni_object_make_global (env, buffer); (*buffers)[i].object = gst_amc_jni_object_make_global (env, buffer);
if (!(*buffers)[i].object) { if (!(*buffers)[i].object) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to create global buffer reference %d", i); GST_LIBRARY_ERROR_FAILED,
"Failed to create global buffer reference %d", i);
goto error; goto error;
} }
(*buffers)[i].data = (*buffers)[i].data =
(*env)->GetDirectBufferAddress (env, (*buffers)[i].object); (*env)->GetDirectBufferAddress (env, (*buffers)[i].object);
if (!(*buffers)[i].data) { if (!(*buffers)[i].data) {
gst_amc_jni_set_error (env, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
err, "Failed to get buffer address %d", i); GST_LIBRARY_ERROR_FAILED, "Failed to get buffer address %d", i);
goto error; goto error;
} }
(*buffers)[i].size = (*buffers)[i].size =

View file

@ -30,43 +30,43 @@
#include <gst/gst.h> #include <gst/gst.h>
jclass gst_amc_jni_get_class (JNIEnv * env, jclass gst_amc_jni_get_class (JNIEnv * env,
const gchar * name, GError ** err,
GError ** err); const gchar * name);
jmethodID gst_amc_jni_get_method_id (JNIEnv * env, jmethodID gst_amc_jni_get_method_id (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
const gchar * name, const gchar * name,
const gchar * signature, const gchar * signature);
GError ** err);
jmethodID gst_amc_jni_get_static_method_id (JNIEnv * env, jmethodID gst_amc_jni_get_static_method_id (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
const gchar * name, const gchar * name,
const gchar * signature, const gchar * signature);
GError ** err);
jfieldID gst_amc_jni_get_field_id (JNIEnv * env, jfieldID gst_amc_jni_get_field_id (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
const gchar * name, const gchar * name,
const gchar * type, const gchar * type);
GError ** err);
jfieldID gst_amc_jni_get_static_field_id (JNIEnv * env, jfieldID gst_amc_jni_get_static_field_id (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
const gchar * name, const gchar * name,
const gchar * type, const gchar * type);
GError ** err);
jobject gst_amc_jni_new_object (JNIEnv * env, jobject gst_amc_jni_new_object (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
jmethodID constructor, jmethodID constructor,
GError ** err,
...); ...);
jobject gst_amc_jni_new_object_from_static (JNIEnv * env, jobject gst_amc_jni_new_object_from_static (JNIEnv * env,
GError ** err,
jclass klass, jclass klass,
jmethodID constructor, jmethodID constructor,
GError ** err,
...); ...);
jobject gst_amc_jni_object_make_global (JNIEnv * env, jobject gst_amc_jni_object_make_global (JNIEnv * env,
@ -86,14 +86,14 @@ gchar *gst_amc_jni_string_to_gchar (JNIEnv * env,
gboolean release); gboolean release);
jstring gst_amc_jni_string_from_gchar (JNIEnv * env, jstring gst_amc_jni_string_from_gchar (JNIEnv * env,
const gchar * string, GError ** error,
GError ** err); const gchar * string);
G_GNUC_PRINTF (5, 6) G_GNUC_PRINTF (5, 6)
void gst_amc_jni_set_error (JNIEnv * env, void gst_amc_jni_set_error (JNIEnv * env,
GError ** error,
GQuark domain, GQuark domain,
gint code, gint code,
GError ** error,
const gchar * format, ...); const gchar * format, ...);
gboolean gst_amc_jni_initialize (void); gboolean gst_amc_jni_initialize (void);