plebble
syncd.h
Go to the documentation of this file.
1 /*
2 -------------------------------------------------------------------------------
3  PLEBBLE
4 -------------------------------------------------------------------------------
5  Copyright (C) 2019-2020 KATLAS Technology. (http://katlastechnology.com)
6  Copyright (C) 2017-2020 Marcos Mayorga. (mm@mm-studios.com)
7 
8  This file is part of our Plebble(R) Platform.
9 
10  The code below cannot be copied, used for any purpose other than the one
11  agreed and/or distributed without the express permission of
12  KATLAS Technology.
13 -------------------------------------------------------------------------------
14 
15 
16 */
17 #ifndef USGOV_77adc1ef338434dcbe2fd89f5a86d54ba6fe219dcb84f80d6903a1ee04fc73ea
18 #define USGOV_77adc1ef338434dcbe2fd89f5a86d54ba6fe219dcb84f80d6903a1ee04fc73ea
19 
20 #include <condition_variable>
21 #include <mutex>
22 #include <chrono>
23 #include <atomic>
24 #include "diff.h"
25 #include <us/gov/config.h>
26 #include <us/gov/bgtask.h>
27 
28 namespace us{ namespace gov {
29 namespace engine {
30  using namespace std;
31 
32  struct syncd_t: bgtask {
33  typedef bgtask t;
35 
36  struct actuator {
37  virtual ~actuator() {}
38  virtual bool get_prev(const hash_t& h, hash_t& prev) const=0;
39  virtual int query_block(const hash_t& hash)=0;
40  virtual void clear()=0;
41  virtual bool patch_db(vector<hash_t>& patches)=0;
42  virtual void on_sync()=0;
43  };
44 
46  ~syncd_t() override;
47  syncd_t(const syncd_t&)=delete;
48  syncd_t& operator = (const syncd_t&)=delete;
49  //void on_finish() override;
50  void dump(ostream& os) const;
51  void run();
52  void update(const hash_t& head, const hash_t& tail);
53  void update(const hash_t& tail);
54  void wait();
55  void onwakeup();
56  void wait(const chrono::steady_clock::duration& d);
57  const hash_t& tip() const;
58  bool in_sync() const;
59  bool in_sync_() const;
61  void logline(ostream&os) const;
63  condition_variable cv;
64  mutable mutex mx;
65 
69  //atomic<short> resume{0};
70  condition_variable cv_wait4file;
71  mutex mx_wait4file;
72  atomic<bool> file_arrived{false};
73  hash_t last_snapshot{0};
74 
75  #if CFG_COUNTERS==1
76  struct counters_t {
77  uint32_t trigger_sync_event{0};
78  uint32_t db_reset_countdowns{0};
79  uint32_t db_reset{0};
80  void dump(ostream&os) const;
81  };
82  static counters_t counters;
83  #endif
84  #if CFG_LOGS==1
85  string logdir;
86  #endif
87  };
88 
89 }}
90 }
91 
92 #endif
93 
bgtask.h
us::gov::engine::syncd_t::update
void update(const hash_t &tail)
diff.h
us::gov::engine::syncd_t::head
hash_t head
Definition: syncd.h:66
us::gov::engine::syncd_t::cv
condition_variable cv
Definition: syncd.h:63
us::gov::engine::syncd_t::actuator::~actuator
virtual ~actuator()
Definition: syncd.h:37
us::gov::engine::syncd_t::syncd_t
syncd_t(actuator *d)
us
Definition: daemon.h:22
us::gov::crypto::ripemd160::value_type
Definition: ripemd160.h:38
us::gov::engine::syncd_t::onwakeup
void onwakeup()
us::gov::engine::syncd_t::in_sync
bool in_sync() const
us::gov::engine::syncd_t::logline
void logline(ostream &os) const
us::gov::engine::syncd_t::in_sync_
bool in_sync_() const
us::gov::engine::syncd_t::actuator::get_prev
virtual bool get_prev(const hash_t &h, hash_t &prev) const =0
us::gov::engine::syncd_t::update
void update(const hash_t &head, const hash_t &tail)
us::gov::engine::syncd_t::tip
const hash_t & tip() const
us::gov::engine::syncd_t::t
bgtask t
Definition: syncd.h:33
us::gov::engine::syncd_t::tail
hash_t tail
Definition: syncd.h:68
us::gov::engine::syncd_t::d
actuator * d
Definition: syncd.h:62
us::gov::engine::syncd_t::mx_wait4file
mutex mx_wait4file
Definition: syncd.h:71
us::gov::engine::syncd_t::actuator::query_block
virtual int query_block(const hash_t &hash)=0
us::gov::engine::syncd_t::mx
mutex mx
Definition: syncd.h:64
us::gov::engine::syncd_t::actuator::clear
virtual void clear()=0
us::gov::engine::syncd_t::syncd_t
syncd_t(const syncd_t &)=delete
us::gov::engine::syncd_t::actuator
Definition: syncd.h:36
us::gov::engine::syncd_t::wait
void wait()
us::gov::engine::syncd_t::cv_wait4file
condition_variable cv_wait4file
Definition: syncd.h:70
us::gov::engine::syncd_t::dump
void dump(ostream &os) const
us::gov::engine::syncd_t::signal_file_arrived
void signal_file_arrived()
us::gov::engine::syncd_t::wait
void wait(const chrono::steady_clock::duration &d)
us::gov::engine::syncd_t::actuator::on_sync
virtual void on_sync()=0
us::gov::engine::syncd_t::run
void run()
std
Definition: app.h:380
us::gov::engine::syncd_t
Definition: syncd.h:32
config.h
us::gov::engine::syncd_t::hash_t
diff::hash_t hash_t
Definition: syncd.h:34
us::gov::engine::syncd_t::cur
hash_t cur
Definition: syncd.h:67
us::gov::engine::syncd_t::~syncd_t
~syncd_t() override
us::gov::bgtask
Definition: bgtask.h:31
us::gov::engine::syncd_t::actuator::patch_db
virtual bool patch_db(vector< hash_t > &patches)=0