]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/control.h
Forgot to add the new files
[r2c2.git] / source / libmarklin / control.h
index 62d64f9a8063c645ae5ccc20bdcb804acc185f87..a041e957caaf1b009ee216b43ef34e1794cf52e7 100644 (file)
@@ -1,8 +1,16 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2006-2009  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
 #ifndef LIBMARKLIN_CONTROL_H_
 #define LIBMARKLIN_CONTROL_H_
 
 #include <list>
 #include <string>
+#include <msp/time/timer.h>
 #include <msp/time/timestamp.h>
 #include "constants.h"
 #include "sensor.h"
 namespace Marklin {
 
 class Command;
+class Reply;
 
 class Control
 {
 public:
+       sigc::signal<void, bool> signal_power_event;
        sigc::signal<void, unsigned, bool> signal_turnout_event;
        sigc::signal<void, unsigned, bool> signal_sensor_event;
 
-       Control();
-       void       set_power(bool);
-       void       set_debug(bool d) { debug=d; }
-       bool       get_power() const { return power; }
-       const TurnoutMap &get_turnouts() const { return turnouts; }
-       Turnout    *get_turnout(unsigned) const;
-       Locomotive *get_locomotive(unsigned) const;
-       Sensor     *get_sensor(unsigned) const;
-       unsigned   get_queue_length() const { return queue.size(); }
-       void       open(const std::string &);
-       Command    &command(const std::string &);
-       void       add_turnout(Turnout *);
-       void       add_locomotive(Locomotive *);
-       void       add_sensor(Sensor *);
-       void       tick();
-       ~Control();
 private:
-       int  serial_fd;
-       bool p50_enabled;
+       int serial_fd;
        bool power;
        std::list<Command> queue;
-       TurnoutMap turnouts;
-       LocomotiveSeq locomotives;
-       SensorMap sensors;
+       std::map<unsigned, Turnout *> turnouts;
+       std::map<unsigned, Locomotive *> locomotives;
+       std::map<unsigned, Sensor *> sensors;
        Msp::Time::TimeStamp next_event_query;
        bool poll_sensors;
        bool debug;
+       Msp::Time::Timer timer;
 
-       void read_all(int, char *, int);
-       std::string read_reply(Cmd);
-       void event_query_done(Error, const std::string &);
-       void turnout_event_done(Error, const std::string &);
-       void sensor_event_done(Error, const std::string &);
+public:
+       Control();
+       ~Control();
+
+       void open(const std::string &);
+       void set_debug(bool);
+       void set_power(bool);
+       bool get_power() const { return power; }
+       Command &command(Cmd);
+       Command &command(Cmd, unsigned char);
+       Command &command(Cmd, const unsigned char *, unsigned);
+       unsigned get_queue_length() const { return queue.size(); }
+       void flush();
+
+       void add_turnout(Turnout &);
+       Turnout &get_turnout(unsigned) const;
+       const std::map<unsigned, Turnout *> &get_turnouts() const { return turnouts; }
+       void add_locomotive(Locomotive &);
+       Locomotive &get_locomotive(unsigned) const;
+       const std::map<unsigned, Locomotive *> &get_locomotives() const { return locomotives; }
+       void add_sensor(Sensor &);
+       Sensor &get_sensor(unsigned) const;
+       const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
+
+       void tick();
+       Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
+private:
+       void status_done(const Reply &);
+       void event_query_done(const Reply &);
+       void turnout_event_done(const Reply &);
+       void sensor_event_done(const Reply &);
 };
 
 } // namespace Marklin