]> git.sesse.net Git - vlc/commitdiff
python-ctypes: accomodate both old and new message exception getter
authorOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 28 Aug 2009 14:34:49 +0000 (16:34 +0200)
committerOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 28 Aug 2009 14:34:49 +0000 (16:34 +0200)
bindings/python-ctypes/header.py

index 4f4c870ade32bebe6f3215c1745387a7bffc5056..83b370f84c30d02a60cd0c9a09b486289e1310c5 100755 (executable)
@@ -91,19 +91,42 @@ class LibVLCException(Exception):
     pass
 
 # From libvlc_structures.h
-class VLCException(ctypes.Structure):
-    """libvlc exception.
-    """
-    _fields_= [
-                ('raised', ctypes.c_int),
-                ('code', ctypes.c_int),
-                ('message', ctypes.c_char_p),
-                ]
-    def init(self):
-        libvlc_exception_init(self)
 
-    def clear(self):
-        libvlc_exception_clear(self)
+# This is version-dependent, depending on the presence of libvlc_exception_get_message.
+
+if hasattr(dll, 'libvlc_exception_get_message'):
+    # New-style message passing
+    class VLCException(ctypes.Structure):
+        """libvlc exception.
+        """
+        _fields_= [
+                    ('raised', ctypes.c_int),
+                    ]
+
+        @property
+        def message(self):
+            return dll.libvlc_exception_get_message()
+
+        def init(self):
+            libvlc_exception_init(self)
+
+        def clear(self):
+            libvlc_exception_clear(self)
+else:
+    # Old-style exceptions
+    class VLCException(ctypes.Structure):
+        """libvlc exception.
+        """
+        _fields_= [
+                    ('raised', ctypes.c_int),
+                    ('code', ctypes.c_int),
+                    ('message', ctypes.c_char_p),
+                    ]
+        def init(self):
+            libvlc_exception_init(self)
+
+        def clear(self):
+            libvlc_exception_clear(self)
 
 class PlaylistItem(ctypes.Structure):
     _fields_= [