From 0e9add68ceaea3d87949299cb450466526a18d95 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 18 Feb 2009 16:01:31 +0000 Subject: [PATCH] remove new motes without stopping simulation: from timevent invoked by simulation loop enables test scripts to remove new motes --- .../cooja/java/se/sics/cooja/Simulation.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 901c37c81..008d19446 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: Simulation.java,v 1.39 2009/02/18 15:57:47 fros4943 Exp $ + * $Id: Simulation.java,v 1.40 2009/02/18 16:01:31 fros4943 Exp $ */ package se.sics.cooja; @@ -602,21 +602,29 @@ public class Simulation extends Observable implements Runnable { * @param mote * Mote to remove */ - public void removeMote(Mote mote) { - - if (isRunning()) { - stopSimulation(); - motes.remove(mote); - startSimulation(); - } else { + public void removeMote(final Mote mote) { + if (!isRunning()) { + /* Simulation is stopped, remove mote immediately */ motes.remove(mote); + currentRadioMedium.unregisterMote(mote, this); + myGUI.closeMotePlugins(mote); + this.setChanged(); + this.notifyObservers(this); + return; } - myGUI.closeMotePlugins(mote); - currentRadioMedium.unregisterMote(mote, this); + /* Simulation is running, remove mote in simulation loop */ + TimeEvent removeNewMoteEvent = new TimeEvent(0) { + public void execute(long t) { + motes.remove(mote); + currentRadioMedium.unregisterMote(mote, Simulation.this); + recreateTickLists(); + Simulation.this.setChanged(); + Simulation.this.notifyObservers(this); + } + }; - this.setChanged(); - this.notifyObservers(this); + scheduleEvent(removeNewMoteEvent, Simulation.this.getSimulationTime()); } /**