Merge pull request #850 from TheGeorge/master

Pull request for issue #840
This commit is contained in:
Fredrik Österlind 2014-11-10 15:36:57 +01:00
commit 16141845cf
4 changed files with 50 additions and 26 deletions

View file

@ -952,7 +952,8 @@ public class Cooja extends Observable {
String tooltip = "<html><pre>"; String tooltip = "<html><pre>";
if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) {
tooltip += "Cooja 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: "; tooltip += "Simulation plugin: ";
if (getSimulation() == null) { if (getSimulation() == null) {
menuItem.setEnabled(false); menuItem.setEnabled(false);
@ -963,7 +964,8 @@ public class Cooja extends Observable {
tooltip += description + " (" + newPluginClass.getName() + ")"; tooltip += description + " (" + newPluginClass.getName() + ")";
/* Check if simulation plugin depends on any particular radio medium */ /* 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) { if (newPluginClass.getAnnotation(SupportedArguments.class) != null) {
boolean active = false; boolean active = false;
Class<? extends RadioMedium>[] radioMediums = newPluginClass.getAnnotation(SupportedArguments.class).radioMediums(); 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(); 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; continue;
} }
@ -1848,8 +1851,8 @@ public class Cooja extends Observable {
pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class }) pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class })
.newInstance(argMote, argSimulation, argGUI); .newInstance(argMote, argSimulation, argGUI);
} else if (pluginType == PluginType.SIM_PLUGIN } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN
|| pluginType == PluginType.SIM_STANDARD_PLUGIN) { || pluginType == PluginType.SIM_CONTROL_PLUGIN) {
if (argGUI == null) { if (argGUI == null) {
throw new PluginConstructionException("No GUI argument for simulation plugin"); throw new PluginConstructionException("No GUI argument for simulation plugin");
} }
@ -1931,7 +1934,8 @@ public class Cooja extends Observable {
try { try {
if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) { if (pluginType == PluginType.COOJA_PLUGIN || pluginType == PluginType.COOJA_STANDARD_PLUGIN) {
pluginClass.getConstructor(new Class[] { Cooja.class }); 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 }); pluginClass.getConstructor(new Class[] { Simulation.class, Cooja.class });
} else if (pluginType == PluginType.MOTE_PLUGIN) { } else if (pluginType == PluginType.MOTE_PLUGIN) {
pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class }); pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, Cooja.class });
@ -3247,19 +3251,19 @@ public class Cooja extends Observable {
} }
Cooja gui = sim.getCooja(); Cooja gui = sim.getCooja();
/* Make sure at least one test editor is controlling the simulation */ /* Make sure at least one plugin controlling the simulation */
boolean hasEditor = false; boolean hasController = false;
for (Plugin startedPlugin : gui.startedPlugins) { for (Plugin startedPlugin : gui.startedPlugins) {
if (startedPlugin instanceof ScriptRunner) { int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
hasEditor = true; if (pluginType == PluginType.SIM_CONTROL_PLUGIN) {
break; hasController = true;
} }
} }
/* Backwards compatibility: /* 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. */ * We will manually start a test editor from here. */
if (!hasEditor) { if (!hasController) {
File scriptFile = new File(config.substring(0, config.length()-4) + ".js"); File scriptFile = new File(config.substring(0, config.length()-4) + ".js");
if (scriptFile.exists()) { if (scriptFile.exists()) {
logger.info("Detected old simulation test, starting test editor manually from: " + scriptFile); logger.info("Detected old simulation test, starting test editor manually from: " + scriptFile);
@ -3275,13 +3279,12 @@ public class Cooja extends Observable {
System.exit(1); System.exit(1);
} }
} else { } else {
logger.fatal("No test editor controlling simulation, aborting"); logger.fatal("No plugin controlling simulation, aborting");
System.exit(1); System.exit(1);
} }
} }
sim.setSpeedLimit(null);
sim.startSimulation();
} else if (args.length > 0 && args[0].startsWith("-applet")) { } else if (args.length > 0 && args[0].startsWith("-applet")) {

View file

@ -109,6 +109,18 @@ public @interface PluginType {
* @see #COOJA_PLUGIN * @see #COOJA_PLUGIN
*/ */
public static final int COOJA_STANDARD_PLUGIN = 5; 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(); int value();
} }

View file

@ -88,7 +88,7 @@ import org.contikios.cooja.dialogs.MessageList;
import org.contikios.cooja.util.StringUtils; import org.contikios.cooja.util.StringUtils;
@ClassDescription("Simulation script editor") @ClassDescription("Simulation script editor")
@PluginType(PluginType.SIM_PLUGIN) @PluginType(PluginType.SIM_CONTROL_PLUGIN)
public class ScriptRunner extends VisPlugin { public class ScriptRunner extends VisPlugin {
private static final long serialVersionUID = 7614358340336799109L; private static final long serialVersionUID = 7614358340336799109L;
private static Logger logger = Logger.getLogger(ScriptRunner.class); private static Logger logger = Logger.getLogger(ScriptRunner.class);
@ -276,6 +276,14 @@ public class ScriptRunner extends VisPlugin {
} }
} }
public void startPlugin() {
/* start simulation */
if (!Cooja.isVisualized()) {
simulation.setSpeedLimit(null);
simulation.startSimulation();
}
}
public void setLinkFile(File source) { public void setLinkFile(File source) {
linkedFile = source; linkedFile = source;
if (source == null) { if (source == null) {

View file

@ -57,6 +57,7 @@ import org.contikios.cooja.dialogs.CompileContiki;
import org.contikios.cooja.dialogs.MessageList; import org.contikios.cooja.dialogs.MessageList;
import org.contikios.cooja.dialogs.MessageList.MessageContainer; import org.contikios.cooja.dialogs.MessageList.MessageContainer;
import org.contikios.cooja.plugins.ScriptRunner; import org.contikios.cooja.plugins.ScriptRunner;
import org.contikios.cooja.PluginType;
public class ExecuteJAR { public class ExecuteJAR {
private static Logger logger = Logger.getLogger(ExecuteJAR.class); private static Logger logger = Logger.getLogger(ExecuteJAR.class);
@ -230,18 +231,18 @@ public class ExecuteJAR {
logger.info("Checking mote types: '" + Cooja.getDescriptionOf(t.getClass()) + "'"); logger.info("Checking mote types: '" + Cooja.getDescriptionOf(t.getClass()) + "'");
} }
/* Check dependencies: Contiki Test Editor */ /* Check dependencies: Contiki Control Plugin */
boolean hasTestEditor = false; boolean hasController = false;
for (Plugin startedPlugin : gui.getStartedPlugins()) { for (Plugin startedPlugin : gui.getStartedPlugins()) {
if (startedPlugin instanceof ScriptRunner) { int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
hasTestEditor = true; if (pluginType == PluginType.SIM_CONTROL_PLUGIN) {
break; hasController = true;
} }
} }
logger.info("Checking that Contiki Test Editor exists: " + hasTestEditor); logger.info("Checking that Contiki Control Plugin exists: " + hasController);
if (!hasTestEditor) { if (!hasController) {
throw new RuntimeException( throw new RuntimeException(
"The simulation needs at least one active Contiki Test Editor plugin.\n" + "The simulation needs at least one active control plugin.\n" +
"The plugin is needed to control the non-visualized simulation." "The plugin is needed to control the non-visualized simulation."
); );
} }