X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fcontrol.h;h=0ec3d5ba53022a6f3d2bde7614547d1c24703ee0;hb=ae0600f7c3df5b6ef46992b1423888dd0e9a5026;hp=62d64f9a8063c645ae5ccc20bdcb804acc185f87;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/control.h b/source/libmarklin/control.h index 62d64f9..0ec3d5b 100644 --- a/source/libmarklin/control.h +++ b/source/libmarklin/control.h @@ -1,8 +1,16 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #ifndef LIBMARKLIN_CONTROL_H_ #define LIBMARKLIN_CONTROL_H_ #include #include +#include #include #include "constants.h" #include "sensor.h" @@ -12,46 +20,56 @@ namespace Marklin { class Command; +class Reply; class Control { +private: + int serial_fd; + bool power; + std::list queue; + std::map turnouts; + std::map locomotives; + std::map sensors; + Msp::Time::TimeStamp next_event_query; + bool poll_sensors; + bool debug; + Msp::Time::Timer timer; + public: + sigc::signal signal_power_event; sigc::signal signal_turnout_event; sigc::signal signal_sensor_event; Control(); + ~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; + void set_debug(bool); + const std::map &get_sensors() const { return sensors; } 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 *); + Command &command(Cmd); + Command &command(Cmd, unsigned char); + Command &command(Cmd, const unsigned char *, unsigned); + + void add_turnout(Turnout &); + Turnout &get_turnout(unsigned) const; + void add_locomotive(Locomotive &); + Locomotive &get_locomotive(unsigned) const; + void add_sensor(Sensor &); + Sensor &get_sensor(unsigned) const; + void tick(); - ~Control(); + Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &); private: - int serial_fd; - bool p50_enabled; - bool power; - std::list queue; - TurnoutMap turnouts; - LocomotiveSeq locomotives; - SensorMap sensors; - Msp::Time::TimeStamp next_event_query; - bool poll_sensors; - bool debug; - 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 &); + 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