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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.mspmote;
|
||||||
|
@ -81,7 +81,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
||||||
|
|
||||||
private Simulation simulation;
|
private Simulation simulation;
|
||||||
private CommandHandler commandHandler;
|
private CommandHandler commandHandler;
|
||||||
private LineListener commandListener;
|
private ArrayList<LineListener> commandListeners = new ArrayList<LineListener>();
|
||||||
private MSP430 myCpu = null;
|
private MSP430 myCpu = null;
|
||||||
private MspMoteType myMoteType = null;
|
private MspMoteType myMoteType = null;
|
||||||
private MspMoteMemory myMemory = null;
|
private MspMoteMemory myMemory = null;
|
||||||
|
@ -148,11 +148,15 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCLIListener() {
|
public boolean hasCLIListener() {
|
||||||
return this.commandListener != null;
|
return !commandListeners.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCLIListener(LineListener listener) {
|
public void addCLIListener(LineListener listener) {
|
||||||
this.commandListener = 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 {
|
protected void prepareMote(File fileELF, GenericNode node) throws IOException {
|
||||||
LineOutputStream lout = new LineOutputStream(new LineListener() {
|
LineOutputStream lout = new LineOutputStream(new LineListener() {
|
||||||
@Override
|
|
||||||
public void lineRead(String line) {
|
public void lineRead(String line) {
|
||||||
LineListener listener = commandListener;
|
for (LineListener l: commandListeners.toArray(new LineListener[0])) {
|
||||||
if (listener != null) {
|
if (l == null) {
|
||||||
listener.lineRead(line);
|
continue;
|
||||||
|
}
|
||||||
|
l.lineRead(line);
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
PrintStream out = new PrintStream(lout);
|
PrintStream out = new PrintStream(lout);
|
||||||
|
@ -374,20 +379,15 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCLICommandAndPrint(String comamnd) {
|
private void sendCLICommandAndPrint(String cmd) {
|
||||||
/* Backup listener */
|
LineListener tmp = new LineListener() {
|
||||||
LineListener oldListener = commandListener;
|
|
||||||
|
|
||||||
|
|
||||||
setCLIListener(new LineListener() {
|
|
||||||
public void lineRead(String line) {
|
public void lineRead(String line) {
|
||||||
logger.fatal(line);
|
logger.fatal(line);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
sendCLICommand(comamnd);
|
commandListeners.add(tmp);
|
||||||
|
sendCLICommand(cmd);
|
||||||
/* Restore listener */
|
commandListeners.remove(tmp);
|
||||||
setCLIListener(oldListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID() {
|
public int getID() {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.mspmote.plugins;
|
||||||
|
@ -166,29 +166,17 @@ public class MspCLI extends VisPlugin {
|
||||||
});
|
});
|
||||||
panel.add(commandField, BorderLayout.SOUTH);
|
panel.add(commandField, BorderLayout.SOUTH);
|
||||||
|
|
||||||
if (mspMote.hasCLIListener()) {
|
|
||||||
logArea.setText("*** CLI already occupied by another listener ***");
|
|
||||||
} else {
|
|
||||||
myListener = new LineListener() {
|
myListener = new LineListener() {
|
||||||
@Override
|
|
||||||
public void lineRead(String line) {
|
public void lineRead(String line) {
|
||||||
addCLIData(line);
|
addCLIData(line);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mspMote.setCLIListener(myListener);
|
mspMote.addCLIListener(myListener);
|
||||||
}
|
|
||||||
// Tries to select this plugin
|
|
||||||
try {
|
|
||||||
setSize(400, 200);
|
|
||||||
setSelected(true);
|
|
||||||
} catch (java.beans.PropertyVetoException e) {
|
|
||||||
// Could not select
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
if (myListener != null) {
|
if (myListener != null) {
|
||||||
mspMote.setCLIListener(null);
|
mspMote.addCLIListener(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue