jvlc logging classes added
authorFilippo Carone <littlejohn@videolan.org>
Sun, 6 Apr 2008 18:37:45 +0000 (20:37 +0200)
committerFilippo Carone <littlejohn@videolan.org>
Sun, 6 Apr 2008 18:38:09 +0000 (20:38 +0200)
core/src/main/java/org/videolan/jvlc/JVLC.java
core/src/main/java/org/videolan/jvlc/Logger.java [new file with mode: 0644]
core/src/main/java/org/videolan/jvlc/LoggerIterator.java [new file with mode: 0644]
core/src/main/java/org/videolan/jvlc/LoggerMessage.java [new file with mode: 0644]
core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java [new file with mode: 0644]
core/src/test/java/org/videolan/jvlc/LoggerTest.java [new file with mode: 0644]

index 5d4d9c7..e6c5be6 100644 (file)
@@ -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/core/src/main/java/org/videolan/jvlc/Logger.java b/core/src/main/java/org/videolan/jvlc/Logger.java
new file mode 100644 (file)
index 0000000..0acd44c
--- /dev/null
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Logger.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $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<LoggerMessage> iterator()
+    {
+        return new LoggerIterator(this);
+    }
+
+    
+}
diff --git a/core/src/main/java/org/videolan/jvlc/LoggerIterator.java b/core/src/main/java/org/videolan/jvlc/LoggerIterator.java
new file mode 100644 (file)
index 0000000..dedd22e
--- /dev/null
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * LoggerIterator.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $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<LoggerMessage>
+{
+
+    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/core/src/main/java/org/videolan/jvlc/LoggerMessage.java b/core/src/main/java/org/videolan/jvlc/LoggerMessage.java
new file mode 100644 (file)
index 0000000..e55c69d
--- /dev/null
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * LoggerMessage.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $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/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java b/core/src/main/java/org/videolan/jvlc/LoggerVerbosityLevel.java
new file mode 100644 (file)
index 0000000..2fa9f0b
--- /dev/null
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * LoggerSeverityEnum.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $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/core/src/test/java/org/videolan/jvlc/LoggerTest.java b/core/src/test/java/org/videolan/jvlc/LoggerTest.java
new file mode 100644 (file)
index 0000000..113eb15
--- /dev/null
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * LoggerTest.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $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<LoggerMessage> loggerIterator = logger.iterator();
+        while (loggerIterator.hasNext())
+        {
+            LoggerMessage message = loggerIterator.next();
+            Assert.assertNotNull(message.getMessage());
+        }
+        
+    }
+    
+}