diff --git a/tools/cooja/java/org/contikios/cooja/Cooja.java b/tools/cooja/java/org/contikios/cooja/Cooja.java index d053fd45e..a0e9dccda 100644 --- a/tools/cooja/java/org/contikios/cooja/Cooja.java +++ b/tools/cooja/java/org/contikios/cooja/Cooja.java @@ -952,18 +952,20 @@ public class Cooja extends Observable { String tooltip = "
"; if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { tooltip += "Cooja plugin: "; - } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) { + } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN + || pluginType == PluginType.SIM_CONTROL_PLUGIN) { tooltip += "Simulation plugin: "; if (getSimulation() == null) { menuItem.setEnabled(false); } } else if (pluginType == PluginType.MOTE_PLUGIN) { - tooltip += "Mote plugin: "; + tooltip += "Mote plugin: "; } tooltip += description + " (" + newPluginClass.getName() + ")"; /* Check if simulation plugin depends on any particular radio medium */ - if ((pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) && (getSimulation() != null)) { + if ((pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN + || pluginType == PluginType.SIM_CONTROL_PLUGIN) && (getSimulation() != null)) { if (newPluginClass.getAnnotation(SupportedArguments.class) != null) { boolean active = false; Class extends RadioMedium>[] radioMediums = newPluginClass.getAnnotation(SupportedArguments.class).radioMediums(); @@ -1020,7 +1022,8 @@ public class Cooja extends Observable { } int pluginType = pluginClass.getAnnotation(PluginType.class).value(); - if (pluginType != PluginType.SIM_PLUGIN && pluginType != PluginType.SIM_STANDARD_PLUGIN) { + if (pluginType != PluginType.SIM_PLUGIN && pluginType != PluginType.SIM_STANDARD_PLUGIN + && pluginType == PluginType.SIM_CONTROL_PLUGIN) { continue; } @@ -1848,8 +1851,8 @@ public class Cooja extends Observable { pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class }) .newInstance(argMote, argSimulation, argGUI); - } else if (pluginType == PluginType.SIM_PLUGIN - || pluginType == PluginType.SIM_STANDARD_PLUGIN) { + } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN + || pluginType == PluginType.SIM_CONTROL_PLUGIN) { if (argGUI == null) { throw new PluginConstructionException("No GUI argument for simulation plugin"); } @@ -1931,7 +1934,8 @@ public class Cooja extends Observable { try { if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { pluginClass.getConstructor(new Class[] { Cooja.class }); - } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) { + } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN + || pluginType == PluginType.SIM_CONTROL_PLUGIN) { pluginClass.getConstructor(new Class[] { Simulation.class, Cooja.class }); } else if (pluginType == PluginType.MOTE_PLUGIN) { pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class }); @@ -3247,19 +3251,19 @@ public class Cooja extends Observable { } Cooja gui = sim.getCooja(); - /* Make sure at least one test editor is controlling the simulation */ - boolean hasEditor = false; + /* Make sure at least one plugin controlling the simulation */ + boolean hasController = false; for (Plugin startedPlugin : gui.startedPlugins) { - if (startedPlugin instanceof ScriptRunner) { - hasEditor = true; - break; - } + int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); + if (pluginType == PluginType.SIM_CONTROL_PLUGIN) { + hasController = true; + } } /* Backwards compatibility: - * simulation has no test editor, but has external (old style) test script. + * simulation has no control plugin, but has external (old style) test script. * We will manually start a test editor from here. */ - if (!hasEditor) { + if (!hasController) { File scriptFile = new File(config.substring(0, config.length()-4) + ".js"); if (scriptFile.exists()) { logger.info("Detected old simulation test, starting test editor manually from: " + scriptFile); @@ -3280,8 +3284,7 @@ public class Cooja extends Observable { } } - sim.setSpeedLimit(null); - sim.startSimulation(); + } else if (args.length > 0 && args[0].startsWith("-applet")) { diff --git a/tools/cooja/java/org/contikios/cooja/PluginType.java b/tools/cooja/java/org/contikios/cooja/PluginType.java index 34790a823..9bf6344e9 100644 --- a/tools/cooja/java/org/contikios/cooja/PluginType.java +++ b/tools/cooja/java/org/contikios/cooja/PluginType.java @@ -109,6 +109,18 @@ public @interface PluginType { * @see #COOJA_PLUGIN */ public static final int COOJA_STANDARD_PLUGIN = 5; + + /** + * Simulation Control Plugin + * + * A Simulation Control Plugin indicates control over the simulation. If COOJA + * is loaded in nogui mode, it will terminate if no controll plugin is present. + * + * COOJA plugins are available via the plugins menubar. + * + * When constructed, a COOJA plugin is given the current GUI. + */ + public static final int SIM_CONTROL_PLUGIN = 6; int value(); } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/ScriptRunner.java b/tools/cooja/java/org/contikios/cooja/plugins/ScriptRunner.java index b77d365c8..4e3be7297 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/ScriptRunner.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/ScriptRunner.java @@ -88,7 +88,7 @@ import org.contikios.cooja.dialogs.MessageList; import org.contikios.cooja.util.StringUtils; @ClassDescription("Simulation script editor") -@PluginType(PluginType.SIM_PLUGIN) +@PluginType(PluginType.SIM_CONTROL_PLUGIN) public class ScriptRunner extends VisPlugin { private static final long serialVersionUID = 7614358340336799109L; private static Logger logger = Logger.getLogger(ScriptRunner.class); @@ -274,6 +274,10 @@ public class ScriptRunner extends VisPlugin { if (script != null) { updateScript(script); } + + /* start simulation */ + simulation.setSpeedLimit(null); + simulation.startSimulation(); } public void setLinkFile(File source) {