]> git.tdb.fi Git - r2c2.git/commitdiff
Block reservation fixes
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Dec 2009 13:09:18 +0000 (13:09 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Dec 2009 13:09:18 +0000 (13:09 +0000)
source/libmarklin/train.cpp
source/libmarklin/train.h

index 42d3e01e1f87b1675d9edd32fd7439533ced4af4..d7b422039ea71e43b740f619a59c33a03f9edd6a 100644 (file)
@@ -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<BlockRef>::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<BlockRef>::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<BlockRef>::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<BlockRef>::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<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+               i->block->reserve(0);
+       rsv_blocks.clear();
+}
+
 
 Train::Loader::Loader(Train &t):
        DataFile::BasicLoader<Train>(t)
index 9b6344c2fa104066bbb782f0dc6e87bfa3fcd832..e749a8336a09de542d0b6f0d3815b0f9437d121d 100644 (file)
@@ -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