From 0cb32a7df3050b3fb8449610d3ca3ba0fd136bff Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Fri, 22 Jul 2022 17:12:02 +0100 Subject: [PATCH] Work on batch processing, after testing of options to autostart, autoexit and set wav file folder, database and binary store. --- src/Acquisition/FileInputSystem.java | 12 +++- src/Acquisition/FolderInputSystem.java | 6 +- src/PamController/PamController.java | 65 ++++++++++++++++++- src/PamController/PamControllerInterface.java | 12 +++- src/PamView/NullGuiController.java | 1 + src/PamView/PamGui.java | 5 +- src/PamView/PamView.java | 10 --- src/generalDatabase/sqlite/SqliteSystem.java | 3 +- src/pamViewFX/PamGuiManagerFX.java | 5 +- src/pamguard/Pamguard.java | 23 +++++-- 10 files changed, 119 insertions(+), 23 deletions(-) diff --git a/src/Acquisition/FileInputSystem.java b/src/Acquisition/FileInputSystem.java index 5fbea317..fc12d573 100644 --- a/src/Acquisition/FileInputSystem.java +++ b/src/Acquisition/FileInputSystem.java @@ -61,6 +61,7 @@ import PamView.dialog.PamLabel; import PamView.dialog.warn.WarnOnce; import PamView.panel.PamPanel; import PamView.panel.PamProgressBar; +import pamguard.GlobalArguments; import warnings.PamWarning; /** @@ -1075,8 +1076,17 @@ public class FileInputSystem extends DaqSystem implements ActionListener, PamSe @Override public void daqHasEnded() { - // TODO Auto-generated method stub + fileListComplete(); + } + /** + * Called when all files to be processed have been processed. + */ + protected void fileListComplete() { + if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) { + System.out.println("All sound files processed, PAMGuard can close on " + PamController.AUTOEXIT); + PamController.getInstance().batchProcessingComplete(); + } } JPanel statusPanel; diff --git a/src/Acquisition/FolderInputSystem.java b/src/Acquisition/FolderInputSystem.java index 227ff2d1..96bab40f 100644 --- a/src/Acquisition/FolderInputSystem.java +++ b/src/Acquisition/FolderInputSystem.java @@ -79,7 +79,7 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings{ private FolderInputParameters folderInputParameters; - public static final String GlobalWavFolderArg = "wavfilefolder"; + public static final String GlobalWavFolderArg = "-wavfilefolder"; /** @@ -652,6 +652,10 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings{ } calculateETA(); setFolderProgress(); + + if (currentFile > 0 && currentFile >= allFiles.size()) { + fileListComplete(); + } // System.out.println("FolderinputSytem: daqHasEnded"); } diff --git a/src/PamController/PamController.java b/src/PamController/PamController.java index 1f680f4d..227dbdaf 100644 --- a/src/PamController/PamController.java +++ b/src/PamController/PamController.java @@ -43,6 +43,7 @@ import Acquisition.AcquisitionProcess; import pamScrollSystem.AbstractScrollManager; import pamViewFX.PamGuiManagerFX; import pamViewFX.pamTask.PamTaskUpdate; +import pamguard.GlobalArguments; import pamguard.Pamguard; import soundPlayback.PlaybackControl; import warnings.PamWarning; @@ -51,6 +52,7 @@ import zipUnpacker.ZipUnpacker; import fftManager.FFTDataBlock; import fftManager.FFTDataUnit; import generalDatabase.DBControlUnit; +import javafx.application.Platform; import javafx.stage.Stage; import Array.ArrayManager; import PamController.command.NetworkController; @@ -128,6 +130,11 @@ public class PamController implements PamControllerInterface, PamSettings { public static final int RUN_NETWORKRECEIVER = 5; private int runMode = RUN_NORMAL; + + // flag used in main() to indicate that processing should start immediately. + public static final String AUTOSTART = "-autostart"; + // flag used in main() to indicate that pamguard should exit as soon as processing ends. + public static final String AUTOEXIT = "-autoexit"; /** * The pam model. @@ -300,10 +307,33 @@ public class PamController implements PamControllerInterface, PamSettings { public static void create(int runMode) { if (uniqueController == null) { PamController pamcontroller = new PamController(runMode, null); - // I don't see any reason not have have this running with the GUI. + /* + * I don't see any reason not have have this running with the GUI. + * It launches in a new thread, so it should be fine to have + * additional commands afterwards. + */ TerminalController tc = new TerminalController(pamcontroller); tc.getTerminalCommands(); } + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + uniqueController.creationComplete(); + } + }); + } + + /** + * Not to sound God like, but this will be called on the AWT dispatch thread shortly + * after all modules are created, PAMGuard should be fully setup and all modules will + * have recieved INITIALISATION_COMPLETE and should be good to run + */ + private void creationComplete() { + if (GlobalArguments.getParam(PamController.AUTOSTART) != null) { + startLater(); // may as well give AWT time to loop it's queue once more + } } /** @@ -526,6 +556,7 @@ public class PamController implements PamControllerInterface, PamSettings { clearSelectorsAndSymbols(); + /** * Debug code for starting PG as soon as it's initialised. */ @@ -660,11 +691,24 @@ public class PamController implements PamControllerInterface, PamSettings { @Override public void pamClose() { + getUidManager().runShutDownOps(); + for (int i = 0; i < pamControlledUnits.size(); i++) { pamControlledUnits.get(i).pamClose(); } } + /** + * Shut down Pamguard + */ + public void shutDownPamguard() { + // force close the javaFX thread (because it won't close by itself - see Platform.setImplicitExit(false) in constructor + Platform.exit(); + + // terminate the JVM + System.exit(0); + } + /** * Go through all data blocks in all modules and tell them to save. * This has been built into PamProcess and PamDataBlock since we want @@ -1297,6 +1341,25 @@ public class PamController implements PamControllerInterface, PamSettings { pamControlledUnits.get(iU).pamHasStopped(); } guiFrameManager.pamEnded(); + + // no good having this here since it get's called at the end of every file. +// if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) { +//// can exit here, since we've auto started, can auto exit. +// if (canClose()) { +// pamClose(); +// shutDownPamguard(); +// } +// } + } + + public void batchProcessingComplete( ) { + if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) { + // can exit here, since we've auto started, can auto exit. + if (canClose()) { + pamClose(); + shutDownPamguard(); + } + } } diff --git a/src/PamController/PamControllerInterface.java b/src/PamController/PamControllerInterface.java index 03abda1b..3f6dd192 100644 --- a/src/PamController/PamControllerInterface.java +++ b/src/PamController/PamControllerInterface.java @@ -307,7 +307,10 @@ public interface PamControllerInterface { public static final int REORDER_CONTROLLEDUNITS = 8; /** * Automatically sent when PAMGAURD has finished loading it's - * initial settings file and created the GUI + * initial settings file and created the GUI. It's a good time for modules + * to subscribe to their data sources, but they shouldn't do much else since + * these go around in order, so when this arrives in the first module, other + * modules may not yet be setup. */ public static final int INITIALIZATION_COMPLETE = 9; /** @@ -404,6 +407,13 @@ public interface PamControllerInterface { * The medium has been updated. */ public static final int GLOBAL_MEDIUM_UPDATE = 24; + + /** + * Sent shortly after the main PAMGUard setup has been completed, but this point + * all modules will have received INITIALIZATION_COMPLETE and should be ready to + * go. + */ + public static final int READY_TO_RUN = 25; diff --git a/src/PamView/NullGuiController.java b/src/PamView/NullGuiController.java index 6c1ad3d1..9bab00b9 100644 --- a/src/PamView/NullGuiController.java +++ b/src/PamView/NullGuiController.java @@ -32,6 +32,7 @@ public class NullGuiController implements PAMControllerGUI { @Override public void pamEnded() { // TODO Auto-generated method stub + } diff --git a/src/PamView/PamGui.java b/src/PamView/PamGui.java index e5d754f8..a502e0d8 100644 --- a/src/PamView/PamGui.java +++ b/src/PamView/PamGui.java @@ -1659,7 +1659,8 @@ public class PamGui extends PamView implements WindowListener, PamSettings { } // deal with anything that needs sorting out in the realm of UID's. - pamController.getUidManager().runShutDownOps(); + // move this to pamController.pamClose() +// pamController.getUidManager().runShutDownOps(); // if the user doesn't want to save the config file, make sure they know // that they'll lose any changes to the settings @@ -1685,7 +1686,7 @@ public class PamGui extends PamView implements WindowListener, PamSettings { pamControllerInterface.pamClose(); // shut down the JavaFX thread and the JVM - this.shutDownPamguard(); + pamController.shutDownPamguard(); return true; } diff --git a/src/PamView/PamView.java b/src/PamView/PamView.java index def9b468..f742de52 100644 --- a/src/PamView/PamView.java +++ b/src/PamView/PamView.java @@ -86,15 +86,5 @@ abstract public class PamView implements PamViewInterface { this.frameNumber = frameNumber; } - /** - * Shut down Pamguard - */ - public void shutDownPamguard() { - // force close the javaFX thread (because it won't close by itself - see Platform.setImplicitExit(false) in constructor - Platform.exit(); - - // terminate the JVM - System.exit(0); - } } diff --git a/src/generalDatabase/sqlite/SqliteSystem.java b/src/generalDatabase/sqlite/SqliteSystem.java index 2bb92d33..b41d71b8 100644 --- a/src/generalDatabase/sqlite/SqliteSystem.java +++ b/src/generalDatabase/sqlite/SqliteSystem.java @@ -122,7 +122,8 @@ public class SqliteSystem extends DBSystem implements PamSettings { File newFile = new File(databaseName); // if the file doesn't exit, consider creating it. if (newFile.exists() == false) { - newFile = createNewDatabase(databaseName, null, true); + boolean ask = GlobalArguments.getParam(DBControl.GlobalDatabaseNameArg) == null; + newFile = createNewDatabase(databaseName, null, ask); if (newFile == null) { System.out.println("Unable to create "+newFile); return; diff --git a/src/pamViewFX/PamGuiManagerFX.java b/src/pamViewFX/PamGuiManagerFX.java index 59768e90..37512661 100644 --- a/src/pamViewFX/PamGuiManagerFX.java +++ b/src/pamViewFX/PamGuiManagerFX.java @@ -880,8 +880,9 @@ public class PamGuiManagerFX implements PAMControllerGUI, PamSettings { pamController.saveViewerData(); } - // deal with anything that needs sorting out in the realm of UID's. - pamController.getUidManager().runShutDownOps(); +// // deal with anything that needs sorting out in the realm of UID's. + // move this to pamController.pamClose() +// pamController.getUidManager().runShutDownOps(); // if the user doesn't want to save the config file, make sure they know // that they'll lose any changes to the settings diff --git a/src/pamguard/Pamguard.java b/src/pamguard/Pamguard.java index 31ccc8a0..f1f7aaa1 100644 --- a/src/pamguard/Pamguard.java +++ b/src/pamguard/Pamguard.java @@ -23,6 +23,7 @@ package pamguard; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import Acquisition.AcquisitionControl; import Acquisition.FolderInputSystem; import PamController.PamController; import PamController.PamGUIManager; @@ -229,6 +230,14 @@ public class Pamguard { // source folder for wav files (or other supported sound files) GlobalArguments.setParam(FolderInputSystem.GlobalWavFolderArg, args[iArg++]); } + else if (anArg.equalsIgnoreCase(PamController.AUTOSTART)) { + // auto start processing. + GlobalArguments.setParam(PamController.AUTOSTART, PamController.AUTOSTART); + } + else if (anArg.equalsIgnoreCase(PamController.AUTOEXIT)) { + // auto exit at end of processing. + GlobalArguments.setParam(PamController.AUTOEXIT, PamController.AUTOEXIT); + } else if (anArg.equalsIgnoreCase("-help")) { System.out.println("--PamGuard Help"); System.out.println("\n--For standard GUI deployment run without any options.\n"); @@ -329,10 +338,16 @@ public class Pamguard { Thread.setDefaultUncaughtExceptionHandler(new PamExceptionHandler()); System.setProperty("sun.awt.exception.handler", PamExceptionHandler.class.getName()); - //Amongst other stuff the call to PamController.create() - //will build and show the GUI and the user can't - //do much else until that's done so let's have all - //that kicked off from with the EDT CJB 2009-06-16 + /* + * Amongst other stuff the call to PamController.create() + * will build and show the GUI and the user can't + * do much else until that's done so let's have all + * that kicked off from with the EDT CJB 2009-06-16 + * Either of these will call .create, just one is in a different + * thread, so it's at the end of the create function that other automatic + * processes should be started. + * + */ if (PamGUIManager.isSwing()) { SwingUtilities.invokeLater(createPamguard);