From c71376ba3596b5f555964fe30e486cac3a5130b7 Mon Sep 17 00:00:00 2001 From: Filippo Carone Date: Sun, 6 Apr 2008 20:37:45 +0200 Subject: [PATCH] jvlc logging classes added --- .../src/main/java/org/videolan/jvlc/JVLC.java | 19 ++++ .../main/java/org/videolan/jvlc/Logger.java | 79 ++++++++++++++ .../org/videolan/jvlc/LoggerIterator.java | 97 +++++++++++++++++ .../java/org/videolan/jvlc/LoggerMessage.java | 103 ++++++++++++++++++ .../videolan/jvlc/LoggerVerbosityLevel.java | 37 +++++++ .../java/org/videolan/jvlc/LoggerTest.java | 80 ++++++++++++++ 6 files changed, 415 insertions(+) create mode 100644 bindings/java/core/src/main/java/org/videolan/jvlc/Logger.java create mode 100644 bindings/java/core/src/main/java/org/videolan/jvlc/LoggerIterator.java create mode 100644 bindings/java/core/src/main/java/org/videolan/jvlc/LoggerMessage.java create mode 100644 bindings/java/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java create mode 100644 bindings/java/core/src/test/java/org/videolan/jvlc/LoggerTest.java diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java b/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java index 5d4d9c7453..e6c5be6640 100644 --- a/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java @@ -89,6 +89,25 @@ public class JVLC return libvlc.libvlc_new(args.length, args, exception); } + public Logger getLogger() + { + return new Logger(this); + } + + public LoggerVerbosityLevel getLogVerbosity() + { + libvlc_exception_t exception = new libvlc_exception_t(); + int level = libvlc.libvlc_get_log_verbosity(instance, exception); + return LoggerVerbosityLevel.getSeverity(level); + } + + public void setLogVerbosity(LoggerVerbosityLevel level) + { + libvlc_exception_t exception = new libvlc_exception_t(); + libvlc.libvlc_set_log_verbosity(instance, level.ordinal(), exception); + } + + /** * Returns the _instance. * @return the _instance diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/Logger.java b/bindings/java/core/src/main/java/org/videolan/jvlc/Logger.java new file mode 100644 index 0000000000..0acd44ced5 --- /dev/null +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/Logger.java @@ -0,0 +1,79 @@ +/***************************************************************************** + * Logger.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc; + +import java.util.Iterator; + +import org.videolan.jvlc.internal.LibVlc; +import org.videolan.jvlc.internal.LibVlc.LibVlcLog; +import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; + + +public class Logger +{ + LibVlcLog logInstance; + LibVlc libvlc; + + + /** + * @param jvlc The current jvlc instance + */ + public Logger(JVLC jvlc) + { + this.libvlc = jvlc.getLibvlc(); + libvlc_exception_t exception = new libvlc_exception_t(); + this.logInstance = jvlc.getLibvlc().libvlc_log_open(jvlc.getInstance(), exception); + if (exception.raised == 1) + { + throw new RuntimeException("Native exception thrown: " + exception.message); + } + } + + public void clear() + { + libvlc_exception_t exception = new libvlc_exception_t(); + libvlc.libvlc_log_clear(logInstance, exception); + } + + public void close() + { + libvlc_exception_t exception = new libvlc_exception_t(); + libvlc.libvlc_log_close(logInstance, exception); + } + + public int count() + { + libvlc_exception_t exception = new libvlc_exception_t(); + return libvlc.libvlc_log_count(logInstance, exception); + } + + public Iterator iterator() + { + return new LoggerIterator(this); + } + + +} diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerIterator.java b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerIterator.java new file mode 100644 index 0000000000..dedd22ed4b --- /dev/null +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerIterator.java @@ -0,0 +1,97 @@ +/***************************************************************************** + * LoggerIterator.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc; + +import java.util.Iterator; + +import org.videolan.jvlc.internal.LibVlc.LibVlcLogIterator; +import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; +import org.videolan.jvlc.internal.LibVlc.libvlc_log_message_t; + + +public class LoggerIterator implements Iterator +{ + + private Logger logger; + private LibVlcLogIterator logIterator; + + /** + * @param logInstance + */ + LoggerIterator(Logger logger) + { + this.logger = logger; + libvlc_exception_t exception = new libvlc_exception_t(); + this.logIterator = logger.libvlc.libvlc_log_get_iterator(logger.logInstance, exception); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() + { + libvlc_exception_t exception = new libvlc_exception_t(); + return logger.libvlc.libvlc_log_iterator_has_next(logIterator, exception) != 0; + } + + /** + * {@inheritDoc} + */ + @Override + public LoggerMessage next() + { + libvlc_exception_t exception = new libvlc_exception_t(); + libvlc_log_message_t message = new libvlc_log_message_t(); + logger.libvlc.libvlc_log_iterator_next(logIterator, message, exception); + LoggerMessage result = new LoggerMessage(message); + return result; + } + + /** + * {@inheritDoc} + * Does not remove the element. + */ + @Override + public void remove() + { + // + } + + /** + * {@inheritDoc} + */ + @Override + protected void finalize() throws Throwable + { + libvlc_exception_t exception = new libvlc_exception_t(); + logger.libvlc.libvlc_log_iterator_free(logIterator, exception); + super.finalize(); + } + + + +} diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerMessage.java b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerMessage.java new file mode 100644 index 0000000000..e55c69dc3e --- /dev/null +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerMessage.java @@ -0,0 +1,103 @@ +/***************************************************************************** + * LoggerMessage.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc; + +import org.videolan.jvlc.internal.LibVlc.libvlc_log_message_t; + + +public class LoggerMessage +{ + + private LoggerVerbosityLevel severity; + private String header; + private String message; + private String name; + private String type; + + /** + * @param message + */ + LoggerMessage(libvlc_log_message_t message) + { + this.severity = LoggerVerbosityLevel.getSeverity(message.i_severity); + this.header = message.psz_header; + this.message = message.psz_message; + this.name = message.psz_name; + this.type = message.psz_type; + } + + + /** + * Returns the header. + * @return the header + */ + public String getHeader() + { + return header; + } + + + /** + * Returns the message. + * @return the message + */ + public String getMessage() + { + return message; + } + + + /** + * Returns the name. + * @return the name + */ + public String getName() + { + return name; + } + + + /** + * Returns the type. + * @return the type + */ + public String getType() + { + return type; + } + + + + /** + * Returns the severity. + * @return the severity + */ + public LoggerVerbosityLevel getSeverity() + { + return severity; + } + +} diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java new file mode 100644 index 0000000000..2fa9f0bf08 --- /dev/null +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java @@ -0,0 +1,37 @@ +/***************************************************************************** + * LoggerSeverityEnum.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc; + +public enum LoggerVerbosityLevel { + + INFO, ERROR, WARNING, DEBUG; + + public static LoggerVerbosityLevel getSeverity(int ordinal) + { + return new LoggerVerbosityLevel[]{INFO, ERROR, WARNING, DEBUG }[ordinal]; + } + +} diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/LoggerTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/LoggerTest.java new file mode 100644 index 0000000000..113eb15271 --- /dev/null +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/LoggerTest.java @@ -0,0 +1,80 @@ +/***************************************************************************** + * LoggerTest.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $Id $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +package org.videolan.jvlc; + +import java.util.Iterator; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + + +public class LoggerTest +{ + + private JVLC jvlc; + + private String mrl = getClass().getResource("/raffa_voice.ogg").getFile(); + + @Before + public void setup() + { + jvlc = new JVLC("-I dummy --aout=dummy --vout=dummy"); + } + + @Test + public void testLogDebug() + { + jvlc.setLogVerbosity(LoggerVerbosityLevel.DEBUG); + Logger logger = jvlc.getLogger(); + jvlc.play(mrl); + Assert.assertTrue(logger.count() > 0); + } + + /** + * + */ + @Test + public void testLogError() + { + jvlc.setLogVerbosity(LoggerVerbosityLevel.DEBUG); + Logger logger = jvlc.getLogger(); + logger.clear(); + Assert.assertEquals(0, logger.count()); + + jvlc.play(mrl); + + Iterator loggerIterator = logger.iterator(); + while (loggerIterator.hasNext()) + { + LoggerMessage message = loggerIterator.next(); + Assert.assertNotNull(message.getMessage()); + } + + } + +} -- 2.39.2