Fixed two major bugs in paxos.cc.
[invirt/third/libt4.git] / config.h
1 #ifndef config_h
2 #define config_h
3
4 #include "types.h"
5 #include "paxos.h"
6
7 class config_view_change {
8     public:
9         virtual void commit_change(unsigned view_id) = 0;
10         virtual ~config_view_change() {}
11 };
12
13 class config : public paxos_change {
14     private:
15         unsigned my_view_id;
16         string first;
17         string me;
18         config_view_change *vc;
19         proposer_acceptor paxos;
20         vector<string> mems;
21         mutex cfg_mutex;
22         cond config_cond;
23         paxos_protocol::status heartbeat(int &r, string m, unsigned instance);
24         string value(const vector<string> &mems) const;
25         vector<string> members(const string &v) const;
26         void get_view(unsigned instance, vector<string> &m, lock &cfg_mutex_lock);
27         bool remove(const string &, lock &cfg_mutex_lock);
28         void reconstruct(lock &cfg_mutex_lock);
29         typedef enum {
30             OK, // response and same view #
31             VIEWERR, // response but different view #
32             FAILURE, // no response
33         } heartbeat_t;
34         heartbeat_t doheartbeat(const string &m, lock &cfg_mutex_lock);
35     public:
36         config(const string &_first, const string &_me, config_view_change *_vc);
37         unsigned view_id() { return my_view_id; }
38         const string &myaddr() const { return me; }
39         string dump() { return paxos.dump(); }
40         void get_view(unsigned instance, vector<string> &m);
41         void restore(const string &s);
42         bool add(const string &, unsigned view_id);
43         bool ismember(const string &m, unsigned view_id);
44         void heartbeater(void);
45         void paxos_commit(unsigned instance, const string &v);
46         rpcs *get_rpcs() { return paxos.get_rpcs(); }
47         void breakpoint(int b) { paxos.breakpoint(b); }
48 };
49
50 #endif