]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/block.h
Simplify some interfaces by using track and block iterators
[r2c2.git] / source / libr2c2 / block.h
index e13e58b7da510703c57834a232619bd6f1076db3..23fb3c789c6c77a0c0768b7d52dd9c140b678e82 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef LIBR2C2_BLOCK_H_
 #define LIBR2C2_BLOCK_H_
 
@@ -19,9 +12,17 @@ class Route;
 class TrackIter;
 class Train;
 
-class Block
+class Block: public sigc::trackable
 {
 public:
+       enum State
+       {
+               INACTIVE,
+               MAYBE_INACTIVE,
+               MAYBE_ACTIVE,
+               ACTIVE
+       };
+
        struct Endpoint
        {
                Track *track;
@@ -30,13 +31,20 @@ public:
                unsigned paths;
 
                Endpoint(Track *, unsigned);
+
+               TrackIter track_iter() const;
        };
 
+       sigc::signal<void, Train *> signal_reserved;
+       sigc::signal<void, State> signal_state_changed;
+
 private:
        Layout &layout;
        unsigned id;
        unsigned sensor_id;
        unsigned turnout_id;
+       State state;
+       Msp::Time::TimeDelta state_confirm_timeout;
        std::set<Track *> tracks;
        std::vector<Endpoint> endpoints;
        Train *train;
@@ -48,6 +56,7 @@ public:
        unsigned get_id() const { return id; }
        unsigned get_sensor_id() const { return sensor_id; }
        unsigned get_turnout_id() const { return turnout_id; }
+       State get_state() const { return state; }
        const std::set<Track *> &get_tracks() const { return tracks; }
        bool has_track(Track &) const;
        const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
@@ -59,10 +68,11 @@ public:
        Block *get_link(unsigned) const;
        bool reserve(Train *);
        Train *get_train() const { return train; }
-       void print_debug();
+       void tick(const Msp::Time::TimeDelta &);
 private:
-       void find_paths(TrackIter, unsigned);
+       void find_paths(const TrackIter &, unsigned);
        void determine_id();
+       void sensor_event(unsigned, bool);
 };
 
 } // namespace R2C2