Fixed so that COOJA sends in isVisible instead of quick as visibility parameter to plugins to get compile info back into COOJA - and fixed CoreComm to use MessageList text if no UI

This commit is contained in:
Joakim Eriksson 2016-12-11 16:55:29 +01:00
parent ac2a31455e
commit 2a3edc9136
18 changed files with 57 additions and 21 deletions

View file

@ -115,7 +115,7 @@ public class CC430MoteType extends MspMoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -151,7 +151,7 @@ public class ESBMoteType extends MspMoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -73,7 +73,7 @@ public class Eth1120MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -73,7 +73,7 @@ public class Exp1101MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -74,7 +74,7 @@ public class Exp1120MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -74,7 +74,7 @@ public class Exp2420MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -115,7 +115,7 @@ public class Exp5438MoteType extends MspMoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -51,8 +51,6 @@ import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation; import org.contikios.cooja.Simulation;
import org.contikios.cooja.dialogs.CompileContiki; import org.contikios.cooja.dialogs.CompileContiki;
import org.contikios.cooja.dialogs.MessageList; import org.contikios.cooja.dialogs.MessageList;
import org.contikios.cooja.dialogs.MessageListText;
import org.contikios.cooja.dialogs.MessageListUI;
import org.contikios.cooja.dialogs.MessageContainer; import org.contikios.cooja.dialogs.MessageContainer;
import org.contikios.cooja.interfaces.IPAddress; import org.contikios.cooja.interfaces.IPAddress;
import org.contikios.cooja.interfaces.Mote2MoteRelations; import org.contikios.cooja.interfaces.Mote2MoteRelations;
@ -137,7 +135,7 @@ public class SkyMoteType extends MspMoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -73,7 +73,7 @@ public class Trxeb1120MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -73,7 +73,7 @@ public class Trxeb2520MoteType extends Exp5438MoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -114,7 +114,7 @@ public class TyndallMoteType extends MspMoteType {
throw new MoteTypeCreationException("No identifier"); throw new MoteTypeCreationException("No identifier");
} }
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
if (getCompileCommands() != null) { if (getCompileCommands() != null) {
/* Handle multiple compilation commands one by one */ /* Handle multiple compilation commands one by one */

View file

@ -3378,7 +3378,7 @@ public class Cooja extends Observable {
} }
/* Verify extension directories */ /* Verify extension directories */
boolean projectsOk = verifyProjects(root.getChildren(), !quick); boolean projectsOk = verifyProjects(root.getChildren(), isVisualized());
/* GENERATE UNIQUE MOTE TYPE IDENTIFIERS */ /* GENERATE UNIQUE MOTE TYPE IDENTIFIERS */
root.detach(); root.detach();
@ -3428,7 +3428,8 @@ public class Cooja extends Observable {
Collection<Element> config = ((Element) element).getChildren(); Collection<Element> config = ((Element) element).getChildren();
newSim = new Simulation(this); newSim = new Simulation(this);
System.gc(); System.gc();
boolean createdOK = newSim.setConfigXML(config, !quick, manualRandomSeed);
boolean createdOK = newSim.setConfigXML(config, isVisualized(), manualRandomSeed);
if (!createdOK) { if (!createdOK) {
logger.info("Simulation not loaded"); logger.info("Simulation not loaded");
return null; return null;
@ -3437,7 +3438,7 @@ public class Cooja extends Observable {
} }
// Restart plugins from config // Restart plugins from config
setPluginsConfigXML(root.getChildren(), newSim, !quick); setPluginsConfigXML(root.getChildren(), newSim, isVisualized());
} catch (JDOMException e) { } catch (JDOMException e) {
throw (SimulationCreationException) new SimulationCreationException( throw (SimulationCreationException) new SimulationCreationException(

View file

@ -35,8 +35,9 @@ import java.util.Vector;
import org.contikios.cooja.MoteType.MoteTypeCreationException; import org.contikios.cooja.MoteType.MoteTypeCreationException;
import org.contikios.cooja.contikimote.ContikiMoteType; import org.contikios.cooja.contikimote.ContikiMoteType;
import org.contikios.cooja.dialogs.MessageContainer;
import org.contikios.cooja.dialogs.MessageList; import org.contikios.cooja.dialogs.MessageList;
import org.contikios.cooja.dialogs.MessageListUI;
/** /**
* The purpose of corecomm's is communicating with a compiled Contiki system * The purpose of corecomm's is communicating with a compiled Contiki system
@ -204,9 +205,10 @@ public abstract class CoreComm {
*/ */
public static void compileSourceFile(String className) public static void compileSourceFile(String className)
throws MoteTypeCreationException { throws MoteTypeCreationException {
MessageListUI compilationOutput = new MessageListUI(); /* Try to create a message list with support for GUI - will give not UI if headless */
MessageList compilationOutput = MessageContainer.createMessageList(true);
OutputStream compilationStandardStream = compilationOutput OutputStream compilationStandardStream = compilationOutput
.getInputStream(MessageListUI.NORMAL); .getInputStream(MessageList.NORMAL);
OutputStream compilationErrorStream = compilationOutput OutputStream compilationErrorStream = compilationOutput
.getInputStream(MessageList.ERROR); .getInputStream(MessageList.ERROR);

View file

@ -66,7 +66,7 @@ import org.contikios.cooja.mote.memory.SectionMoteMemory;
import org.contikios.cooja.Simulation; import org.contikios.cooja.Simulation;
import org.contikios.cooja.dialogs.CompileContiki; import org.contikios.cooja.dialogs.CompileContiki;
import org.contikios.cooja.dialogs.ContikiMoteCompileDialog; import org.contikios.cooja.dialogs.ContikiMoteCompileDialog;
import org.contikios.cooja.dialogs.MessageListUI; import org.contikios.cooja.dialogs.MessageList;
import org.contikios.cooja.dialogs.MessageContainer; import org.contikios.cooja.dialogs.MessageContainer;
import org.contikios.cooja.mote.memory.ArrayMemory; import org.contikios.cooja.mote.memory.ArrayMemory;
import org.contikios.cooja.mote.memory.MemoryInterface; import org.contikios.cooja.mote.memory.MemoryInterface;
@ -317,7 +317,7 @@ public class ContikiMoteType implements MoteType {
if (getCompileCommands() == null) { if (getCompileCommands() == null) {
throw new MoteTypeCreationException("No compile commands specified"); throw new MoteTypeCreationException("No compile commands specified");
} }
final MessageListUI compilationOutput = new MessageListUI(); final MessageList compilationOutput = MessageContainer.createMessageList(visAvailable);
String[] arr = getCompileCommands().split("\n"); String[] arr = getCompileCommands().split("\n");
for (String cmd : arr) { for (String cmd : arr) {
if (cmd.trim().isEmpty()) { if (cmd.trim().isEmpty()) {

View file

@ -1,4 +1,7 @@
package org.contikios.cooja.dialogs; package org.contikios.cooja.dialogs;
import java.awt.GraphicsEnvironment;
import org.contikios.cooja.Cooja;
public class MessageContainer { public class MessageContainer {
@ -14,4 +17,15 @@ public class MessageContainer {
public String toString() { public String toString() {
return message; return message;
} }
/* This will select UI based or not UI based depending on withUI in combination with
* headless info.
*/
public static MessageList createMessageList(boolean withUI) {
if (withUI && !GraphicsEnvironment.isHeadless() && Cooja.isVisualized()) {
return new MessageListUI();
} else {
return new MessageListText();
}
}
} }

View file

@ -1,5 +1,7 @@
package org.contikios.cooja.dialogs; package org.contikios.cooja.dialogs;
import java.io.OutputStream;
public interface MessageList { public interface MessageList {
public static final int NORMAL = 0; public static final int NORMAL = 0;
@ -14,4 +16,6 @@ public interface MessageList {
public void addMessage(String string); public void addMessage(String string);
public OutputStream getInputStream(int type);
} }

View file

@ -1,7 +1,12 @@
package org.contikios.cooja.dialogs; package org.contikios.cooja.dialogs;
import java.io.OutputStream;
public class MessageListText implements MessageList { public class MessageListText implements MessageList {
public MessageListText() {
}
@Override @Override
public void addMessage(String string, int type) { public void addMessage(String string, int type) {
System.out.println("Message:" + string); System.out.println("Message:" + string);
@ -24,4 +29,12 @@ public class MessageListText implements MessageList {
addMessage(string, MessageList.NORMAL); addMessage(string, MessageList.NORMAL);
} }
@Override
public OutputStream getInputStream(int type) {
// TODO Auto-generated method stub
return System.out;
}
} }

View file

@ -33,6 +33,7 @@ package org.contikios.cooja.dialogs;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
@ -81,6 +82,9 @@ public class MessageListUI extends JList implements MessageList {
private int max = -1; private int max = -1;
public MessageListUI() { public MessageListUI() {
if (GraphicsEnvironment.isHeadless()) {
throw new RuntimeException("Can not use UI version of message list in Headless mode");
}
super.setModel(new MessageModel()); super.setModel(new MessageModel());
setCellRenderer(new MessageRenderer()); setCellRenderer(new MessageRenderer());
setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setSelectionMode(ListSelectionModel.SINGLE_SELECTION);