1 #ifndef LIBR2C2_DRIVER_H_
2 #define LIBR2C2_DRIVER_H_
6 #include <sigc++/signal.h>
7 #include <msp/strings/lexicalcast.h>
21 typedef std::map<std::string, std::string> OptionMap;
27 Options(const std::string &);
29 void set(const std::string &, const std::string &);
32 T get(const std::string &k, const T &d = T()) const
34 OptionMap::const_iterator i = opts.find(k);
37 return Msp::lexical_cast<T>(i->second);
41 struct DetectedLocomotive
48 sigc::signal<void, bool> signal_power;
49 sigc::signal<void, bool> signal_halt;
50 sigc::signal<void, const DetectedLocomotive &> signal_locomotive_detected;
51 sigc::signal<void, const DetectedLocomotive &> signal_locomotive_gone;
52 sigc::signal<void, unsigned, unsigned, bool> signal_loco_speed;
53 sigc::signal<void, unsigned, unsigned, bool> signal_loco_function;
54 sigc::signal<void, unsigned, unsigned> signal_turnout;
55 sigc::signal<void, unsigned> signal_turnout_failed;
56 sigc::signal<void, unsigned, unsigned> signal_signal;
57 sigc::signal<void, unsigned, bool> signal_sensor;
64 virtual void set_power(bool) = 0;
65 virtual bool get_power() const = 0;
66 virtual void halt(bool) = 0;
67 virtual bool is_halted() const = 0;
69 virtual const char *enumerate_protocols(unsigned) const = 0;
70 virtual unsigned get_protocol_speed_steps(const std::string &) const = 0;
72 virtual const DetectedLocomotive *enumerate_detected_locos(unsigned) const = 0;
73 virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &) = 0;
74 virtual void remove_loco(unsigned) = 0;
75 virtual void set_loco_speed(unsigned, unsigned) = 0;
76 virtual void set_loco_reverse(unsigned, bool) = 0;
77 virtual void set_loco_function(unsigned, unsigned, bool) = 0;
79 virtual unsigned add_turnout(unsigned, const TrackType &) = 0;
80 virtual void remove_turnout(unsigned) = 0;
81 virtual void set_turnout(unsigned, unsigned) = 0;
82 virtual unsigned get_turnout(unsigned) const = 0;
84 virtual unsigned add_signal(unsigned, const SignalType &) = 0;
85 virtual void remove_signal(unsigned) = 0;
86 virtual void set_signal(unsigned, unsigned) = 0;
87 virtual unsigned get_signal(unsigned) const = 0;
89 virtual unsigned add_sensor(unsigned) = 0;
90 virtual void remove_sensor(unsigned) = 0;
91 virtual void set_sensor(unsigned, bool) = 0;
92 virtual bool get_sensor(unsigned) const = 0;
94 virtual void tick() = 0;
95 virtual void flush() = 0;
97 static Driver *create(const std::string &);