mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
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
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user