bdb_lib.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _BDB_LIB_H_
00032 #define _BDB_LIB_H_
00033
00034 #include <stdlib.h>
00035 #include <syslog.h>
00036 #include <sys/stat.h>
00037 #include <db.h>
00038
00039 #include "../../str.h"
00040 #include "../../db/db.h"
00041 #include "../../db/db_val.h"
00042 #include "../../locking.h"
00043
00044
00045 #define MAX_NUM_COLS 32
00046
00047
00048 #define MAX_ROW_SIZE 2048
00049
00050
00051 #define MAX_TABLENAME_SIZE 64
00052
00053 #define METADATA_COLUMNS "METADATA_COLUMNS"
00054 #define METADATA_KEY "METADATA_KEY"
00055 #define METADATA_READONLY "METADATA_READONLY"
00056 #define METADATA_LOGFLAGS "METADATA_LOGFLAGS"
00057 #define METADATA_DEFAULTS "METADATA_DEFAULTS"
00058
00059
00060 #define JLOG_NONE 0
00061 #define JLOG_INSERT 1
00062 #define JLOG_DELETE 2
00063 #define JLOG_UPDATE 4
00064 #define JLOG_FILE 8
00065 #define JLOG_STDOUT 16
00066 #define JLOG_SYSLOG 32
00067
00068 #define DELIM "|"
00069 #define DELIM_LEN (sizeof(DELIM)-1)
00070
00071 typedef db_val_t bdb_val_t, *bdb_val_p;
00072
00073 typedef struct _row
00074 {
00075 bdb_val_p fields;
00076 struct _row *prev;
00077 struct _row *next;
00078 } row_t, *row_p;
00079
00080 typedef struct _column
00081 {
00082 str name;
00083 str dv;
00084 int type;
00085 int flag;
00086 } column_t, *column_p;
00087
00088 typedef struct _table
00089 {
00090 str name;
00091 DB *db;
00092 gen_lock_t sem;
00093 column_p colp [MAX_NUM_COLS];
00094 int ncols;
00095 int nkeys;
00096 int ro;
00097 int logflags;
00098 FILE* fp;
00099 time_t t;
00100 ino_t ino;
00101 } table_t, *table_p;
00102
00103 typedef struct _tbl_cache
00104 {
00105 gen_lock_t sem;
00106 table_p dtp;
00107 struct _tbl_cache *prev;
00108 struct _tbl_cache *next;
00109 } tbl_cache_t, *tbl_cache_p;
00110
00111 typedef struct _database
00112 {
00113 str name;
00114 DB_ENV *dbenv;
00115 tbl_cache_p tables;
00116 } database_t, *database_p;
00117
00118 typedef struct _db_parms
00119 {
00120 u_int32_t cache_size;
00121 int auto_reload;
00122 int log_enable;
00123 int journal_roll_interval;
00124 } db_parms_t, *db_parms_p;
00125
00126
00127 int bdblib_init(db_parms_p _parms);
00128 int bdblib_destroy(void);
00129 int bdblib_close(char* _n);
00130 int bdblib_reopen(char* _n);
00131 int bdblib_recover(table_p _tp, int error_code);
00132 void bdblib_log(int op, table_p _tp, char* _msg, int len);
00133 int bdblib_create_dbenv(DB_ENV **dbenv, char* home);
00134 int bdblib_create_journal(table_p _tp);
00135 database_p bdblib_get_db(str *_s);
00136 tbl_cache_p bdblib_get_table(database_p _db, str *_s);
00137 table_p bdblib_create_table(database_p _db, str *_s);
00138
00139 int db_free(database_p _dbp);
00140 int tbl_cache_free(tbl_cache_p _tbc);
00141 int tbl_free(table_p _tp);
00142
00143 int load_metadata_columns(table_p _tp);
00144 int load_metadata_keys(table_p _tp);
00145 int load_metadata_readonly(table_p _tp);
00146 int load_metadata_logflags(table_p _tp);
00147 int load_metadata_defaults(table_p _tp);
00148
00149 int bdblib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v, int _n, int _ko);
00150
00151 #endif