[vlc-devel] commit: python-ctypes: fix Logger bindings. (Olivier Aubert )

git version control git at videolan.org
Thu Sep 3 17:22:52 CEST 2009


vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Thu Sep  3 17:22:22 2009 +0200| [d3b60bf02d38db7098205ad495c4c74cbce713fd] | committer: Olivier Aubert 

python-ctypes: fix Logger bindings.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d3b60bf02d38db7098205ad495c4c74cbce713fd
---

 bindings/python-ctypes/generate.py |   10 ++++++++--
 bindings/python-ctypes/header.py   |    3 +++
 bindings/python-ctypes/override.py |    9 ++++++---
 bindings/python-ctypes/test.py     |   26 ++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/bindings/python-ctypes/generate.py b/bindings/python-ctypes/generate.py
index a1870e0..05f39a7 100755
--- a/bindings/python-ctypes/generate.py
+++ b/bindings/python-ctypes/generate.py
@@ -329,7 +329,7 @@ class PythonGenerator(object):
         'libvlc_media_t*': 'Media',
         'libvlc_log_t*': 'Log',
         'libvlc_log_iterator_t*': 'LogIterator',
-        'libvlc_log_message_t*': 'LogMessage',
+        'libvlc_log_message_t*': 'ctypes.POINTER(LogMessage)',
         'libvlc_event_type_t': 'ctypes.c_uint',
         'libvlc_event_manager_t*': 'EventManager',
         'libvlc_media_discoverer_t*': 'MediaDiscoverer',
@@ -658,10 +658,16 @@ class PythonGenerator(object):
                 # Check for standard methods
                 if name == 'count':
                     # There is a count method. Generate a __len__ one.
-                    self.output("""    def __len__(self):
+                    if params and params[-1][0] == 'libvlc_exception_t*':
+                        self.output("""    def __len__(self):
         e=VLCException()
         return %s(self, e)
 """ % method)
+                    else:
+                        # No exception
+                        self.output("""    def __len__(self):
+        return %s(self)
+""" % method)
                 elif name.endswith('item_at_index'):
                     # Indexable (and thus iterable)"
                     self.output("""    def __getitem__(self, i):
diff --git a/bindings/python-ctypes/header.py b/bindings/python-ctypes/header.py
index d567b9b..fcaaaae 100755
--- a/bindings/python-ctypes/header.py
+++ b/bindings/python-ctypes/header.py
@@ -149,6 +149,9 @@ class LogMessage(ctypes.Structure):
                 ('message', ctypes.c_char_p),
                 ]
 
+    def __init__(self):
+        self.size=ctypes.sizeof(self)
+
     def __str__(self):
         return "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message)
 
diff --git a/bindings/python-ctypes/override.py b/bindings/python-ctypes/override.py
index 0888ae9..61ddd1e 100644
--- a/bindings/python-ctypes/override.py
+++ b/bindings/python-ctypes/override.py
@@ -210,11 +210,14 @@ class LogIterator:
     def next(self):
         if not self.has_next():
             raise StopIteration
-        buffer=LogMessage()
+        buf=LogMessage()
         e=VLCException()
-        ret=libvlc_log_iterator_next(self, buffer, e)
-        return ret
+        ret=libvlc_log_iterator_next(self, buf, e)
+        return ret.contents
 
 class Log:
     def __iter__(self):
         return self.get_iterator()
+
+    def dump(self):
+        return [ str(m) for m in self ]
diff --git a/bindings/python-ctypes/test.py b/bindings/python-ctypes/test.py
index 97899fa..02622f3 100755
--- a/bindings/python-ctypes/test.py
+++ b/bindings/python-ctypes/test.py
@@ -107,5 +107,31 @@ class TestVLCAPI(unittest.TestCase):
         p=i.media_player_new(mrl)
         self.assertEqual(p.get_state(), vlc.State.Ended)
 
+    def test_libvlc_logger(self):
+        i=vlc.Instance()
+        l=i.log_open()
+        l.clear()
+        self.assertEqual(l.count(), 0)
+        l.close()
+
+    def test_libvlc_logger_clear(self):
+        i=vlc.Instance()
+        l=i.log_open()
+        l.clear()
+        self.assertEqual(l.count(), 0)
+        l.close()
+
+    def test_libvlc_logger(self):
+        i=vlc.Instance()
+        i.set_log_verbosity(3)
+        l=i.log_open()
+        # This should generate a log message
+        i.add_intf('dummy')
+        self.assertNotEqual(l.count(), 0)
+        for m in l:
+            # Ensure that messages can be read.
+            self.assertNotEqual(len(m.message), 0)
+        l.close()
+
 if __name__ == '__main__':
     unittest.main()




More information about the vlc-devel mailing list