remove new motes without stopping simulation: from timevent invoked by simulation loop

enables test scripts to remove new motes
This commit is contained in:
fros4943 2009-02-18 16:01:31 +00:00
parent d458fe79b5
commit 0e9add68ce
1 changed files with 20 additions and 12 deletions

View File

@ -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());
}
/**