Added passing the contents of the Plugins properties file into the datasource

class.  This can be used to within the plugin to affect its behaviour if
code is added to read the passed properties.  These would be properties
not available in the Plugins dialog settings.
This commit is contained in:
Dale Schultz 2015-02-12 23:20:12 -05:00
parent a02a0b7496
commit 798598f807
16 changed files with 88 additions and 37 deletions

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -31,6 +31,7 @@ import static com.romraider.util.ThreadUtil.runAsDaemon;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
@ -72,6 +73,9 @@ public final class AemDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new AemRunner(port, dataItem);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.Action;
@ -87,6 +88,9 @@ public final class AemDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new AemRunner(port, dataItems);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -31,6 +31,7 @@ import static com.romraider.util.ThreadUtil.runAsDaemon;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
@ -72,6 +73,9 @@ public final class AemDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new AemRunner(port, dataItem);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -22,6 +22,7 @@ package com.romraider.logger.external.core;
import com.romraider.logger.ecu.EcuLogger;
import javax.swing.Action;
import java.util.List;
import java.util.Properties;
public interface ExternalDataSource {
String getId();
@ -38,6 +39,8 @@ public interface ExternalDataSource {
String getPort();
void setProperties(Properties properties);
public void connect();
public void disconnect();

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -38,7 +38,6 @@ public final class ExternalDataSourceLoaderImpl implements ExternalDataSourceLoa
try {
File pluginsDir = new File("./plugins");
if (pluginsDir.exists() && pluginsDir.isDirectory()) {
// externalDataSources = new ArrayList<ExternalDataSource>();
File[] pluginPropertyFiles = pluginsDir.listFiles(new PluginFilenameFilter());
for (File pluginPropertyFile : pluginPropertyFiles) {
Properties pluginProps = new Properties();
@ -50,7 +49,7 @@ public final class ExternalDataSourceLoaderImpl implements ExternalDataSourceLoa
try {
Class<?> dataSourceClass = getClass().getClassLoader().loadClass(datasourceClassName);
if (dataSourceClass != null && ExternalDataSource.class.isAssignableFrom(dataSourceClass)) {
ExternalDataSource dataSource = dataSource(dataSourceClass, loggerPluginPorts);
ExternalDataSource dataSource = dataSource(dataSourceClass, loggerPluginPorts, pluginProps);
ExternalDataSource managedDataSource = new GenericDataSourceManager(dataSource);
externalDataSources.add(managedDataSource);
LOGGER.info("Plugin loaded: " + dataSource.getName() + " v" + dataSource.getVersion());
@ -70,12 +69,17 @@ public final class ExternalDataSourceLoaderImpl implements ExternalDataSourceLoa
}
}
private ExternalDataSource dataSource(Class<?> dataSourceClass, Map<String, String> loggerPluginPorts) throws Exception {
private ExternalDataSource dataSource(
Class<?> dataSourceClass,
Map<String, String> loggerPluginPorts,
Properties pluginProps) throws Exception {
ExternalDataSource dataSource = (ExternalDataSource) dataSourceClass.newInstance();
if (loggerPluginPorts != null) {
String port = loggerPluginPorts.get(dataSource.getId());
if (port != null && port.trim().length() > 0) dataSource.setPort(port);
}
dataSource.setProperties(pluginProps);
return dataSource;
}

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -28,6 +28,7 @@ import static org.apache.log4j.Logger.getLogger;
import javax.swing.Action;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public final class GenericDataSourceManager implements ExternalDataSource {
private static final Logger LOGGER = getLogger(GenericDataSourceManager.class);
@ -73,6 +74,9 @@ public final class GenericDataSourceManager implements ExternalDataSource {
return dataSource.getPort();
}
public void setProperties(Properties properties) {
}
public synchronized void connect() {
if (connectCount++ == 0) doConnect();
LOGGER.trace("Connect count [" + dataSource.getName() + "]: " + connectCount);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -31,6 +31,7 @@ import static com.romraider.util.ThreadUtil.runAsDaemon;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
@ -72,6 +73,9 @@ public final class NawDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new NawRunner(port, dataItem);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -31,6 +31,7 @@ import static com.romraider.util.ThreadUtil.runAsDaemon;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
@ -72,6 +73,9 @@ public final class InnovateDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new InnovateRunner(port, dataItem);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2014 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
//import java.util.Set;
import javax.swing.Action;
@ -47,6 +48,7 @@ public final class Lm2MtsDataSource implements ExternalDataSource {
private Map<Integer, Lm2MtsDataItem> dataItems = new HashMap<Integer, Lm2MtsDataItem>();
private MTSRunner runner;
private int mtsPort = -1;
private boolean pollMode;
/**
* The Lm2MtsDataSource class is called when the Logger starts up and the
@ -62,23 +64,7 @@ public final class Lm2MtsDataSource implements ExternalDataSource {
if (ports != null) {
for (int i = 0; i < ports.length; i++) {
connector.usePort(i);
// Set<MTSSensor> sensors = connector.getSensors();
dataItems = connector.getSensors();
// if (sensors.isEmpty())
// continue;
// dataItems.put(0, new Lm2MtsDataItem("LM-2", 0, "AFR", 9, 20, 14.7f)); // a default entry
// for (MTSSensor sensor : sensors) {
// dataItems.put(
// sensor.getInputNumber(),
// new Lm2MtsDataItem(
// sensor.getDeviceName(),
// sensor.getDeviceChannel(),
// sensor.getUnits(),
// sensor.getMinValue(),
// sensor.getMaxValue(),
// sensor.getMultiplier()
// ));
// }
}
}
else {
@ -96,7 +82,7 @@ public final class Lm2MtsDataSource implements ExternalDataSource {
}
public String getVersion() {
return "0.05";
return "0.06";
}
public List<? extends ExternalDataItem> getDataItems() {
@ -115,8 +101,13 @@ public final class Lm2MtsDataSource implements ExternalDataSource {
return "" + mtsPort;
}
public void setProperties(Properties properties) {
final String pollMode = properties.getProperty("datasource.pollmode");
this.pollMode = Boolean.parseBoolean(pollMode);
}
public void connect() {
runner = new MTSRunner(mtsPort, dataItems);
runner = new MTSRunner(mtsPort, dataItems, pollMode);
runAsDaemon(runner);
}

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -56,6 +56,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.Action;
@ -107,6 +108,9 @@ public final class MrfDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new MrfRunner(port, dataItems);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2013 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.swing.Action;
@ -94,6 +95,9 @@ public final class IntfKitDataSource implements ExternalDataSource {
return new IntfKitPluginMenuAction(logger);
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new IntfKitRunner(kits, dataItems);
ThreadUtil.runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2014 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -92,6 +92,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.Action;
@ -159,6 +160,9 @@ public final class PlxDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new PlxRunner(port, dataItems);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.Action;
@ -101,6 +102,9 @@ public final class TEDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new TERunner(port, dataItems);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -34,6 +34,8 @@ import static java.util.Collections.unmodifiableList;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
import com.romraider.logger.ecu.EcuLogger;
@ -91,6 +93,9 @@ public class TxsTunerDataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new TxsRunner(port, dataItems, LOGGER, DEVICE);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -42,6 +42,7 @@ import static java.util.Collections.unmodifiableList;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.swing.Action;
@ -115,6 +116,9 @@ public class TxsUtecLogger1DataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new TxsRunner(port, dataItems, LOGGER, DEVICE);
runAsDaemon(runner);

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2015 RomRaider.com
*
* 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
@ -49,6 +49,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.Action;
@ -100,6 +101,9 @@ public final class ZT2DataSource implements ExternalDataSource {
return port;
}
public void setProperties(Properties properties) {
}
public void connect() {
runner = new ZT2Runner(port, dataItems);
runAsDaemon(runner);