From 1c1f8e0c2ce41bc6f943b450a510cc6bac7ef2e4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 11 Feb 2015 14:06:39 +0200 Subject: [PATCH] Do not allocate blocks while halt is in effect 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 | 10 ++++++++++ source/libr2c2/blockallocator.h | 1 + 2 files changed, 11 insertions(+) diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index 7e992e0..79274b7 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -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 &tracks = layout.get_all(); for(set::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 &st) const { if(!blocks.empty() && cur_blocks_end!=blocks.begin()) diff --git a/source/libr2c2/blockallocator.h b/source/libr2c2/blockallocator.h index cd6dfd5..2e3f3b2 100644 --- a/source/libr2c2/blockallocator.h +++ b/source/libr2c2/blockallocator.h @@ -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 &) const; -- 2.43.0