]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/blockallocator.h
Avoid nested block reservations completely
[r2c2.git] / source / libr2c2 / blockallocator.h
index 7ff5d77f2cf538b4effc9fa4c40826b9a8cb956d..b401233593793a52743ef9bfb0967e4f27005197 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <list>
 #include <msp/datafile/objectloader.h>
-#include "block.h"
 #include "blockiter.h"
+#include "sensor.h"
 
 namespace R2C2 {
 
@@ -27,20 +27,33 @@ public:
                void hint(unsigned);
        };
 
+       sigc::signal<void, Block &, Sensor *> signal_advanced;
+       sigc::signal<void, Block &> signal_rear_advanced;
+
 private:
+       struct BlockMatch;
+
        typedef std::list<BlockIter> BlockList;
 
        Train &train;
+       bool active;
        BlockList blocks;
        BlockList::iterator cur_blocks_end;
+       Sensor *next_sensor;
        Block *pending_block;
        const Block *stop_at_block;
        bool reserving;
+       bool advancing;
+       bool reserve_pending;
 
 public:
        BlockAllocator(Train &);
 
-       void start_from(const BlockIter &);
+       void set_active(bool);
+       bool is_active() const { return active; }
+
+       bool start_from(const BlockIter &);
+       void rewind_to(const Block &);
        void clear();
        bool empty() const { return blocks.empty(); }
        void stop_at(const Block *);
@@ -48,22 +61,32 @@ public:
        const BlockIter &first() const;
        const BlockIter &last() const;
        const BlockIter &last_current() const;
+       const BlockIter &iter_for(const Block &) const;
 
-       int get_entry_to_block(const Block &) const;
+       bool has_block(const Block &) const;
+       bool is_block_current(const Block &) const;
+
+       void tick();
 
-       void reserve_more();
-       void release_until(const Block &);
-       bool release_from(const Block &);
-       void release_noncurrent();
 private:
-       void release_blocks(const BlockList::iterator &, const BlockList::iterator &);
+       void reserve_more();
+       bool reserve_block(const BlockIter &);
+       void advance_front(const Block *, bool);
+       void advance_front(const Sensor *);
+       void advance_back();
+       void release_blocks_begin(const BlockList::iterator &);
+       void release_blocks_end(const BlockList::iterator &);
+       void release_block(const BlockList::iterator &);
 public:
        void reverse();
 
 private:
+       void turnout_path_changing(Track &);
        void turnout_path_changed(Track &);
        void block_reserved(Block &, const Train *);
-       void block_state_changed(Block &, Block::State);
+       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;