added support for multiple msp command line listeners
This commit is contained in:
parent
93c748cc74
commit
cc252e5c16
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: MspMote.java,v 1.36 2009/12/02 17:12:32 fros4943 Exp $
|
||||
* $Id: MspMote.java,v 1.37 2009/12/14 13:22:57 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.mspmote;
|
||||
|
@ -81,7 +81,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||
|
||||
private Simulation simulation;
|
||||
private CommandHandler commandHandler;
|
||||
private LineListener commandListener;
|
||||
private ArrayList<LineListener> commandListeners = new ArrayList<LineListener>();
|
||||
private MSP430 myCpu = null;
|
||||
private MspMoteType myMoteType = null;
|
||||
private MspMoteMemory myMemory = null;
|
||||
|
@ -148,11 +148,15 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||
}
|
||||
|
||||
public boolean hasCLIListener() {
|
||||
return this.commandListener != null;
|
||||
return !commandListeners.isEmpty();
|
||||
}
|
||||
|
||||
public void setCLIListener(LineListener listener) {
|
||||
this.commandListener = listener;
|
||||
public void addCLIListener(LineListener listener) {
|
||||
commandListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeCLIListener(LineListener listener) {
|
||||
commandListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,11 +241,12 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||
*/
|
||||
protected void prepareMote(File fileELF, GenericNode node) throws IOException {
|
||||
LineOutputStream lout = new LineOutputStream(new LineListener() {
|
||||
@Override
|
||||
public void lineRead(String line) {
|
||||
LineListener listener = commandListener;
|
||||
if (listener != null) {
|
||||
listener.lineRead(line);
|
||||
for (LineListener l: commandListeners.toArray(new LineListener[0])) {
|
||||
if (l == null) {
|
||||
continue;
|
||||
}
|
||||
l.lineRead(line);
|
||||
}
|
||||
}});
|
||||
PrintStream out = new PrintStream(lout);
|
||||
|
@ -374,20 +379,15 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||
}*/
|
||||
}
|
||||
|
||||
private void sendCLICommandAndPrint(String comamnd) {
|
||||
/* Backup listener */
|
||||
LineListener oldListener = commandListener;
|
||||
|
||||
|
||||
setCLIListener(new LineListener() {
|
||||
private void sendCLICommandAndPrint(String cmd) {
|
||||
LineListener tmp = new LineListener() {
|
||||
public void lineRead(String line) {
|
||||
logger.fatal(line);
|
||||
}
|
||||
});
|
||||
sendCLICommand(comamnd);
|
||||
|
||||
/* Restore listener */
|
||||
setCLIListener(oldListener);
|
||||
};
|
||||
commandListeners.add(tmp);
|
||||
sendCLICommand(cmd);
|
||||
commandListeners.remove(tmp);
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: MspCLI.java,v 1.3 2009/09/17 13:19:08 fros4943 Exp $
|
||||
* $Id: MspCLI.java,v 1.4 2009/12/14 13:23:18 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.mspmote.plugins;
|
||||
|
@ -166,29 +166,17 @@ public class MspCLI extends VisPlugin {
|
|||
});
|
||||
panel.add(commandField, BorderLayout.SOUTH);
|
||||
|
||||
if (mspMote.hasCLIListener()) {
|
||||
logArea.setText("*** CLI already occupied by another listener ***");
|
||||
} else {
|
||||
myListener = new LineListener() {
|
||||
@Override
|
||||
public void lineRead(String line) {
|
||||
addCLIData(line);
|
||||
}
|
||||
};
|
||||
mspMote.setCLIListener(myListener);
|
||||
}
|
||||
// Tries to select this plugin
|
||||
try {
|
||||
setSize(400, 200);
|
||||
setSelected(true);
|
||||
} catch (java.beans.PropertyVetoException e) {
|
||||
// Could not select
|
||||
}
|
||||
mspMote.addCLIListener(myListener);
|
||||
}
|
||||
|
||||
public void closePlugin() {
|
||||
if (myListener != null) {
|
||||
mspMote.setCLIListener(null);
|
||||
mspMote.addCLIListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue