]> git.stg.codes - ssmd.git/blob - include/syncer.h
Removed GTS string.
[ssmd.git] / include / syncer.h
1 #ifndef __SSMD_SYNCER_H__
2 #define __SSMD_SYNCER_H__
3
4 #include <ctime>
5 #include <list>
6 #include <map>
7
8 #include <boost/function.hpp>
9
10 class Snmp;
11
12 namespace SSMD {
13
14 class SettingsParser;
15 class Switch;
16
17 class Timer {
18     public:
19         Timer(boost::function<void ()> callback, time_t interval);
20         ~Timer();
21
22         void fire();
23
24         time_t getInterval() const { return _interval; }
25         time_t getLastFire() const { return _lastFire; }
26         int getTimeout() const;
27     private:
28         time_t _interval;
29         time_t _lastFire;
30         boost::function<void ()> _callback;
31 };
32
33 typedef std::list<Timer>::iterator TimerIterator;
34 typedef std::pair<Switch, TimerIterator> TimedSwitch;
35
36 class Syncer {
37     public:
38         Syncer(SettingsParser & sp,
39                Snmp & snmp);
40         ~Syncer();
41
42         void run(const bool & running, bool & reload);
43
44     private:
45         SettingsParser & _settingsParser;
46         Snmp & _snmp;
47         std::list<Timer> _timers;
48         std::list<TimedSwitch> _switches;
49
50         bool wait();
51         void syncInfo();
52         Timer & getNextTimer();
53         bool getSwitchesState(std::map<std::string, Switch> & switches);
54         bool getDBData(std::string & data) const;
55 };
56
57 }
58
59 #endif