[PATCH] ActiveX: Use exception_bridge() for errors

Cyril Mathé cmathe at actech-innovation.com
Wed May 27 10:19:45 CEST 2009


---
 projects/activex/vlccontrol2.cpp |   92 +++++++++++--------------------------
 projects/activex/vlccontrol2.h   |    1 +
 2 files changed, 29 insertions(+), 64 deletions(-)

diff --git a/projects/activex/vlccontrol2.cpp b/projects/activex/vlccontrol2.cpp
index daebef7..28a2a45 100644
--- a/projects/activex/vlccontrol2.cpp
+++ b/projects/activex/vlccontrol2.cpp
@@ -56,6 +56,7 @@ EMIT_EXCEPTION_BRIDGE( VLCMessages )
 EMIT_EXCEPTION_BRIDGE( VLCLog )
 EMIT_EXCEPTION_BRIDGE( VLCPlaylistItems )
 EMIT_EXCEPTION_BRIDGE( VLCPlaylist )
+EMIT_EXCEPTION_BRIDGE( VLCSubtitle )
 EMIT_EXCEPTION_BRIDGE( VLCVideo )
 
 #undef  EMIT_EXCEPTION_BRIDGE
@@ -251,14 +252,7 @@ STDMETHODIMP VLCAudio::get_count(long* trackNumber)
         libvlc_exception_init(&ex);
         // get the number of audio track available and return it
         *trackNumber = libvlc_audio_get_track_count(p_md, &ex);
-        if( libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCAudio,
-                         libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
-        return NOERROR;
+        hr = exception_bridge(&ex);
     }
     return hr;
 };
@@ -282,25 +276,19 @@ STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
 
         // get tracks description
         p_trackDesc = libvlc_audio_get_track_description(p_md, &ex);
-        if(  libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
+        hr = exception_bridge(&ex);
+        if(  hr == E_FAIL )
+            return hr;
 
         //get the number of available track
         i_limit = libvlc_audio_get_track_count(p_md, &ex);
-        if(  libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
+        hr = exception_bridge(&ex);
+        if(  hr == E_FAIL )
+            return hr;
 
         // check if the number given is a good one
         if ( ( trackID > ( i_limit -1 ) ) || ( trackID < 0 ) )
-                return E_FAIL;
+            return E_FAIL;
 
         // get the good trackDesc
         for( i = 0 ; i < trackID ; i++ )
@@ -311,13 +299,13 @@ STDMETHODIMP VLCAudio::description(long trackID, BSTR* name)
         psz_name = p_trackDesc->psz_name;
 
         // return it
-        if( psz_name != NULL )
+        if( psz_name == NULL )
         {
-            *name = BSTRFromCStr(CP_UTF8, psz_name);
-            return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
+            *name = NULL;
+            return E_FAIL;
         }
-        *name = NULL;
-        return E_FAIL;
+        *name = BSTRFromCStr(CP_UTF8, psz_name);
+        hr = (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
     }
     return hr;
 };
@@ -1819,13 +1807,7 @@ STDMETHODIMP VLCSubtitle::get_track(long* spu)
         libvlc_exception_init(&ex);
 
         *spu = libvlc_video_get_spu(p_md, &ex);
-        if( ! libvlc_exception_raised(&ex) )
-        {
-            return NOERROR;
-        }
-        _p_instance->setErrorInfo(IID_IVLCSubtitle, libvlc_exception_get_message(&ex));
-        libvlc_exception_clear(&ex);
-        return E_FAIL;
+        hr = exception_bridge(&ex);
     }
     return hr;
 };
@@ -1840,13 +1822,7 @@ STDMETHODIMP VLCSubtitle::put_track(long spu)
         libvlc_exception_init(&ex);
 
         libvlc_video_set_spu(p_md, spu, &ex);
-        if( libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCSubtitle, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
-        return NOERROR;
+        hr = exception_bridge(&ex);
     }
     return hr;
 };
@@ -1864,13 +1840,7 @@ STDMETHODIMP VLCSubtitle::get_count(long* spuNumber)
         libvlc_exception_init(&ex);
         // get the number of video subtitle available and return it
         *spuNumber = libvlc_video_get_spu_count(p_md, &ex);
-        if( libvlc_exception_raised(&ex) )
-        {
-           _p_instance->setErrorInfo(IID_IVLCSubtitle, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
-        return NOERROR;
+        hr = exception_bridge(&ex);
     }
     return hr;
 };
@@ -1894,21 +1864,15 @@ STDMETHODIMP VLCSubtitle::description(long nameID, BSTR* name)
 
         // get subtitles description
         p_spuDesc = libvlc_video_get_spu_description(p_md, &ex);
-        if(  libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCSubtitle, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
+        hr = exception_bridge(&ex);
+        if( hr == E_FAIL)
+            return hr;
 
         // get the number of available subtitle
         i_limit = libvlc_video_get_spu_count(p_md, &ex);
-        if( libvlc_exception_raised(&ex) )
-        {
-            _p_instance->setErrorInfo(IID_IVLCSubtitle, libvlc_exception_get_message(&ex));
-            libvlc_exception_clear(&ex);
-            return E_FAIL;
-        }
+        hr = exception_bridge(&ex);
+        if( hr == E_FAIL)
+            return hr;
 
         // check if the number given is a good one
         if ( ( nameID > ( i_limit -1 ) ) || ( nameID < 0 ) )
@@ -1923,13 +1887,13 @@ STDMETHODIMP VLCSubtitle::description(long nameID, BSTR* name)
         psz_name = p_spuDesc->psz_name;
 
         // return it
-        if( psz_name != NULL )
+        if( psz_name == NULL )
         {
-            *name = BSTRFromCStr(CP_UTF8, psz_name);
-            return (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
+            *name = NULL;
+            return E_FAIL;
         }
-        *name = NULL;
-        return E_FAIL;
+        *name = BSTRFromCStr(CP_UTF8, psz_name);
+        hr = (NULL == *name) ? E_OUTOFMEMORY : NOERROR;
     }
     return hr;
 };
diff --git a/projects/activex/vlccontrol2.h b/projects/activex/vlccontrol2.h
index 5e06fdf..1134643 100644
--- a/projects/activex/vlccontrol2.h
+++ b/projects/activex/vlccontrol2.h
@@ -532,6 +532,7 @@ public:
 
 protected:
     HRESULT loadTypeInfo();
+    HRESULT exception_bridge(libvlc_exception_t *ex);
 
 private:
     VLCPlugin*      _p_instance;
-- 
1.5.4.3


--=-0zCtUVnQUgGEWvjWN7Ov--



More information about the vlc-devel mailing list