mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-07-29 13:28:58 +00:00
automatically listening to newly added nodes
This commit is contained in:
parent
c3bcf8569c
commit
0e8f94ed77
@ -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: LogListener.java,v 1.6 2007/04/02 17:44:43 fros4943 Exp $
|
* $Id: LogListener.java,v 1.7 2008/02/08 14:42:33 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
@ -49,7 +49,7 @@ import se.sics.cooja.interfaces.Log;
|
|||||||
* When instantiated, is registers as a listener on all currently existing
|
* When instantiated, is registers as a listener on all currently existing
|
||||||
* motes' log interfaces. (Observe that if new motes are added to a simulation,
|
* motes' log interfaces. (Observe that if new motes are added to a simulation,
|
||||||
* a new log listener must be created to listen to those motes also).
|
* a new log listener must be created to listen to those motes also).
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Log Listener")
|
@ClassDescription("Log Listener")
|
||||||
@ -74,12 +74,13 @@ public class LogListener extends VisPlugin {
|
|||||||
super("Log Listener - Listening on ?? mote logs", gui);
|
super("Log Listener - Listening on ?? mote logs", gui);
|
||||||
simulation = simulationToControl;
|
simulation = simulationToControl;
|
||||||
int nrLogs = 0;
|
int nrLogs = 0;
|
||||||
|
|
||||||
// Log observer
|
// Log observer
|
||||||
logObserver = new Observer() {
|
logObserver = new Observer() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
if (logTextArea == null)
|
if (logTextArea == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Mote mote = (Mote) obj;
|
Mote mote = (Mote) obj;
|
||||||
Log moteLogInterface = (Log) obs;
|
Log moteLogInterface = (Log) obs;
|
||||||
@ -88,13 +89,14 @@ public class LogListener extends VisPlugin {
|
|||||||
outputString = outputString.concat("ID:" + mote.getInterfaces().getMoteID().getMoteID() + "\t");
|
outputString = outputString.concat("ID:" + mote.getInterfaces().getMoteID().getMoteID() + "\t");
|
||||||
}
|
}
|
||||||
// Match against filter (if any)
|
// Match against filter (if any)
|
||||||
if (filterText != null && !filterText.equals("") &&
|
if (filterText != null && !filterText.equals("") &&
|
||||||
!moteLogInterface.getLastLogMessages().contains(filterText))
|
!moteLogInterface.getLastLogMessages().contains(filterText)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
outputString = outputString.concat(moteLogInterface.getLastLogMessages());
|
outputString = outputString.concat(moteLogInterface.getLastLogMessages());
|
||||||
|
|
||||||
|
|
||||||
final String str = outputString;
|
final String str = outputString;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -105,7 +107,7 @@ public class LogListener extends VisPlugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register as loglistener on all currently active motes
|
// Register as loglistener on all currently active motes
|
||||||
for (int i=0; i < simulation.getMotesCount(); i++) {
|
for (int i=0; i < simulation.getMotesCount(); i++) {
|
||||||
if (simulation.getMote(i).getInterfaces().getLog() != null) {
|
if (simulation.getMote(i).getInterfaces().getLog() != null) {
|
||||||
@ -114,6 +116,21 @@ public class LogListener extends VisPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simulation.addObserver(new Observer() {
|
||||||
|
public void update(Observable obs, Object obj) {
|
||||||
|
/* Reregister as log listener */
|
||||||
|
int nrLogs = 0;
|
||||||
|
for (int i=0; i < simulation.getMotesCount(); i++) {
|
||||||
|
if (simulation.getMote(i).getInterfaces().getLog() != null) {
|
||||||
|
simulation.getMote(i).getInterfaces().getLog().deleteObserver(logObserver);
|
||||||
|
simulation.getMote(i).getInterfaces().getLog().addObserver(logObserver);
|
||||||
|
nrLogs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTitle("Log Listener - Listening on " + nrLogs + " mote logs");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Main panel
|
// Main panel
|
||||||
logTextArea = new JTextArea(8,50);
|
logTextArea = new JTextArea(8,50);
|
||||||
logTextArea.setMargin(new Insets(5,5,5,5));
|
logTextArea.setMargin(new Insets(5,5,5,5));
|
||||||
@ -170,13 +187,14 @@ public class LogListener extends VisPlugin {
|
|||||||
logger.fatal("Could not write to file: " + saveFile);
|
logger.fatal("Could not write to file: " + saveFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
logger.fatal("No write access to file");
|
logger.fatal("No write access to file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getContentPane().add(BorderLayout.CENTER, new JScrollPane(logTextArea));
|
getContentPane().add(BorderLayout.CENTER, new JScrollPane(logTextArea));
|
||||||
getContentPane().add(BorderLayout.SOUTH, new JScrollPane(filterPanel));
|
getContentPane().add(BorderLayout.SOUTH, new JScrollPane(filterPanel));
|
||||||
|
|
||||||
@ -194,16 +212,17 @@ public class LogListener extends VisPlugin {
|
|||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
// Remove log observer from all log interfaces
|
// Remove log observer from all log interfaces
|
||||||
for (int i=0; i < simulation.getMotesCount(); i++) {
|
for (int i=0; i < simulation.getMotesCount(); i++) {
|
||||||
if (simulation.getMote(i).getInterfaces().getLog() != null)
|
if (simulation.getMote(i).getInterfaces().getLog() != null) {
|
||||||
simulation.getMote(i).getInterfaces().getLog().deleteObserver(logObserver);
|
simulation.getMote(i).getInterfaces().getLog().deleteObserver(logObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
Vector<Element> config = new Vector<Element>();
|
Vector<Element> config = new Vector<Element>();
|
||||||
|
|
||||||
Element element;
|
Element element;
|
||||||
|
|
||||||
// Selected variable name
|
// Selected variable name
|
||||||
element = new Element("filter");
|
element = new Element("filter");
|
||||||
element.setText(filterText);
|
element.setText(filterText);
|
||||||
@ -213,16 +232,16 @@ public class LogListener extends VisPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
||||||
|
|
||||||
for (Element element : configXML) {
|
for (Element element : configXML) {
|
||||||
if (element.getName().equals("filter")) {
|
if (element.getName().equals("filter")) {
|
||||||
filterText = element.getText();
|
filterText = element.getText();
|
||||||
filterTextField.setText(filterText);
|
filterTextField.setText(filterText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user