- plugin functionality added
- Logging adapted to use the .configure property file git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@178 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="test"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="con" path="SWT_CONTAINER/PLATFORM"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
6
java/.configure
Normal file
6
java/.configure
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# enable or disable logging
|
||||||
|
ch.ntb.usb/debug = true
|
||||||
|
# set and configure individual loggers here
|
||||||
|
# the format is: projectName/debug/<loggerX> = <logger name>/<log level>
|
||||||
|
ch.ntb.usb/debug/logger0 = ch.ntb.usb/OFF
|
||||||
|
ch.ntb.usb/debug/logger1 = ch.ntb.usb.test/INFO
|
||||||
@@ -10,10 +10,21 @@
|
|||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
|
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
|
||||||
|
<nature>org.eclipse.pde.PluginNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
#Wed Oct 26 15:55:07 CEST 2005
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.5
|
|
||||||
13
java/META-INF/MANIFEST.MF
Normal file
13
java/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Bundle-ManifestVersion: 2
|
||||||
|
Bundle-Name: Inf USB Library
|
||||||
|
Bundle-SymbolicName: ch.ntb.usb
|
||||||
|
Bundle-Version: 1.0.0
|
||||||
|
Bundle-Localization: plugin
|
||||||
|
Bundle-Vendor: inf.ntb.ch
|
||||||
|
Eclipse-LazyStart: false
|
||||||
|
Require-Bundle: org.junit4,
|
||||||
|
org.eclipse.swt
|
||||||
|
Export-Package: ch.ntb.usb,
|
||||||
|
ch.ntb.usb.testApp,
|
||||||
|
ch.ntb.usb.usbView
|
||||||
4
java/build.properties
Normal file
4
java/build.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
source.. = src/,\
|
||||||
|
test/
|
||||||
|
bin.includes = META-INF/,\
|
||||||
|
.
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package ch.ntb.usb;
|
package ch.ntb.usb;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import ch.ntb.usb.logger.LogUtil;
|
import ch.ntb.usb.logger.LogUtil;
|
||||||
import ch.ntb.usb.logger.UsbLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents an USB device.<br>
|
* This class represents an USB device.<br>
|
||||||
@@ -14,7 +14,7 @@ import ch.ntb.usb.logger.UsbLogger;
|
|||||||
*/
|
*/
|
||||||
public class Device {
|
public class Device {
|
||||||
|
|
||||||
private static UsbLogger logger = LogUtil.ch_ntb_usb;
|
private static Logger logger = LogUtil.getLogger("ch.ntb.usb");
|
||||||
|
|
||||||
private static final int TIMEOUT_ERROR_CODE = -116;
|
private static final int TIMEOUT_ERROR_CODE = -116;
|
||||||
|
|
||||||
@@ -224,7 +224,8 @@ public class Device {
|
|||||||
+ LibusbWin.usb_strerror());
|
+ LibusbWin.usb_strerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.getLevel().intValue() <= Level.INFO.intValue()) {
|
logger.info("length written: " + lenWritten);
|
||||||
|
if (logger.getLevel().intValue() <= Level.FINEST.intValue()) {
|
||||||
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
||||||
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
||||||
+ " Bytes sent: ");
|
+ " Bytes sent: ");
|
||||||
@@ -283,7 +284,8 @@ public class Device {
|
|||||||
+ LibusbWin.usb_strerror());
|
+ LibusbWin.usb_strerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.getLevel().intValue() <= Level.INFO.intValue()) {
|
logger.info("length read: " + lenRead);
|
||||||
|
if (logger.getLevel().intValue() <= Level.FINEST.intValue()) {
|
||||||
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
||||||
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
||||||
+ " Bytes received: ");
|
+ " Bytes received: ");
|
||||||
@@ -343,7 +345,8 @@ public class Device {
|
|||||||
+ LibusbWin.usb_strerror());
|
+ LibusbWin.usb_strerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.getLevel().intValue() <= Level.INFO.intValue()) {
|
logger.info("length written: " + lenWritten);
|
||||||
|
if (logger.getLevel().intValue() <= Level.FINEST.intValue()) {
|
||||||
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
||||||
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
||||||
+ " Bytes sent: ");
|
+ " Bytes sent: ");
|
||||||
@@ -403,7 +406,8 @@ public class Device {
|
|||||||
+ LibusbWin.usb_strerror());
|
+ LibusbWin.usb_strerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.getLevel().intValue() <= Level.INFO.intValue()) {
|
logger.info("length read: " + lenRead);
|
||||||
|
if (logger.getLevel().intValue() <= Level.FINEST.intValue()) {
|
||||||
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
||||||
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
||||||
+ " Bytes received: ");
|
+ " Bytes received: ");
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package ch.ntb.usb;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import ch.ntb.usb.logger.LogUtil;
|
import ch.ntb.usb.logger.LogUtil;
|
||||||
import ch.ntb.usb.logger.UsbLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages all USB devices and defines some USB specific constants.<br>
|
* This class manages all USB devices and defines some USB specific constants.<br>
|
||||||
@@ -26,7 +26,7 @@ public class USB {
|
|||||||
*/
|
*/
|
||||||
public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64;
|
public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64;
|
||||||
|
|
||||||
private static UsbLogger logger = LogUtil.ch_ntb_usb;
|
private static Logger logger = LogUtil.getLogger("ch.ntb.usb");
|
||||||
|
|
||||||
private static LinkedList<Device> devices = new LinkedList<Device>();
|
private static LinkedList<Device> devices = new LinkedList<Device>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package ch.ntb.usb.logger;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class LogLevel extends Level {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8918592094095458645L;
|
|
||||||
|
|
||||||
public static final Level DEBUG = new LogLevel("DEBUG", 750);
|
|
||||||
|
|
||||||
protected LogLevel(String name, int value) {
|
|
||||||
super(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,25 @@
|
|||||||
package ch.ntb.usb.logger;
|
package ch.ntb.usb.logger;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.ConsoleHandler;
|
import java.util.logging.ConsoleHandler;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogManager;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class LogUtil {
|
public class LogUtil {
|
||||||
|
|
||||||
public static UsbLogger ch_ntb_usb, ch_ntb_usb_test;
|
private static final String PLUGIN_ID = "ch.ntb.usb";
|
||||||
|
private static final String PROPERTIES_FILE = ".configure";
|
||||||
|
|
||||||
|
private static boolean debugEnabled;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// set all loglevels here
|
createLoggersFromProperties();
|
||||||
ch_ntb_usb = getLogger("ch.ntb.usb", Level.OFF);
|
|
||||||
ch_ntb_usb_test = getLogger("ch.ntb.usb.test", Level.ALL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLevel(UsbLogger logger, Level loglevel) {
|
public static void setLevel(Logger logger, Level loglevel) {
|
||||||
Handler[] h = logger.getHandlers();
|
Handler[] h = logger.getHandlers();
|
||||||
for (int i = 0; i < h.length; i++) {
|
for (int i = 0; i < h.length; i++) {
|
||||||
h[i].setLevel(loglevel);
|
h[i].setLevel(loglevel);
|
||||||
@@ -22,7 +27,19 @@ public class LogUtil {
|
|||||||
logger.setLevel(loglevel);
|
logger.setLevel(loglevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initLevel(UsbLogger logger, Level loglevel) {
|
public static Logger getLogger(String name) {
|
||||||
|
LogManager manager = LogManager.getLogManager();
|
||||||
|
// check if logger is already registered
|
||||||
|
Logger logger = manager.getLogger(name);
|
||||||
|
if (logger == null) {
|
||||||
|
logger = Logger.getLogger(name);
|
||||||
|
manager.addLogger(logger);
|
||||||
|
}
|
||||||
|
logger.setLevel(null);
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initLevel(Logger logger, Level loglevel) {
|
||||||
Handler[] h = logger.getHandlers();
|
Handler[] h = logger.getHandlers();
|
||||||
for (int i = 0; i < h.length; i++) {
|
for (int i = 0; i < h.length; i++) {
|
||||||
logger.removeHandler(h[i]);
|
logger.removeHandler(h[i]);
|
||||||
@@ -34,9 +51,43 @@ public class LogUtil {
|
|||||||
logger.setUseParentHandlers(false);
|
logger.setUseParentHandlers(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UsbLogger getLogger(String name, Level loglevel) {
|
private static void createLoggersFromProperties() {
|
||||||
UsbLogger logger = UsbLogger.getLogger(name);
|
try {
|
||||||
initLevel(logger, loglevel);
|
FileInputStream fis = new FileInputStream(PROPERTIES_FILE);
|
||||||
return logger;
|
Properties prop = new Properties();
|
||||||
|
prop.load(fis);
|
||||||
|
// get global debug enable flag
|
||||||
|
debugEnabled = Boolean.parseBoolean(prop.getProperty(PLUGIN_ID
|
||||||
|
+ "/debug"));
|
||||||
|
// get and configure loggers
|
||||||
|
boolean moreLoggers = true;
|
||||||
|
int loggerCount = 0;
|
||||||
|
while (moreLoggers) {
|
||||||
|
String loggerProp = prop.getProperty(PLUGIN_ID
|
||||||
|
+ "/debug/logger" + loggerCount);
|
||||||
|
loggerCount++;
|
||||||
|
if (loggerProp != null) {
|
||||||
|
// parse string and get logger name and log level
|
||||||
|
int slashIndex = loggerProp.indexOf('/');
|
||||||
|
String loggerName = loggerProp.substring(0, slashIndex)
|
||||||
|
.trim();
|
||||||
|
String logLevel = loggerProp.substring(slashIndex + 1,
|
||||||
|
loggerProp.length());
|
||||||
|
// register logger
|
||||||
|
Level level;
|
||||||
|
if (debugEnabled) {
|
||||||
|
level = Level.parse(logLevel);
|
||||||
|
} else {
|
||||||
|
level = Level.OFF;
|
||||||
|
}
|
||||||
|
Logger logger = getLogger(loggerName);
|
||||||
|
initLevel(logger, level);
|
||||||
|
} else {
|
||||||
|
moreLoggers = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package ch.ntb.usb.logger;
|
|
||||||
|
|
||||||
import java.util.logging.LogManager;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class UsbLogger extends Logger {
|
|
||||||
|
|
||||||
protected UsbLogger(String name, String resourceBundleName) {
|
|
||||||
super(name, resourceBundleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void debug(String msg) {
|
|
||||||
log(LogLevel.DEBUG, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized UsbLogger getLogger(String name) {
|
|
||||||
LogManager manager = LogManager.getLogManager();
|
|
||||||
UsbLogger result = (UsbLogger) manager.getLogger(name);
|
|
||||||
if (result == null) {
|
|
||||||
result = new UsbLogger(name, null);
|
|
||||||
manager.addLogger(result);
|
|
||||||
result = (UsbLogger) manager.getLogger(name);
|
|
||||||
}
|
|
||||||
result.setLevel(null);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import ch.ntb.usb.logger.LogUtil;
|
|||||||
|
|
||||||
public class TestImplementation {
|
public class TestImplementation {
|
||||||
|
|
||||||
private static Logger logger = LogUtil.ch_ntb_usb_test;
|
private static Logger logger = LogUtil.getLogger("ch.ntb.usb.test");
|
||||||
|
|
||||||
public static String sendData = "0x5b 0x02 0x01 0x00 0x03 0x03 0xf0 0xf0 0x1f";
|
public static String sendData = "0x5b 0x02 0x01 0x00 0x03 0x03 0xf0 0xf0 0x1f";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user