automatically listening to newly added nodes
This commit is contained in:
parent
c3bcf8569c
commit
0e8f94ed77
1 changed files with 38 additions and 19 deletions
|
@ -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;
|
||||||
|
@ -78,8 +78,9 @@ public class LogListener extends VisPlugin {
|
||||||
// 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;
|
||||||
|
@ -89,8 +90,9 @@ public class LogListener extends VisPlugin {
|
||||||
}
|
}
|
||||||
// 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());
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
@ -171,8 +188,9 @@ public class LogListener extends VisPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
logger.fatal("No write access to file");
|
logger.fatal("No write access to file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -194,8 +212,9 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue