From: Mikko Rasa Date: Sat, 12 Dec 2009 13:09:18 +0000 (+0000) Subject: Block reservation fixes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=39566dc89cdadf4f6e701a14b5d9049f22b591fb;p=r2c2.git Block reservation fixes --- diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 42d3e01..d7b4220 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -67,10 +67,8 @@ void Train::set_speed(unsigned speed) target_speed = speed; if(!target_speed) { - // XXX We might roll onto a new sensor and get confused - should delay freeing blocks a bit - for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) - i->block->reserve(0); - rsv_blocks.clear(); + trfc_mgr.get_control().set_timer(3*Time::sec).signal_timeout.connect( + sigc::bind_return(sigc::mem_fun(this, &Train::release_reserved_blocks), false)); } else reserve_more(); @@ -245,12 +243,15 @@ void Train::sensor_event(bool state, Sensor *sensor) else { for(list::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i) - if(i->block->get_sensor_id()==addr) + if(unsigned b_addr = i->block->get_sensor_id()) { - ++i; - for(list::iterator j=cur_blocks.begin(); j!=i; ++j) - j->block->reserve(0); - cur_blocks.erase(cur_blocks.begin(), i); + if(b_addr==addr) + { + ++i; + for(list::iterator j=cur_blocks.begin(); j!=i; ++j) + j->block->reserve(0); + cur_blocks.erase(cur_blocks.begin(), i); + } break; } @@ -401,6 +402,13 @@ void Train::set_position(const Block::Endpoint &bep) pos = cur_track->get_endpoint_position(cur_track_ep); } +void Train::release_reserved_blocks() +{ + for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) + i->block->reserve(0); + rsv_blocks.clear(); +} + Train::Loader::Loader(Train &t): DataFile::BasicLoader(t) diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 9b6344c..e749a83 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -86,6 +86,7 @@ private: void update_speed(); void set_status(const std::string &); void set_position(const Block::Endpoint &); + void release_reserved_blocks(); }; } // namespace Marklin