identt
SharedTable.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_UTILS_SHAREDTABLE_HPP_
34 #define _IDENTT_UTILS_SHAREDTABLE_HPP_
35 
36 #include <memory>
37 #include <vector>
38 #include <chrono>
39 #include <random>
40 
41 #include <utils/SharedCounter.hpp>
42 #include <utils/SharedPairMap.hpp>
43 #include <utils/SharedMap.hpp>
44 
45 #include <store/StoreLevel.hpp>
46 #include <store/StoreCache.hpp>
47 #include <crypto/CryptoBase.hpp>
48 
49 #define IDENTT_CURRTIME_MS std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()
50 
51 namespace identt {
52 namespace utils {
53 class SharedTable : public std::enable_shared_from_this<SharedTable> {
54 public:
55  using pointer=std::shared_ptr<SharedTable>;
56  using dbpointer=identt::store::StoreLevel::dbpointer;
57  using LockT = boost::shared_mutex;
58  using WriteLockT = boost::unique_lock< LockT >;
59  using ReadLockT = boost::shared_lock< LockT >;
64 
67 
69  using KeyRingT = std::unordered_map<std::string,std::shared_ptr<identt::crypto::CryptoBase> >;
70 
71  using SharedCache = identt::store::StoreCache::pointer;
72 
76  KeyRingT keyring;
77 
78  // map of shared followers
79  SharedRemote remotes;
80 
81  // map of shared transactions
82  SharedTrans transactions;
83 
84  // shared cache
85  SharedCache dbcache;
86 
87  // string shared
88  SharedString master;
89  SharedString shared_secret;
90  SharedString hostname;
91  SharedString baseurl;
92  SharedString thisurl;
93  SharedString lastslave;
94  // counter shared
95  SharedCounter maincounter;
96  SharedCounter logcounter;
97  // database pointers
98  SharedDBPointer maindb;
99  SharedDBPointer logdb;
100  // booleans
101  SharedBool is_master;
102  SharedBool is_ready;
103  SharedBool lookup_requires_key;
104  SharedBool invite_requires_key;
105  SharedBool dont_send_sms;
106  SharedBool lookup_uses_local;
107 
112  SharedTable(const SharedTable&) = delete;
113  SharedTable& operator=(const SharedTable&) = delete;
114 
121  static pointer create()
122  {
123  pointer p(new SharedTable());
124  return p;
125  }
126 
133  pointer share()
134  {
135  return shared_from_this();
136  }
137 
141  virtual ~SharedTable () {}
142 
143 private:
144 
145  LockT class_mutex;
146  LockT number_mutex;
147 
154  SharedTable()
155  : dbcache ( identt::store::StoreCache::create() )
156  {}
157 
158 };
159 } // namespace utils
160 } // namespace identt
161 #endif /* _IDENTT_UTILS_SHAREDTABLE_HPP_ */
static pointer create()
create : static construction creates new first time
Definition: StoreCache.hpp:65
static pointer create()
create : static construction creates new first time
Definition: SharedTable.hpp:121
KeyRingT keyring
public stable to be used directly , never updated after init by code
Definition: SharedTable.hpp:76
Definition: SharedCounter.hpp:40
Definition: CryptoBase.hpp:49
pointer share()
share : return instance
Definition: SharedTable.hpp:133
Definition: SharedTable.hpp:53
virtual ~SharedTable()
destructor
Definition: SharedTable.hpp:141