remove new motes without stopping simulation: from timevent invoked by simulation loop
enables test scripts to remove new motes
This commit is contained in:
parent
d458fe79b5
commit
0e9add68ce
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja;
|
||||||
|
@ -602,21 +602,29 @@ public class Simulation extends Observable implements Runnable {
|
||||||
* @param mote
|
* @param mote
|
||||||
* Mote to remove
|
* Mote to remove
|
||||||
*/
|
*/
|
||||||
public void removeMote(Mote mote) {
|
public void removeMote(final Mote mote) {
|
||||||
|
if (!isRunning()) {
|
||||||
if (isRunning()) {
|
/* Simulation is stopped, remove mote immediately */
|
||||||
stopSimulation();
|
|
||||||
motes.remove(mote);
|
motes.remove(mote);
|
||||||
startSimulation();
|
|
||||||
} else {
|
|
||||||
motes.remove(mote);
|
|
||||||
}
|
|
||||||
|
|
||||||
myGUI.closeMotePlugins(mote);
|
|
||||||
currentRadioMedium.unregisterMote(mote, this);
|
currentRadioMedium.unregisterMote(mote, this);
|
||||||
|
myGUI.closeMotePlugins(mote);
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers(this);
|
this.notifyObservers(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
scheduleEvent(removeNewMoteEvent, Simulation.this.getSimulationTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue