amc: Allow creating global and local references of objects

This commit is contained in:
Sebastian Dröge 2015-03-28 15:48:28 +01:00
parent 6c7b64f90c
commit 7fb0fafed2
2 changed files with 23 additions and 11 deletions

View file

@ -128,8 +128,8 @@ gst_amc_jni_get_static_field_id (JNIEnv * env, GError ** err, jclass klass,
} }
jobject jobject
gst_amc_jni_new_object (JNIEnv * env, GError ** err, jclass klass, gst_amc_jni_new_object (JNIEnv * env, GError ** err, gboolean global,
jmethodID constructor, ...) jclass klass, jmethodID constructor, ...)
{ {
jobject tmp; jobject tmp;
va_list args; va_list args;
@ -144,12 +144,15 @@ gst_amc_jni_new_object (JNIEnv * env, GError ** err, jclass klass,
return NULL; return NULL;
} }
return gst_amc_jni_object_make_global (env, tmp); if (global)
return gst_amc_jni_object_make_global (env, tmp);
else
return tmp;
} }
jobject jobject
gst_amc_jni_new_object_from_static (JNIEnv * env, GError ** err, jclass klass, gst_amc_jni_new_object_from_static (JNIEnv * env, GError ** err,
jmethodID method, ...) gboolean global, jclass klass, jmethodID method, ...)
{ {
jobject tmp; jobject tmp;
va_list args; va_list args;
@ -164,7 +167,10 @@ gst_amc_jni_new_object_from_static (JNIEnv * env, GError ** err, jclass klass,
return NULL; return NULL;
} }
return gst_amc_jni_object_make_global (env, tmp); if (global)
return gst_amc_jni_object_make_global (env, tmp);
else
return tmp;
} }
jobject jobject
@ -207,18 +213,21 @@ gst_amc_jni_object_local_unref (JNIEnv * env, jobject object)
jstring jstring
gst_amc_jni_string_from_gchar (JNIEnv * env, GError ** err, gst_amc_jni_string_from_gchar (JNIEnv * env, GError ** err,
const gchar * string) gboolean global, const gchar * string)
{ {
jstring ret; jstring tmp;
ret = (*env)->NewStringUTF (env, string); tmp = (*env)->NewStringUTF (env, string);
if ((*env)->ExceptionCheck (env)) { if ((*env)->ExceptionCheck (env)) {
gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR, gst_amc_jni_set_error (env, err, GST_LIBRARY_ERROR,
GST_LIBRARY_ERROR_FAILED, "Failed to call Java method"); GST_LIBRARY_ERROR_FAILED, "Failed to call Java method");
ret = NULL; tmp = NULL;
} }
return ret; if (global)
return gst_amc_jni_object_make_global (env, tmp);
else
return tmp;
} }
gchar * gchar *

View file

@ -59,12 +59,14 @@ jfieldID gst_amc_jni_get_static_field_id (JNIEnv * env,
jobject gst_amc_jni_new_object (JNIEnv * env, jobject gst_amc_jni_new_object (JNIEnv * env,
GError ** err, GError ** err,
gboolean global,
jclass klass, jclass klass,
jmethodID constructor, jmethodID constructor,
...); ...);
jobject gst_amc_jni_new_object_from_static (JNIEnv * env, jobject gst_amc_jni_new_object_from_static (JNIEnv * env,
GError ** err, GError ** err,
gboolean global,
jclass klass, jclass klass,
jmethodID constructor, jmethodID constructor,
...); ...);
@ -87,6 +89,7 @@ gchar *gst_amc_jni_string_to_gchar (JNIEnv * env,
jstring gst_amc_jni_string_from_gchar (JNIEnv * env, jstring gst_amc_jni_string_from_gchar (JNIEnv * env,
GError ** error, GError ** error,
gboolean global,
const gchar * string); const gchar * string);
G_GNUC_PRINTF (5, 6) G_GNUC_PRINTF (5, 6)