]> git.tdb.fi Git - r2c2.git/commitdiff
Do not allocate blocks while halt is in effect
authorMikko Rasa <tdb@tdb.fi>
Wed, 11 Feb 2015 12:06:39 +0000 (14:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 11 Feb 2015 12:06:39 +0000 (14:06 +0200)
A turnout state change signal is emitted even if a failure is detected,
to indicate the end of the operation.  Resuming allocation in such a case
would cause the train to stray to an incorrect path.  It's better to wait
until the user has resolved the situation and removed the halt state.

source/libr2c2/blockallocator.cpp
source/libr2c2/blockallocator.h

index 7e992e00f41b65f6aecdc6afd6e89ec03e899bd0..79274b77ded54cd6df67fb7e38329e36a2a4b03a 100644 (file)
@@ -39,6 +39,7 @@ BlockAllocator::BlockAllocator(Train &t):
        Layout &layout = train.get_layout();
        layout.signal_block_reserved.connect(sigc::mem_fun(this, &BlockAllocator::block_reserved));
        layout.signal_sensor_state_changed.connect(sigc::mem_fun(this, &BlockAllocator::sensor_state_changed));
+       layout.get_driver().signal_halt.connect(sigc::mem_fun(this, &BlockAllocator::halt_event));
 
        const set<Track *> &tracks = layout.get_all<Track>();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
@@ -190,6 +191,9 @@ void BlockAllocator::reserve_more()
        if(blocks.empty())
                throw logic_error("no blocks");
 
+       if(train.get_layout().get_driver().is_halted())
+               return;
+
        BlockIter start = blocks.back();
        if(&*start==stop_at_block)
                return;
@@ -561,6 +565,12 @@ void BlockAllocator::update_next_sensor(Sensor *after)
        next_sensor = 0;
 }
 
+void BlockAllocator::halt_event(bool halted)
+{
+       if(active && !halted)
+               reserve_more();
+}
+
 void BlockAllocator::save(list<DataFile::Statement> &st) const
 {
        if(!blocks.empty() && cur_blocks_end!=blocks.begin())
index cd6dfd5949d58aa49ec346079fcf8624241f1fd0..2e3f3b28a7fb08d2ec809f35e2a75200651a1b8c 100644 (file)
@@ -83,6 +83,7 @@ private:
        void block_reserved(Block &, const Train *);
        void sensor_state_changed(Sensor &, Sensor::State);
        void update_next_sensor(Sensor *);
+       void halt_event(bool);
 
 public:
        void save(std::list<Msp::DataFile::Statement> &) const;