[Android] [PATCH] VlcObject: more explicit exceptions
Thomas Guillem
thomas at gllm.fr
Mon Mar 23 09:39:25 CET 2015
---
libvlc/jni/libvlcjni-media.c | 10 ++++++----
libvlc/jni/libvlcjni-mediadiscoverer.c | 5 +++--
libvlc/jni/libvlcjni-medialist.c | 17 +++++++++++------
libvlc/jni/libvlcjni-vlcobject.c | 26 +++++++++++++++++++++++---
libvlc/jni/libvlcjni-vlcobject.h | 6 ++++--
5 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index afe1a71..0c3d736 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -124,6 +124,7 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
{
vlcjni_object *p_obj;
const char* p_mrl;
+ const char *p_error;
if (!jmrl || !(p_mrl = (*env)->GetStringUTFChars(env, jmrl, 0)))
{
@@ -131,12 +132,12 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
return;
}
- p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
+ p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc, &p_error);
if (!p_obj)
{
(*env)->ReleaseStringUTFChars(env, jmrl, p_mrl);
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
@@ -156,6 +157,7 @@ Java_org_videolan_libvlc_Media_nativeNewFromMediaList(JNIEnv *env, jobject thiz,
{
vlcjni_object *p_ml_obj = VLCJniObject_getInstance(env, ml);
vlcjni_object *p_obj;
+ const char *p_error;
if (!p_ml_obj)
{
@@ -163,10 +165,10 @@ Java_org_videolan_libvlc_Media_nativeNewFromMediaList(JNIEnv *env, jobject thiz,
return;
}
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_ml_obj->p_libvlc);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_ml_obj->p_libvlc, &p_error);
if (!p_obj)
{
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
diff --git a/libvlc/jni/libvlcjni-mediadiscoverer.c b/libvlc/jni/libvlcjni-mediadiscoverer.c
index 6ce7cfd..ab87037 100644
--- a/libvlc/jni/libvlcjni-mediadiscoverer.c
+++ b/libvlc/jni/libvlcjni-mediadiscoverer.c
@@ -27,6 +27,7 @@ Java_org_videolan_libvlc_MediaDiscoverer_nativeNew(JNIEnv *env,
{
vlcjni_object *p_obj;
const char* p_name;
+ const char *p_error;
if (!jname || !(p_name = (*env)->GetStringUTFChars(env, jname, 0)))
{
@@ -34,12 +35,12 @@ Java_org_videolan_libvlc_MediaDiscoverer_nativeNew(JNIEnv *env,
return;
}
- p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
+ p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc, &p_error);
if (!p_obj)
{
(*env)->ReleaseStringUTFChars(env, jname, p_name);
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
diff --git a/libvlc/jni/libvlcjni-medialist.c b/libvlc/jni/libvlcjni-medialist.c
index 5236885..b5766c8 100644
--- a/libvlc/jni/libvlcjni-medialist.c
+++ b/libvlc/jni/libvlcjni-medialist.c
@@ -163,11 +163,14 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromLibVlc(JNIEnv *env,
jobject thiz,
jobject libVlc)
{
- vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
+ const char *p_error;
+
+ vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc,
+ &p_error);
if (!p_obj)
{
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
@@ -183,6 +186,7 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMediaDiscoverer(JNIEnv *env,
{
vlcjni_object *p_md_obj = VLCJniObject_getInstance(env, md);
vlcjni_object *p_obj;
+ const char *p_error;
if (!p_md_obj)
{
@@ -190,10 +194,10 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMediaDiscoverer(JNIEnv *env,
return;
}
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_md_obj->p_libvlc);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_md_obj->p_libvlc, &p_error);
if (!p_obj)
{
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
@@ -209,6 +213,7 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMedia(JNIEnv *env,
{
vlcjni_object *p_m_obj = VLCJniObject_getInstance(env, m);
vlcjni_object *p_obj;
+ const char *p_error;
if (!p_m_obj)
{
@@ -216,10 +221,10 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMedia(JNIEnv *env,
return;
}
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_m_obj->p_libvlc);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_m_obj->p_libvlc, p_error);
if (!p_obj)
{
- throw_IllegalStateException(env, "can't create VLCObject");
+ throw_IllegalStateException(env, p_error);
return;
}
diff --git a/libvlc/jni/libvlcjni-vlcobject.c b/libvlc/jni/libvlcjni-vlcobject.c
index 46b9b89..0aba247 100644
--- a/libvlc/jni/libvlcjni-vlcobject.c
+++ b/libvlc/jni/libvlcjni-vlcobject.c
@@ -54,22 +54,32 @@ VLCJniObject_setInstance(JNIEnv *env, jobject thiz, vlcjni_object *p_obj)
vlcjni_object *
VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
- libvlc_instance_t *p_libvlc)
+ libvlc_instance_t *p_libvlc,
+ const char **pp_error)
{
vlcjni_object *p_obj;
libvlc_event_manager_t *ev;
p_obj = VLCJniObject_getInstance(env, thiz);
if (p_obj)
+ {
+ *pp_error = "Can't get VLCObject.mInstanceID";
return NULL;
+ }
p_obj = calloc(1, sizeof(vlcjni_object));
if (!p_obj)
+ {
+ *pp_error = "vlcjni_object calloc failed";
goto error;
+ }
p_obj->p_owner = calloc(1, sizeof(vlcjni_object_owner));
if (!p_obj->p_owner)
+ {
+ *pp_error = "vlcjni_object_owner calloc failed";
goto error;
+ }
p_obj->p_libvlc = p_libvlc;
libvlc_retain(p_libvlc);
@@ -86,10 +96,14 @@ VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
} else
p_obj->p_owner->weak = (*env)->NewWeakGlobalRef(env, thiz);
if (!p_obj->p_owner->weak && !p_obj->p_owner->weakCompat)
+ {
+ *pp_error = "No VLCObject weak reference";
goto error;
+ }
VLCJniObject_setInstance(env, thiz, p_obj);
+ *pp_error = NULL;
return p_obj;
error:
@@ -99,12 +113,18 @@ error:
vlcjni_object *
VLCJniObject_newFromJavaLibVlc(JNIEnv *env, jobject thiz,
- jobject libVlc)
+ jobject libVlc, const char **pp_error)
{
libvlc_instance_t *p_libvlc = getLibVlcInstance(env, libVlc);
if (!p_libvlc)
+ {
+ if (libVlc)
+ *pp_error = "Can't get mLibVlcInstance from libVlc";
+ else
+ *pp_error = "libVlc is NULL";
return NULL;
- return VLCJniObject_newFromLibVlc(env, thiz, p_libvlc);
+ }
+ return VLCJniObject_newFromLibVlc(env, thiz, p_libvlc, pp_error);
}
void
diff --git a/libvlc/jni/libvlcjni-vlcobject.h b/libvlc/jni/libvlcjni-vlcobject.h
index b74a8d1..212cd04 100644
--- a/libvlc/jni/libvlcjni-vlcobject.h
+++ b/libvlc/jni/libvlcjni-vlcobject.h
@@ -59,10 +59,12 @@ typedef bool (*event_cb)(vlcjni_object *p_obj, const libvlc_event_t *p_ev,
vlcjni_object *VLCJniObject_getInstance(JNIEnv *env, jobject thiz);
vlcjni_object *VLCJniObject_newFromJavaLibVlc(JNIEnv *env, jobject thiz,
- jobject libVlc);
+ jobject libVlc,
+ const char **pp_error);
vlcjni_object *VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
- libvlc_instance_t *p_libvlc);
+ libvlc_instance_t *p_libvlc,
+ const char **pp_error);
void VLCJniObject_release(JNIEnv *env, jobject thiz, vlcjni_object *p_obj);
--
2.1.3
More information about the Android
mailing list