X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Flayout.cpp;h=72f083d57cc2da491dead13077ad495b716f5942;hb=399b48a7a80dafde49e7530ff8dfd2820232a73f;hp=af7304da6aeef557f3f4f8119d08cc4aaca1ace4;hpb=b3f8467442aac111e9a316db0dda67d37ae240b8;p=r2c2.git diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index af7304d..72f083d 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -40,7 +41,8 @@ namespace R2C2 { Layout::Layout(Catalogue &c, Driver *d): catalogue(c), driver(d), - next_turnout_addr(0x800) + next_turnout_addr(0x800), + emitting_block_reserved(false) { clock.set_rate(60); } @@ -121,7 +123,7 @@ void Layout::add(Block &b) { if(track_chains.insert(b)) { - sigc::connection conn = b.signal_reserved.connect(sigc::bind<0>(signal_block_reserved, sigc::ref(b))); + sigc::connection conn = b.signal_reserved.connect(sigc::bind<0>(sigc::mem_fun(this, &Layout::block_reserved), sigc::ref(b))); try { signal_track_chain_added.emit(b); @@ -546,6 +548,23 @@ void Layout::sensor_state_changed(Sensor &sensor, Sensor::State state) } } +void Layout::block_reserved(Block &block, Train *train) +{ + if(emitting_block_reserved) + block_reserve_queue.push_back(BlockReservation(block, train)); + else + { + SetFlag setf(emitting_block_reserved); + signal_block_reserved.emit(block, train); + while(!block_reserve_queue.empty()) + { + BlockReservation br = block_reserve_queue.front(); + block_reserve_queue.pop_front(); + signal_block_reserved.emit(br.block, br.train); + } + } +} + template Layout::Storage::~Storage() @@ -600,6 +619,12 @@ void Layout::Storage::del() } +Layout::BlockReservation::BlockReservation(Block &b, Train *t): + block(b), + train(t) +{ } + + Layout::Loader::Loader(Layout &l): DataFile::ObjectLoader(l) {