ARB
gb_main.h
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : gb_main.h //
4 // Purpose : GB_MAIN_TYPE //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #ifndef GB_MAIN_H
12 #define GB_MAIN_H
13 
14 #ifndef GB_LOCAL_H
15 #include "gb_local.h"
16 #endif
17 #ifndef GB_CB_H
18 #include "gb_cb.h"
19 #endif
20 
21 // ------------------------------
22 // forward declare types
23 
24 struct g_b_undo_mgr;
25 struct gb_close_callback_list;
26 struct gb_user;
27 struct gb_project;
28 struct gb_Key;
29 struct gb_server_data;
32 
33 // --------------------------------------------------------------------------------
34 
39 };
40 
41 struct gb_quick_save {
42  char *quick_save_disabled; // if set, quick save is not possible and text describes reason why
44 
46  quick_save_disabled(NULp),
47  last_index(0)
48  {}
49 };
50 
51 // --------------------------------------------------------------------------------
52 
53 #if defined(DEBUG)
54 // #define GEN_CACHE_STATS // unit tests will fail if enabled
55 #endif // DEBUG
56 
57 typedef uint16_t gb_cache_idx;
58 
59 struct gb_cache_entry;
60 struct gb_cache : virtual Noncopyable {
62 
66 
67  size_t sum_data_size;
68  size_t max_data_size;
70 
71 #if defined(GEN_CACHE_STATS)
72  GB_HASH *not_reused; // key = DB_path, value = number of cache entries not reused
73  GB_HASH *reused; // key = DB_path, value = number of cache entries reused
74  GB_HASH *reuse_sum; // key = DB_path, value = how often entries were reused
75 #endif
76 
77  gb_cache();
78  ~gb_cache();
79 };
80 
81 // --------------------------------------------------------------------------------
82 // root structure (one for each database)
83 
84 #define ALLOWED_KEYS 15000
85 #define ALLOWED_DATES 256
86 
87 class GB_MAIN_TYPE : virtual Noncopyable {
88  inline GB_ERROR start_transaction() __ATTR__USERESULT;
89  GB_ERROR check_quick_save() const;
90  GB_ERROR initial_client_transaction() __ATTR__USERESULT;
91 
92  int transaction_level;
93  int aborted_transaction;
94 
95  bool i_am_server;
96 
97  struct callback_group : virtual Noncopyable {
98  gb_hierarchy_callback_list *hierarchy_cbs; // defined hierarchy callbacks
99  gb_pending_callbacks pending; // collect triggered callbacks (will be called by commit; discarded by abort)
100 
101  callback_group() : hierarchy_cbs(NULp) {}
102 
103  inline void add_hcb(const gb_hierarchy_location& loc, const TypedDatabaseCallback& dbcb);
104  inline void remove_hcb(const gb_hierarchy_location& loc, const TypedDatabaseCallback& dbcb);
105  inline void forget_hcbs();
106 
107  void trigger(GBDATA *gbd, GB_CB_TYPE type, gb_callback_list *dataCBs);
108  };
109 
110  callback_group changeCBs; // all but GB_CB_DELETE
111  callback_group deleteCBs; // GB_CB_DELETE
112 
113  friend class ArbDBWriter;
114 
115 public:
116 
122  char *path;
126 
130 
131  int keycnt; // first non used key
132  long sizeofkeys; // malloc size
133  long first_free_key; // index of first gap
136  long key_clock; // trans. nr. of last change
137  bool mapped; // true -> loaded via mapfile
138 
139  unsigned int last_updated;
143 
146 
148 
149  char *dates[ALLOWED_DATES]; // @@@ saved to DB, but never used
150  unsigned int security_level;
151  long clock;
153 
155 
156  gb_user *users[GB_MAX_USERS]; // user 0 is server
158 
159  // --------------------
160 
161 private:
162  GBCONTAINER*& gb_main_ref() { return root_container; }
163 
164  GB_ERROR check_saveable(const char *new_path, const char *flags) const;
165  GB_ERROR check_quick_saveable(const char *new_path, const char *flags) const {
166  GB_ERROR error = check_quick_save();
167  return error ? error : check_saveable(new_path, flags);
168  }
169 public:
170 
171  GB_MAIN_TYPE(const char *db_path);
172  ~GB_MAIN_TYPE();
173 
174  void free_all_keys();
175  void release_main_idx();
176 
177  int get_transaction_level() const { return transaction_level; }
178 
179  GBDATA *gb_main() const { return (GBDATA*)root_container; }
180 
181  GB_ERROR login_remote(const char *db_path, const char *opent) __ATTR__USERESULT;
182 
183  inline GB_ERROR begin_transaction() __ATTR__USERESULT;
184  inline GB_ERROR commit_transaction() __ATTR__USERESULT;
185  inline GB_ERROR abort_transaction() __ATTR__USERESULT;
186 
187  inline GB_ERROR push_transaction() __ATTR__USERESULT;
188  inline GB_ERROR pop_transaction() __ATTR__USERESULT;
189 
190  inline GB_ERROR no_transaction();
191 
192  __ATTR__USERESULT GB_ERROR send_update_to_server(GBDATA *gbd) __ATTR__USERESULT;
193 
194  GB_ERROR save_quick(const char *refpath);
195 
196  GB_ERROR save_as(const char *as_path, const char *savetype);
197  GB_ERROR save_quick_as(const char *as_path);
198 
199  GB_ERROR panic_save(const char *db_panic);
200 
201  void mark_as_server() { i_am_server = true; }
202 
203  bool is_server() const { return i_am_server; }
204  bool is_client() const { return !is_server(); }
205 
206  void call_pending_callbacks();
207 
208  bool has_pending_change_callback() const { return changeCBs.pending.pending(); }
209  bool has_pending_delete_callback() const { return deleteCBs.pending.pending(); }
210 
213  void forget_hierarchy_cbs();
214 
215  inline void trigger_change_callbacks(GBDATA *gbd, GB_CB_TYPE type);
216  void trigger_delete_callbacks(GBDATA *gbd);
217 };
218 
219 #else
220 #error gb_main.h included twice
221 #endif // GB_MAIN_H
222 
long last_main_saved_transaction
Definition: gb_main.h:142
const char * GB_ERROR
Definition: arb_core.h:25
int allow_corrupt_file_recovery
Definition: gb_main.h:125
gb_quick_save qs
Definition: gb_main.h:127
GB_TYPES type
g_b_undo_mgr * undo
Definition: gb_main.h:147
char * path
Definition: gb_main.h:122
void mark_as_server()
Definition: gb_main.h:201
void free_all_keys()
Definition: ad_core.cxx:752
char * dates[ALLOWED_DATES]
Definition: gb_main.h:149
__ATTR__USERESULT GB_ERROR send_update_to_server(GBDATA *gbd) __ATTR__USERESULT
Definition: arbdb.cxx:2468
uint16_t gb_cache_idx
Definition: gb_main.h:57
gb_user * users[GB_MAX_USERS]
Definition: gb_main.h:156
gb_user * this_user
Definition: gb_main.h:157
long key_clock
Definition: gb_main.h:136
long last_saved_time
Definition: gb_main.h:140
gbcmc_comm * c_link
Definition: gb_main.h:117
int compression_mask
Definition: gb_main.h:129
bool has_pending_change_callback() const
Definition: gb_main.h:208
size_t big_data_min_size
Definition: gb_main.h:69
GBCONTAINER * root_container
Definition: gb_main.h:120
unsigned int last_updated
Definition: gb_main.h:139
void forget_hierarchy_cbs()
Definition: ad_cb.cxx:100
Definition: gb_key.h:28
long clock
Definition: gb_main.h:151
gb_open_types opentype
Definition: gb_main.h:123
Definition: adcache.cxx:15
GB_ERROR save_as(const char *as_path, const char *savetype)
gb_cache_idx firstfree_entry
Definition: gb_main.h:63
GB_MAIN_TYPE(const char *db_path)
Definition: ad_core.cxx:262
gb_cache_idx oldest_entry
Definition: gb_main.h:65
GB_ERROR save_quick(const char *refpath)
#define GB_MAX_USERS
Definition: gb_local.h:23
GB_UNDO_TYPE
Definition: arbdb.h:107
GB_UNDO_TYPE undo_type
Definition: gb_main.h:145
uchar flags
Definition: probe_tree.h:38
gb_cache_entry * entries
Definition: gb_main.h:61
GB_HASH * key_2_index_hash
Definition: gb_main.h:135
size_t max_data_size
Definition: gb_main.h:68
char * quick_save_disabled
Definition: gb_main.h:42
~gb_cache()
Definition: adcache.cxx:144
bool is_server() const
Definition: gb_main.h:203
GB_ERROR save_quick_as(const char *as_path)
GBCONTAINER * gb_key_data
Definition: gb_main.h:121
GB_ERROR begin_transaction() __ATTR__USERESULT
Definition: arbdb.cxx:2359
GB_ERROR login_remote(const char *db_path, const char *opent) __ATTR__USERESULT
Definition: ad_load.cxx:955
GB_ERROR push_transaction() __ATTR__USERESULT
Definition: arbdb.cxx:2447
GB_ERROR add_hierarchy_cb(const gb_hierarchy_location &loc, const TypedDatabaseCallback &dbcb)
Definition: ad_cb.cxx:382
static void error(const char *msg)
Definition: mkptypes.cxx:96
bool is_client() const
Definition: gb_main.h:204
size_t sum_data_size
Definition: gb_main.h:67
gb_cache()
Definition: adcache.cxx:106
GB_UNDO_TYPE requested_undo_type
Definition: gb_main.h:144
bool has_pending_delete_callback() const
Definition: gb_main.h:209
int last_index
Definition: gb_main.h:43
long first_free_key
Definition: gb_main.h:133
GBDATA * gb_main() const
Definition: gb_main.h:179
gb_quick_save()
Definition: gb_main.h:45
GB_ERROR pop_transaction() __ATTR__USERESULT
Definition: arbdb.cxx:2454
int get_transaction_level() const
Definition: gb_main.h:177
gb_server_data * server_data
Definition: gb_main.h:118
#define ALLOWED_DATES
Definition: gb_main.h:85
unsigned int security_level
Definition: gb_main.h:150
bool mapped
Definition: gb_main.h:137
void trigger_change_callbacks(GBDATA *gbd, GB_CB_TYPE type)
Definition: ad_core.cxx:52
GB_ERROR commit_transaction() __ATTR__USERESULT
Definition: arbdb.cxx:2387
gb_callback_list * close_callbacks
Definition: gb_main.h:154
#define __ATTR__USERESULT
Definition: attributes.h:58
GB_ERROR panic_save(const char *db_panic)
Definition: adcomm.cxx:187
long sizeofkeys
Definition: gb_main.h:132
gb_open_types
Definition: gb_main.h:35
gb_Key * keys
Definition: gb_main.h:134
#define NULp
Definition: cxxforward.h:116
long last_saved_transaction
Definition: gb_main.h:141
int keycnt
Definition: gb_main.h:131
void release_main_idx()
Definition: ad_load.cxx:947
GB_ERROR remove_hierarchy_cb(const gb_hierarchy_location &loc, const TypedDatabaseCallback &dbcb)
Definition: ad_cb.cxx:395
GB_ERROR abort_transaction() __ATTR__USERESULT
Definition: arbdb.cxx:2365
gb_cache_idx newest_entry
Definition: gb_main.h:64
char * disabled_path
Definition: gb_main.h:124
GB_NUMHASH * remote_hash
Definition: gb_main.h:152
GB_CB_TYPE
Definition: arbdb_base.h:46
GB_ERROR no_transaction()
Definition: arbdb.cxx:2462
gb_cache cache
Definition: gb_main.h:128
void trigger_delete_callbacks(GBDATA *gbd)
Definition: ad_core.cxx:56
void call_pending_callbacks()
Definition: ad_cb.cxx:86
GBCONTAINER * dummy_father
Definition: gb_main.h:119