Commit d3b60bf0 authored by Olivier Aubert's avatar Olivier Aubert

python-ctypes: fix Logger bindings.

parent 5f760829
...@@ -329,7 +329,7 @@ class PythonGenerator(object): ...@@ -329,7 +329,7 @@ class PythonGenerator(object):
'libvlc_media_t*': 'Media', 'libvlc_media_t*': 'Media',
'libvlc_log_t*': 'Log', 'libvlc_log_t*': 'Log',
'libvlc_log_iterator_t*': 'LogIterator', '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_type_t': 'ctypes.c_uint',
'libvlc_event_manager_t*': 'EventManager', 'libvlc_event_manager_t*': 'EventManager',
'libvlc_media_discoverer_t*': 'MediaDiscoverer', 'libvlc_media_discoverer_t*': 'MediaDiscoverer',
...@@ -658,9 +658,15 @@ class PythonGenerator(object): ...@@ -658,9 +658,15 @@ class PythonGenerator(object):
# Check for standard methods # Check for standard methods
if name == 'count': if name == 'count':
# There is a count method. Generate a __len__ one. # 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() e=VLCException()
return %s(self, e) return %s(self, e)
""" % method)
else:
# No exception
self.output(""" def __len__(self):
return %s(self)
""" % method) """ % method)
elif name.endswith('item_at_index'): elif name.endswith('item_at_index'):
# Indexable (and thus iterable)" # Indexable (and thus iterable)"
......
...@@ -149,6 +149,9 @@ class LogMessage(ctypes.Structure): ...@@ -149,6 +149,9 @@ class LogMessage(ctypes.Structure):
('message', ctypes.c_char_p), ('message', ctypes.c_char_p),
] ]
def __init__(self):
self.size=ctypes.sizeof(self)
def __str__(self): def __str__(self):
return "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message) return "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message)
......
...@@ -210,11 +210,14 @@ class LogIterator: ...@@ -210,11 +210,14 @@ class LogIterator:
def next(self): def next(self):
if not self.has_next(): if not self.has_next():
raise StopIteration raise StopIteration
buffer=LogMessage() buf=LogMessage()
e=VLCException() e=VLCException()
ret=libvlc_log_iterator_next(self, buffer, e) ret=libvlc_log_iterator_next(self, buf, e)
return ret return ret.contents
class Log: class Log:
def __iter__(self): def __iter__(self):
return self.get_iterator() return self.get_iterator()
def dump(self):
return [ str(m) for m in self ]
...@@ -107,5 +107,31 @@ class TestVLCAPI(unittest.TestCase): ...@@ -107,5 +107,31 @@ class TestVLCAPI(unittest.TestCase):
p=i.media_player_new(mrl) p=i.media_player_new(mrl)
self.assertEqual(p.get_state(), vlc.State.Ended) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment