fixed file logging

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@624 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
kascade 2007-04-18 11:22:08 +00:00
parent ab9a96a9b1
commit 02f57666bc
9 changed files with 76 additions and 34 deletions

View File

@ -50,6 +50,8 @@ import enginuity.logger.ecu.ui.StatusIndicator;
import enginuity.logger.ecu.ui.handler.DataUpdateHandlerManager;
import enginuity.logger.ecu.ui.handler.DataUpdateHandlerManagerImpl;
import enginuity.logger.ecu.ui.handler.dash.DashboardUpdateHandler;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchHandler;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitorImpl;
import enginuity.logger.ecu.ui.handler.file.FileUpdateHandlerImpl;
import enginuity.logger.ecu.ui.handler.graph.GraphUpdateHandler;
import enginuity.logger.ecu.ui.handler.livedata.LiveDataTableModel;
@ -300,24 +302,19 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
}
private void initFileLoggingController(final EcuSwitch fileLoggingControllerSwitch) {
// add logger and setup callback
controller.setFileLoggerSwitch(fileLoggingControllerSwitch);
//FIXME: Add auto button toggle on defog switch back in somehow! Use a FileLoggingUpdateHandler or something
// controller.setFileLoggerSwitch(fileLoggingControllerSwitch, new LoggerCallback() {
// public void callback(double value) {
// // update handlers
// if (settings.isFileLoggingControllerSwitchActive()) {
// boolean logToFile = (int) value == 1;
// logToFileButton.setSelected(logToFile);
// if (logToFile) {
// fileUpdateHandler.start();
// } else {
// fileUpdateHandler.stop();
// }
// }
// }
// });
controller.setFileLoggerSwitchMonitor(new FileLoggerControllerSwitchMonitorImpl(fileLoggingControllerSwitch, new FileLoggerControllerSwitchHandler() {
public void handleSwitch(double switchValue) {
if (settings.isFileLoggingControllerSwitchActive()) {
boolean logToFile = (int) switchValue == 1;
logToFileButton.setSelected(logToFile);
if (logToFile) {
fileUpdateHandler.start();
} else {
fileUpdateHandler.stop();
}
}
}
}));
}
private void applyUserProfile(UserProfile profile) {

View File

@ -21,13 +21,13 @@
package enginuity.logger.ecu.comms.controller;
import enginuity.logger.ecu.definition.EcuSwitch;
import enginuity.logger.ecu.definition.LoggerData;
import enginuity.logger.ecu.ui.StatusChangeListener;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitor;
public interface LoggerController {
void setFileLoggerSwitch(EcuSwitch ecuSwitch);
void setFileLoggerSwitchMonitor(FileLoggerControllerSwitchMonitor monitor);
void addLogger(String callerId, LoggerData loggerData);

View File

@ -25,11 +25,11 @@ import enginuity.Settings;
import enginuity.logger.ecu.comms.manager.QueryManager;
import enginuity.logger.ecu.comms.manager.QueryManagerImpl;
import enginuity.logger.ecu.comms.query.EcuInitCallback;
import enginuity.logger.ecu.definition.EcuSwitch;
import enginuity.logger.ecu.definition.LoggerData;
import enginuity.logger.ecu.ui.MessageListener;
import enginuity.logger.ecu.ui.StatusChangeListener;
import enginuity.logger.ecu.ui.handler.DataUpdateHandler;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitor;
import static enginuity.util.ParamChecker.checkNotNull;
public final class LoggerControllerImpl implements LoggerController {
@ -46,10 +46,10 @@ public final class LoggerControllerImpl implements LoggerController {
queryManager.addListener(listener);
}
public void setFileLoggerSwitch(EcuSwitch ecuSwitch) {
checkNotNull(ecuSwitch);
System.out.println("Setting file logger switch: " + ecuSwitch.getName());
queryManager.setFileLoggerQuery(ecuSwitch);
public void setFileLoggerSwitchMonitor(FileLoggerControllerSwitchMonitor monitor) {
checkNotNull(monitor);
System.out.println("Setting file logger switch monitor: " + monitor.getEcuSwitch().getName());
queryManager.setFileLoggerSwitchMonitor(monitor);
}
public void addLogger(String callerId, LoggerData loggerData) {

View File

@ -21,13 +21,13 @@
package enginuity.logger.ecu.comms.manager;
import enginuity.logger.ecu.definition.EcuSwitch;
import enginuity.logger.ecu.definition.LoggerData;
import enginuity.logger.ecu.ui.StatusChangeListener;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitor;
public interface QueryManager extends Runnable {
void setFileLoggerQuery(EcuSwitch ecuSwitch);
void setFileLoggerSwitchMonitor(FileLoggerControllerSwitchMonitor monitor);
void addQuery(String callerId, LoggerData loggerData);

View File

@ -36,12 +36,12 @@ import enginuity.logger.ecu.comms.query.Response;
import enginuity.logger.ecu.comms.query.ResponseImpl;
import enginuity.logger.ecu.definition.EcuData;
import static enginuity.logger.ecu.definition.EcuDataType.EXTERNAL;
import enginuity.logger.ecu.definition.EcuSwitch;
import enginuity.logger.ecu.definition.ExternalData;
import enginuity.logger.ecu.definition.LoggerData;
import enginuity.logger.ecu.ui.MessageListener;
import enginuity.logger.ecu.ui.StatusChangeListener;
import enginuity.logger.ecu.ui.handler.DataUpdateHandler;
import enginuity.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitor;
import static enginuity.util.HexUtil.asHex;
import static enginuity.util.ParamChecker.checkNotNull;
import static enginuity.util.ThreadUtil.runAsDaemon;
@ -67,6 +67,7 @@ public final class QueryManagerImpl implements QueryManager {
private final EcuInitCallback ecuInitCallback;
private final MessageListener messageListener;
private final DataUpdateHandler[] dataUpdateHandlers;
private FileLoggerControllerSwitchMonitor monitor;
private EcuQuery fileLoggerQuery;
private Thread queryManagerThread;
private boolean started;
@ -86,9 +87,10 @@ public final class QueryManagerImpl implements QueryManager {
listeners.add(listener);
}
public void setFileLoggerQuery(EcuSwitch ecuSwitch) {
checkNotNull(ecuSwitch);
fileLoggerQuery = new EcuQueryImpl(ecuSwitch);
public void setFileLoggerSwitchMonitor(FileLoggerControllerSwitchMonitor monitor) {
checkNotNull(monitor);
this.monitor = monitor;
fileLoggerQuery = new EcuQueryImpl(monitor.getEcuSwitch());
}
public synchronized void addQuery(String callerId, LoggerData loggerData) {
@ -191,7 +193,7 @@ public final class QueryManagerImpl implements QueryManager {
private void sendEcuQueries(TransmissionManager txManager) {
List<EcuQuery> ecuQueries = filterEcuQueries(queryMap.values());
if (fileLoggerQuery != null && !ecuQueries.contains(fileLoggerQuery)) {
if (fileLoggerQuery != null) {
ecuQueries.add(fileLoggerQuery);
}
txManager.sendQueries(ecuQueries);
@ -206,10 +208,12 @@ public final class QueryManagerImpl implements QueryManager {
}
private void handleQueryResponse() {
monitor.monitorFileLoggerSwitch(fileLoggerQuery.getResponse());
final Response response = buildResponse(queryMap.values());
for (final DataUpdateHandler dataUpdateHandler : dataUpdateHandlers) {
runAsDaemon(new Runnable() {
public void run() {
dataUpdateHandler.handleDataUpdate(buildResponse(queryMap.values()));
dataUpdateHandler.handleDataUpdate(response);
}
});
}

View File

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Set;
public class ResponseImpl implements Response {
private static final double ZERO = 0.0;
private final Map<LoggerData, Double> dataValues = new LinkedHashMap<LoggerData, Double>();
private final long timestamp;
@ -23,7 +24,8 @@ public class ResponseImpl implements Response {
}
public double getDataValue(LoggerData data) {
return dataValues.get(data);
Double value = dataValues.get(data);
return value == null ? ZERO : value;
}
public long getTimestamp() {

View File

@ -0,0 +1,6 @@
package enginuity.logger.ecu.ui.handler.file;
public interface FileLoggerControllerSwitchHandler {
void handleSwitch(double switchValue);
}

View File

@ -0,0 +1,10 @@
package enginuity.logger.ecu.ui.handler.file;
import enginuity.logger.ecu.definition.EcuSwitch;
public interface FileLoggerControllerSwitchMonitor {
void monitorFileLoggerSwitch(double switchValue);
EcuSwitch getEcuSwitch();
}

View File

@ -0,0 +1,23 @@
package enginuity.logger.ecu.ui.handler.file;
import enginuity.logger.ecu.definition.EcuSwitch;
import static enginuity.util.ParamChecker.checkNotNull;
public final class FileLoggerControllerSwitchMonitorImpl implements FileLoggerControllerSwitchMonitor {
private final EcuSwitch fileLoggingSwitch;
private final FileLoggerControllerSwitchHandler handler;
public FileLoggerControllerSwitchMonitorImpl(EcuSwitch fileLoggingSwitch, FileLoggerControllerSwitchHandler handler) {
checkNotNull(fileLoggingSwitch, handler);
this.fileLoggingSwitch = fileLoggingSwitch;
this.handler = handler;
}
public void monitorFileLoggerSwitch(double switchValue) {
handler.handleSwitch(switchValue);
}
public EcuSwitch getEcuSwitch() {
return fileLoggingSwitch;
}
}