Commit c71376ba authored by Filippo Carone's avatar Filippo Carone

jvlc logging classes added

parent 81a45bed
......@@ -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
......
/*****************************************************************************
* 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);
}
}
/*****************************************************************************
* 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();
}
}
/*****************************************************************************
* 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;
}
}
/*****************************************************************************
* 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];
}
}
/*****************************************************************************
* 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());
}
}
}
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