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>";
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);
@ -963,7 +964,8 @@ public class Cooja extends Observable {
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);
@ -3275,13 +3279,12 @@ public class Cooja extends Observable {
System.exit(1);
}
} else {
logger.fatal("No test editor controlling simulation, aborting");
logger.fatal("No plugin controlling simulation, aborting");
System.exit(1);
}
}
sim.setSpeedLimit(null);
sim.startSimulation();
} else if (args.length > 0 && args[0].startsWith("-applet")) {

View file

@ -110,5 +110,17 @@ public @interface PluginType {
*/
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();
}

View file

@ -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);
@ -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) {
linkedFile = source;
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.MessageContainer;
import org.contikios.cooja.plugins.ScriptRunner;
import org.contikios.cooja.PluginType;
public class ExecuteJAR {
private static Logger logger = Logger.getLogger(ExecuteJAR.class);
@ -230,18 +231,18 @@ public class ExecuteJAR {
logger.info("Checking mote types: '" + Cooja.getDescriptionOf(t.getClass()) + "'");
}
/* Check dependencies: Contiki Test Editor */
boolean hasTestEditor = false;
/* Check dependencies: Contiki Control Plugin */
boolean hasController = false;
for (Plugin startedPlugin : gui.getStartedPlugins()) {
if (startedPlugin instanceof ScriptRunner) {
hasTestEditor = true;
break;
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
if (pluginType == PluginType.SIM_CONTROL_PLUGIN) {
hasController = true;
}
}
logger.info("Checking that Contiki Test Editor exists: " + hasTestEditor);
if (!hasTestEditor) {
logger.info("Checking that Contiki Control Plugin exists: " + hasController);
if (!hasController) {
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."
);
}