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);
|
|
||||||
startSimulation();
|
|
||||||
} else {
|
|
||||||
motes.remove(mote);
|
motes.remove(mote);
|
||||||
|
currentRadioMedium.unregisterMote(mote, this);
|
||||||
|
myGUI.closeMotePlugins(mote);
|
||||||
|
this.setChanged();
|
||||||
|
this.notifyObservers(this);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
myGUI.closeMotePlugins(mote);
|
/* Simulation is running, remove mote in simulation loop */
|
||||||
currentRadioMedium.unregisterMote(mote, this);
|
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();
|
scheduleEvent(removeNewMoteEvent, Simulation.this.getSimulationTime());
|
||||||
this.notifyObservers(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue