Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

db_cxx.h

00001 /* DO NOT EDIT: automatically built by dist/s_win32. */
00002 /*-
00003  * See the file LICENSE for redistribution information.
00004  *
00005  * Copyright (c) 1997-2005
00006  *      Sleepycat Software.  All rights reserved.
00007  *
00008  * $Id: db_cxx.in,v 12.13 2005/10/18 14:17:08 mjc Exp $
00009  */
00010 
00011 #ifndef _DB_CXX_H_
00012 #define _DB_CXX_H_
00013 //
00014 // C++ assumptions:
00015 //
00016 // To ensure portability to many platforms, both new and old, we make
00017 // few assumptions about the C++ compiler and library.  For example,
00018 // we do not expect STL, templates or namespaces to be available.  The
00019 // "newest" C++ feature used is exceptions, which are used liberally
00020 // to transmit error information.  Even the use of exceptions can be
00021 // disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags
00022 // with the DbEnv or Db constructor.
00023 //
00024 // C++ naming conventions:
00025 //
00026 //  - All top level class names start with Db.
00027 //  - All class members start with lower case letter.
00028 //  - All private data members are suffixed with underscore.
00029 //  - Use underscores to divide names into multiple words.
00030 //  - Simple data accessors are named with get_ or set_ prefix.
00031 //  - All method names are taken from names of functions in the C
00032 //    layer of db (usually by dropping a prefix like "db_").
00033 //    These methods have the same argument types and order,
00034 //    other than dropping the explicit arg that acts as "this".
00035 //
00036 // As a rule, each DbFoo object has exactly one underlying DB_FOO struct
00037 // (defined in db.h) associated with it.  In some cases, we inherit directly
00038 // from the DB_FOO structure to make this relationship explicit.  Often,
00039 // the underlying C layer allocates and deallocates these structures, so
00040 // there is no easy way to add any data to the DbFoo class.  When you see
00041 // a comment about whether data is permitted to be added, this is what
00042 // is going on.  Of course, if we need to add data to such C++ classes
00043 // in the future, we will arrange to have an indirect pointer to the
00044 // DB_FOO struct (as some of the classes already have).
00045 //
00046 
00049 //
00050 // Forward declarations
00051 //
00052 
00053 #include <stdarg.h>
00054 
00055 #define HAVE_CXX_STDHEADERS 1
00056 #ifdef HAVE_CXX_STDHEADERS
00057 #include <iostream>
00058 #include <exception>
00059 #define __DB_STD(x)     std::x
00060 #else
00061 #include <iostream.h>
00062 #include <exception.h>
00063 #define __DB_STD(x)     x
00064 #endif
00065 
00066 #include "db.h"
00067 
00068 class Db;                                        // forward
00069 class Dbc;                                       // forward
00070 class DbEnv;                                     // forward
00071 class DbInfo;                                    // forward
00072 class DbLock;                                    // forward
00073 class DbLogc;                                    // forward
00074 class DbLsn;                                     // forward
00075 class DbMpoolFile;                               // forward
00076 class DbPreplist;                                // forward
00077 class Dbt;                                       // forward
00078 class DbTxn;                                     // forward
00079 class DbLock;                                    // forward
00080 class DbSequence;                                // forward
00081 class Dbt;                                       // forward
00082 
00083 class DbMultipleIterator;                        // forward
00084 class DbMultipleKeyDataIterator;                 // forward
00085 class DbMultipleRecnoDataIterator;               // forward
00086 class DbMultipleDataIterator;                    // forward
00087 
00088 class DbException;                               // forward
00089 class DbDeadlockException;                       // forward
00090 class DbLockNotGrantedException;                 // forward
00091 class DbMemoryException;                         // forward
00092 class DbRepHandleDeadException;                  // forward
00093 class DbRunRecoveryException;                    // forward
00094 
00097 //
00098 // Turn off inappropriate compiler warnings
00099 //
00100 
00101 #ifdef _MSC_VER
00102 
00103 // These are level 4 warnings that are explicitly disabled.
00104 // With Visual C++, by default you do not see above level 3 unless
00105 // you use /W4.  But we like to compile with the highest level
00106 // warnings to catch other errors.
00107 //
00108 // 4201: nameless struct/union
00109 //       triggered by standard include file <winnt.h>
00110 //
00111 // 4514: unreferenced inline function has been removed
00112 //       certain include files in MSVC define methods that are not called
00113 //
00114 #pragma warning(disable: 4201 4514)
00115 
00116 #endif
00117 
00120 //
00121 // Mechanisms for declaring classes
00122 //
00123 
00124 //
00125 // Every class defined in this file has an _exported next to the class name.
00126 // This is needed for WinTel machines so that the class methods can
00127 // be exported or imported in a DLL as appropriate.  Users of the DLL
00128 // use the define DB_USE_DLL.  When the DLL is built, DB_CREATE_DLL
00129 // must be defined.
00130 //
00131 #if defined(_MSC_VER)
00132 
00133 #  if defined(DB_CREATE_DLL)
00134 #    define _exported __declspec(dllexport)      // creator of dll
00135 #  elif defined(DB_USE_DLL)
00136 #    define _exported __declspec(dllimport)      // user of dll
00137 #  else
00138 #    define _exported                            // static lib creator or user
00139 #  endif
00140 
00141 #else /* _MSC_VER */
00142 
00143 #  define _exported
00144 
00145 #endif /* _MSC_VER */
00146 
00147 // Some interfaces can be customized by allowing users to define
00148 // callback functions.  For performance and logistical reasons, some
00149 // callback functions must be declared in extern "C" blocks.  For others,
00150 // we allow you to declare the callbacks in C++ or C (or an extern "C"
00151 // block) as you wish.  See the set methods for the callbacks for
00152 // the choices.
00153 //
00154 extern "C" {
00155         typedef void * (*db_malloc_fcn_type)
00156                 (size_t);
00157         typedef void * (*db_realloc_fcn_type)
00158                 (void *, size_t);
00159         typedef void (*db_free_fcn_type)
00160                 (void *);
00161         typedef int (*bt_compare_fcn_type)          /*C++ version available*/
00162                 (DB *, const DBT *, const DBT *);
00163         typedef size_t (*bt_prefix_fcn_type)        /*C++ version available*/
00164                 (DB *, const DBT *, const DBT *);
00165         typedef int (*dup_compare_fcn_type)         /*C++ version available*/
00166                 (DB *, const DBT *, const DBT *);
00167         typedef u_int32_t (*h_hash_fcn_type)        /*C++ version available*/
00168                 (DB *, const void *, u_int32_t);
00169         typedef int (*pgin_fcn_type)
00170                 (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
00171         typedef int (*pgout_fcn_type)
00172                 (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
00173 }
00174 
00175 //
00176 // Represents a database table = a set of keys with associated values.
00177 //
00178 class _exported Db
00179 {
00180         friend class DbEnv;
00181 
00182 public:
00183         Db(DbEnv*, u_int32_t);      // Create a Db object.
00184         virtual ~Db();              // Calls close() if the user hasn't.
00185 
00186         // These methods exactly match those in the C interface.
00187         //
00188         virtual int associate(DbTxn *txn, Db *secondary,
00189             int (*callback)(Db *, const Dbt *, const Dbt *, Dbt *),
00190             u_int32_t flags);
00191         virtual int close(u_int32_t flags);
00192         virtual int compact(DbTxn *txnid, Dbt *start, Dbt *stop,
00193             DB_COMPACT *c_data, u_int32_t flags, Dbt *end);
00194         virtual int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
00195         virtual int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
00196         virtual void err(int, const char *, ...);
00197         virtual void errx(const char *, ...);
00198         virtual int fd(int *fdp);
00199         virtual int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
00200         virtual void *get_app_private() const;
00201         virtual int get_byteswapped(int *);
00202         virtual int get_dbname(const char **, const char **);
00203         virtual int get_open_flags(u_int32_t *);
00204         virtual int get_type(DBTYPE *);
00205         virtual int get_transactional();
00206         virtual int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);
00207         virtual int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t);
00208         virtual int open(DbTxn *txnid,
00209             const char *, const char *subname, DBTYPE, u_int32_t, int);
00210         virtual int pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *data,
00211             u_int32_t flags);
00212         virtual int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
00213         virtual int remove(const char *, const char *, u_int32_t);
00214         virtual int rename(const char *, const char *, const char *, u_int32_t);
00215         virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
00216             db_free_fcn_type);
00217         virtual void set_app_private(void *);
00218         virtual int set_append_recno(int (*)(Db *, Dbt *, db_recno_t));
00219         virtual int set_bt_compare(bt_compare_fcn_type); /*deprecated*/
00220         virtual int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
00221         virtual int get_bt_minkey(u_int32_t *);
00222         virtual int set_bt_minkey(u_int32_t);
00223         virtual int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/
00224         virtual int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *));
00225         virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
00226         virtual int set_cachesize(u_int32_t, u_int32_t, int);
00227         virtual int set_dup_compare(dup_compare_fcn_type); /*deprecated*/
00228         virtual int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
00229         virtual int get_encrypt_flags(u_int32_t *);
00230         virtual int set_encrypt(const char *, u_int32_t);
00231         virtual void set_errcall(
00232             void (*)(const DbEnv *, const char *, const char *));
00233         virtual void get_errfile(FILE **);
00234         virtual void set_errfile(FILE *);
00235         virtual void get_errpfx(const char **);
00236         virtual void set_errpfx(const char *);
00237         virtual int set_feedback(void (*)(Db *, int, int));
00238         virtual int get_flags(u_int32_t *);
00239         virtual int set_flags(u_int32_t);
00240         virtual int get_h_ffactor(u_int32_t *);
00241         virtual int set_h_ffactor(u_int32_t);
00242         virtual int set_h_hash(h_hash_fcn_type); /*deprecated*/
00243         virtual int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t));
00244         virtual int get_h_nelem(u_int32_t *);
00245         virtual int set_h_nelem(u_int32_t);
00246         virtual int get_lorder(int *);
00247         virtual int set_lorder(int);
00248         virtual void set_msgcall(void (*)(const DbEnv *, const char *));
00249         virtual void get_msgfile(FILE **);
00250         virtual void set_msgfile(FILE *);
00251         virtual int get_pagesize(u_int32_t *);
00252         virtual int set_pagesize(u_int32_t);
00253         virtual int set_paniccall(void (*)(DbEnv *, int));
00254         virtual int get_re_delim(int *);
00255         virtual int set_re_delim(int);
00256         virtual int get_re_len(u_int32_t *);
00257         virtual int set_re_len(u_int32_t);
00258         virtual int get_re_pad(int *);
00259         virtual int set_re_pad(int);
00260         virtual int get_re_source(const char **);
00261         virtual int set_re_source(const char *);
00262         virtual int get_q_extentsize(u_int32_t *);
00263         virtual int set_q_extentsize(u_int32_t);
00264         virtual int stat(DbTxn *, void *sp, u_int32_t flags);
00265         virtual int stat_print(u_int32_t flags);
00266         virtual int sync(u_int32_t flags);
00267         virtual int truncate(DbTxn *, u_int32_t *, u_int32_t);
00268         virtual int upgrade(const char *name, u_int32_t flags);
00269         virtual int verify(const char *, const char *, __DB_STD(ostream) *,
00270                       u_int32_t);
00271 
00272         // These additional methods are not in the C interface, and
00273         // are only available for C++.
00274         //
00275         virtual __DB_STD(ostream) *get_error_stream();
00276         virtual void set_error_stream(__DB_STD(ostream) *);
00277         virtual __DB_STD(ostream) *get_message_stream();
00278         virtual void set_message_stream(__DB_STD(ostream) *);
00279 
00280         virtual DbEnv *get_env();
00281         virtual DbMpoolFile *get_mpf();
00282 
00283         virtual DB *get_DB()
00284         {
00285                 return imp_;
00286         }
00287 
00288         virtual const DB *get_const_DB() const
00289         {
00290                 return imp_;
00291         }
00292 
00293         static Db* get_Db(DB *db)
00294         {
00295                 return (Db *)db->api_internal;
00296         }
00297 
00298         static const Db* get_const_Db(const DB *db)
00299         {
00300                 return (const Db *)db->api_internal;
00301         }
00302 
00303 private:
00304         // no copying
00305         Db(const Db &);
00306         Db &operator = (const Db &);
00307 
00308         void cleanup();
00309         int initialize();
00310         int error_policy();
00311 
00312         // instance data
00313         DB *imp_;
00314         DbEnv *env_;
00315         DbMpoolFile *mpf_;
00316         int construct_error_;
00317         u_int32_t flags_;
00318         u_int32_t construct_flags_;
00319 
00320 public:
00321         // These are public only because they need to be called
00322         // via C callback functions.  They should never be used by
00323         // external users of this class.
00324         //
00325         int (*append_recno_callback_)(Db *, Dbt *, db_recno_t);
00326         int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *);
00327         int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *);
00328         size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *);
00329         int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *);
00330         void (*feedback_callback_)(Db *, int, int);
00331         u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t);
00332 };
00333 
00334 //
00335 // Cursor
00336 //
00337 class _exported Dbc : protected DBC
00338 {
00339         friend class Db;
00340 
00341 public:
00342         int close();
00343         int count(db_recno_t *countp, u_int32_t flags);
00344         int del(u_int32_t flags);
00345         int dup(Dbc** cursorp, u_int32_t flags);
00346         int get(Dbt* key, Dbt *data, u_int32_t flags);
00347         int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags);
00348         int put(Dbt* key, Dbt *data, u_int32_t flags);
00349 
00350 private:
00351         // No data is permitted in this class (see comment at top)
00352 
00353         // Note: use Db::cursor() to get pointers to a Dbc,
00354         // and call Dbc::close() rather than delete to release them.
00355         //
00356         Dbc();
00357         ~Dbc();
00358 
00359         // no copying
00360         Dbc(const Dbc &);
00361         Dbc &operator = (const Dbc &);
00362 };
00363 
00364 //
00365 // Berkeley DB environment class.  Provides functions for opening databases.
00366 // User of this library can use this class as a starting point for
00367 // developing a DB application - derive their application class from
00368 // this one, add application control logic.
00369 //
00370 // Note that if you use the default constructor, you must explicitly
00371 // call appinit() before any other db activity (e.g. opening files)
00372 //
00373 class _exported DbEnv
00374 {
00375         friend class Db;
00376         friend class DbLock;
00377         friend class DbMpoolFile;
00378 
00379 public:
00380         // After using this constructor, you can set any needed
00381         // parameters for the environment using the set_* methods.
00382         // Then call open() to finish initializing the environment
00383         // and attaching it to underlying files.
00384         //
00385         DbEnv(u_int32_t flags);
00386 
00387         virtual ~DbEnv();
00388 
00389         // These methods match those in the C interface.
00390         //
00391         virtual int close(u_int32_t);
00392         virtual int dbremove(DbTxn *txn, const char *name, const char *subdb,
00393             u_int32_t flags);
00394         virtual int dbrename(DbTxn *txn, const char *name, const char *subdb,
00395             const char *newname, u_int32_t flags);
00396         virtual void err(int, const char *, ...);
00397         virtual void errx(const char *, ...);
00398         virtual int failchk(u_int32_t);
00399         virtual int fileid_reset(const char *, u_int32_t);
00400         virtual void *get_app_private() const;
00401         virtual int get_home(const char **);
00402         virtual int get_open_flags(u_int32_t *);
00403         virtual int open(const char *, u_int32_t, int);
00404         virtual int remove(const char *, u_int32_t);
00405         virtual int stat_print(u_int32_t flags);
00406 
00407         virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
00408                               db_free_fcn_type);
00409         virtual void set_app_private(void *);
00410         virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
00411         virtual int set_cachesize(u_int32_t, u_int32_t, int);
00412         virtual int get_data_dirs(const char ***);
00413         virtual int set_data_dir(const char *);
00414         virtual int get_encrypt_flags(u_int32_t *);
00415         virtual int set_intermediate_dir(int, u_int32_t);
00416         virtual int set_isalive(int (*)(DbEnv *, pid_t, db_threadid_t));
00417         virtual int set_encrypt(const char *, u_int32_t);
00418         virtual void set_errcall(
00419                         void (*)(const DbEnv *, const char *, const char *));
00420         virtual void get_errfile(FILE **);
00421         virtual void set_errfile(FILE *);
00422         virtual void get_errpfx(const char **);
00423         virtual void set_errpfx(const char *);
00424         virtual int get_flags(u_int32_t *);
00425         virtual int set_flags(u_int32_t, int);
00426         virtual bool is_bigendian();
00427         virtual int lsn_reset(const char *, u_int32_t);
00428         virtual int set_feedback(void (*)(DbEnv *, int, int));
00429         virtual int get_lg_bsize(u_int32_t *);
00430         virtual int set_lg_bsize(u_int32_t);
00431         virtual int get_lg_dir(const char **);
00432         virtual int set_lg_dir(const char *);
00433         virtual int get_lg_filemode(int *);
00434         virtual int set_lg_filemode(int);
00435         virtual int get_lg_max(u_int32_t *);
00436         virtual int set_lg_max(u_int32_t);
00437         virtual int get_lg_regionmax(u_int32_t *);
00438         virtual int set_lg_regionmax(u_int32_t);
00439         virtual int get_lk_conflicts(const u_int8_t **, int *);
00440         virtual int set_lk_conflicts(u_int8_t *, int);
00441         virtual int get_lk_detect(u_int32_t *);
00442         virtual int set_lk_detect(u_int32_t);
00443         virtual int set_lk_max(u_int32_t);
00444         virtual int get_lk_max_lockers(u_int32_t *);
00445         virtual int set_lk_max_lockers(u_int32_t);
00446         virtual int get_lk_max_locks(u_int32_t *);
00447         virtual int set_lk_max_locks(u_int32_t);
00448         virtual int get_lk_max_objects(u_int32_t *);
00449         virtual int set_lk_max_objects(u_int32_t);
00450         virtual int get_mp_mmapsize(size_t *);
00451         virtual int set_mp_mmapsize(size_t);
00452         virtual int get_mp_max_openfd(int *);
00453         virtual int set_mp_max_openfd(int);
00454         virtual int get_mp_max_write(int *, int *);
00455         virtual int set_mp_max_write(int, int);
00456         virtual void set_msgcall(void (*)(const DbEnv *, const char *));
00457         virtual void get_msgfile(FILE **);
00458         virtual void set_msgfile(FILE *);
00459         virtual int set_paniccall(void (*)(DbEnv *, int));
00460         virtual int set_rpc_server(void *, char *, long, long, u_int32_t);
00461         virtual int get_shm_key(long *);
00462         virtual int set_shm_key(long);
00463         virtual int get_timeout(db_timeout_t *, u_int32_t);
00464         virtual int set_timeout(db_timeout_t, u_int32_t);
00465         virtual int get_tmp_dir(const char **);
00466         virtual int set_tmp_dir(const char *);
00467         virtual int get_tx_max(u_int32_t *);
00468         virtual int set_tx_max(u_int32_t);
00469         virtual int set_app_dispatch(int (*)(DbEnv *,
00470             Dbt *, DbLsn *, db_recops));
00471         virtual int get_tx_timestamp(time_t *);
00472         virtual int set_tx_timestamp(time_t *);
00473         virtual int get_verbose(u_int32_t which, int *);
00474         virtual int set_verbose(u_int32_t which, int);
00475 
00476         // Version information.  A static method so it can be obtained anytime.
00477         //
00478         static char *version(int *major, int *minor, int *patch);
00479 
00480         // Convert DB errors to strings
00481         static char *strerror(int);
00482 
00483         // If an error is detected and the error call function
00484         // or stream is set, a message is dispatched or printed.
00485         // If a prefix is set, each message is prefixed.
00486         //
00487         // You can use set_errcall() or set_errfile() above to control
00488         // error functionality.  Alternatively, you can call
00489         // set_error_stream() to force all errors to a C++ stream.
00490         // It is unwise to mix these approaches.
00491         //
00492         virtual __DB_STD(ostream) *get_error_stream();
00493         virtual void set_error_stream(__DB_STD(ostream) *);
00494         virtual __DB_STD(ostream) *get_message_stream();
00495         virtual void set_message_stream(__DB_STD(ostream) *);
00496 
00497         // used internally
00498         static void runtime_error(DbEnv *env, const char *caller, int err,
00499                                   int error_policy);
00500         static void runtime_error_dbt(DbEnv *env, const char *caller, Dbt *dbt,
00501                                   int error_policy);
00502         static void runtime_error_lock_get(DbEnv *env, const char *caller,
00503                                   int err, db_lockop_t op, db_lockmode_t mode,
00504                                   const Dbt *obj, DbLock lock, int index,
00505                                   int error_policy);
00506 
00507         // Lock functions
00508         //
00509         virtual int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted);
00510         virtual int lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
00511                      db_lockmode_t lock_mode, DbLock *lock);
00512         virtual int lock_id(u_int32_t *idp);
00513         virtual int lock_id_free(u_int32_t id);
00514         virtual int lock_put(DbLock *lock);
00515         virtual int lock_stat(DB_LOCK_STAT **statp, u_int32_t flags);
00516         virtual int lock_stat_print(u_int32_t flags);
00517         virtual int lock_vec(u_int32_t locker, u_int32_t flags,
00518                      DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);
00519 
00520         // Log functions
00521         //
00522         virtual int log_archive(char **list[], u_int32_t flags);
00523         static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1);
00524         virtual int log_cursor(DbLogc **cursorp, u_int32_t flags);
00525         virtual int log_file(DbLsn *lsn, char *namep, size_t len);
00526         virtual int log_flush(const DbLsn *lsn);
00527         virtual int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags);
00528         virtual int log_printf(DbTxn *, const char *, ...);
00529 
00530         virtual int log_stat(DB_LOG_STAT **spp, u_int32_t flags);
00531         virtual int log_stat_print(u_int32_t flags);
00532 
00533         // Mpool functions
00534         //
00535         virtual int memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags);
00536         virtual int memp_register(int ftype,
00537                           pgin_fcn_type pgin_fcn,
00538                           pgout_fcn_type pgout_fcn);
00539         virtual int memp_stat(DB_MPOOL_STAT
00540                       **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags);
00541         virtual int memp_stat_print(u_int32_t flags);
00542         virtual int memp_sync(DbLsn *lsn);
00543         virtual int memp_trickle(int pct, int *nwrotep);
00544 
00545         // Mpool functions
00546         //
00547         virtual int mutex_alloc(u_int32_t, db_mutex_t *);
00548         virtual int mutex_free(db_mutex_t);
00549         virtual int mutex_get_align(u_int32_t *);
00550         virtual int mutex_get_increment(u_int32_t *);
00551         virtual int mutex_get_max(u_int32_t *);
00552         virtual int mutex_get_tas_spins(u_int32_t *);
00553         virtual int mutex_lock(db_mutex_t);
00554         virtual int mutex_set_align(u_int32_t);
00555         virtual int mutex_set_increment(u_int32_t);
00556         virtual int mutex_set_max(u_int32_t);
00557         virtual int mutex_set_tas_spins(u_int32_t);
00558         virtual int mutex_stat(DB_MUTEX_STAT **, u_int32_t);
00559         virtual int mutex_stat_print(u_int32_t);
00560         virtual int mutex_unlock(db_mutex_t);
00561 
00562         // Transaction functions
00563         //
00564         virtual int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags);
00565         virtual int txn_checkpoint(u_int32_t kbyte, u_int32_t min,
00566                         u_int32_t flags);
00567         virtual int txn_recover(DbPreplist *preplist, long count,
00568                         long *retp, u_int32_t flags);
00569         virtual int txn_stat(DB_TXN_STAT **statp, u_int32_t flags);
00570         virtual int txn_stat_print(u_int32_t flags);
00571 
00572         // Replication functions
00573         //
00574         virtual int rep_elect(int, int, int, u_int32_t, int *, u_int32_t);
00575         virtual int rep_flush();
00576         virtual int rep_process_message(Dbt *, Dbt *, int *, DbLsn *);
00577         virtual int rep_start(Dbt *, u_int32_t);
00578         virtual int rep_stat(DB_REP_STAT **statp, u_int32_t flags);
00579         virtual int rep_stat_print(u_int32_t flags);
00580         virtual int get_rep_limit(u_int32_t *, u_int32_t *);
00581         virtual int set_rep_limit(u_int32_t, u_int32_t);
00582         virtual int set_rep_transport(int, int (*)(DbEnv *,
00583             const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t));
00584         virtual int set_rep_request(u_int32_t, u_int32_t);
00585         virtual int set_thread_count(u_int32_t);
00586         virtual int set_thread_id(void (*)(DbEnv *, pid_t *, db_threadid_t *));
00587         virtual int set_thread_id_string(char *(*)(DbEnv *, pid_t, db_threadid_t, char *));
00588         virtual int rep_set_config(u_int32_t which, int onoff);
00589         virtual int rep_get_config(u_int32_t which, int *onoffp);
00590         virtual int rep_sync(u_int32_t flags);
00591 
00592         // Conversion functions
00593         //
00594         virtual DB_ENV *get_DB_ENV()
00595         {
00596                 return imp_;
00597         }
00598 
00599         virtual const DB_ENV *get_const_DB_ENV() const
00600         {
00601                 return imp_;
00602         }
00603 
00604         static DbEnv* get_DbEnv(DB_ENV *dbenv)
00605         {
00606                 return dbenv ? (DbEnv *)dbenv->api1_internal : 0;
00607         }
00608 
00609         static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv)
00610         {
00611                 return dbenv ? (const DbEnv *)dbenv->api1_internal : 0;
00612         }
00613 
00614         // For internal use only.
00615         static DbEnv* wrap_DB_ENV(DB_ENV *dbenv);
00616 
00617         // These are public only because they need to be called
00618         // via C functions.  They should never be called by users
00619         // of this class.
00620         //
00621         static int _app_dispatch_intercept(DB_ENV *env, DBT *dbt, DB_LSN *lsn,
00622                                        db_recops op);
00623         static void _paniccall_intercept(DB_ENV *env, int errval);
00624         static void _feedback_intercept(DB_ENV *env, int opcode, int pct);
00625         static int _isalive_intercept(DB_ENV *env, pid_t pid,
00626             db_threadid_t thrid);
00627         static int _rep_send_intercept(DB_ENV *env, const DBT *cntrl,
00628             const DBT *data, const DB_LSN *lsn, int id, u_int32_t flags);
00629         static void _stream_error_function(const DB_ENV *env,
00630             const char *prefix, const char *message);
00631         static void _stream_message_function(const DB_ENV *env,
00632             const char *message);
00633         static void _thread_id_intercept(DB_ENV *env, pid_t *pidp,
00634             db_threadid_t *thridp);
00635         static char *_thread_id_string_intercept(DB_ENV *env, pid_t pid,
00636             db_threadid_t thrid, char *buf);
00637 
00638 private:
00639         void cleanup();
00640         int initialize(DB_ENV *env);
00641         int error_policy();
00642 
00643         // For internal use only.
00644         DbEnv(DB_ENV *, u_int32_t flags);
00645 
00646         // no copying
00647         DbEnv(const DbEnv &);
00648         void operator = (const DbEnv &);
00649 
00650         // instance data
00651         DB_ENV *imp_;
00652         int construct_error_;
00653         u_int32_t construct_flags_;
00654         __DB_STD(ostream) *error_stream_;
00655         __DB_STD(ostream) *message_stream_;
00656 
00657         int (*app_dispatch_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops);
00658         int (*isalive_callback_)(DbEnv *, pid_t, db_threadid_t);
00659         void (*error_callback_)(const DbEnv *, const char *, const char *);
00660         void (*feedback_callback_)(DbEnv *, int, int);
00661         void (*message_callback_)(const DbEnv *, const char *);
00662         void (*paniccall_callback_)(DbEnv *, int);
00663         int (*rep_send_callback_)(DbEnv *, const Dbt *, const Dbt *,
00664             const DbLsn *, int, u_int32_t);
00665         void (*thread_id_callback_)(DbEnv *, pid_t *, db_threadid_t *);
00666         char *(*thread_id_string_callback_)(DbEnv *, pid_t, db_threadid_t,
00667             char *);
00668 };
00669 
00670 //
00671 // Lock
00672 //
00673 class _exported DbLock
00674 {
00675         friend class DbEnv;
00676 
00677 public:
00678         DbLock();
00679         DbLock(const DbLock &);
00680         DbLock &operator = (const DbLock &);
00681 
00682 protected:
00683         // We can add data to this class if needed
00684         // since its contained class is not allocated by db.
00685         // (see comment at top)
00686 
00687         DbLock(DB_LOCK);
00688         DB_LOCK lock_;
00689 };
00690 
00691 //
00692 // Log cursor
00693 //
00694 class _exported DbLogc : protected DB_LOGC
00695 {
00696         friend class DbEnv;
00697 
00698 public:
00699         int close(u_int32_t _flags);
00700         int get(DbLsn *lsn, Dbt *data, u_int32_t _flags);
00701 
00702 private:
00703         // No data is permitted in this class (see comment at top)
00704 
00705         // Note: use Db::cursor() to get pointers to a Dbc,
00706         // and call Dbc::close() rather than delete to release them.
00707         //
00708         DbLogc();
00709         ~DbLogc();
00710 
00711         // no copying
00712         DbLogc(const Dbc &);
00713         DbLogc &operator = (const Dbc &);
00714 };
00715 
00716 //
00717 // Log sequence number
00718 //
00719 class _exported DbLsn : public DB_LSN
00720 {
00721         friend class DbEnv;          // friendship needed to cast to base class
00722         friend class DbLogc;         // friendship needed to cast to base class
00723 };
00724 
00725 //
00726 // Memory pool file
00727 //
00728 class _exported DbMpoolFile
00729 {
00730         friend class DbEnv;
00731         friend class Db;
00732 
00733 public:
00734         int close(u_int32_t flags);
00735         int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep);
00736         int open(const char *file, u_int32_t flags, int mode, size_t pagesize);
00737         int get_transactional(void);
00738         int put(void *pgaddr, u_int32_t flags);
00739         int set(void *pgaddr, u_int32_t flags);
00740         int get_clear_len(u_int32_t *len);
00741         int set_clear_len(u_int32_t len);
00742         int get_fileid(u_int8_t *fileid);
00743         int set_fileid(u_int8_t *fileid);
00744         int get_flags(u_int32_t *flagsp);
00745         int set_flags(u_int32_t flags, int onoff);
00746         int get_ftype(int *ftype);
00747         int set_ftype(int ftype);
00748         int get_lsn_offset(int32_t *offsetp);
00749         int set_lsn_offset(int32_t offset);
00750         int get_maxsize(u_int32_t *gbytes, u_int32_t *bytes);
00751         int set_maxsize(u_int32_t gbytes, u_int32_t bytes);
00752         int get_pgcookie(DBT *dbt);
00753         int set_pgcookie(DBT *dbt);
00754         int get_priority(DB_CACHE_PRIORITY *priorityp);
00755         int set_priority(DB_CACHE_PRIORITY priority);
00756         int sync();
00757 
00758         virtual DB_MPOOLFILE *get_DB_MPOOLFILE()
00759         {
00760                 return imp_;
00761         }
00762 
00763         virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const
00764         {
00765                 return imp_;
00766         }
00767 
00768 private:
00769         DB_MPOOLFILE *imp_;
00770 
00771         // We can add data to this class if needed
00772         // since it is implemented via a pointer.
00773         // (see comment at top)
00774 
00775         // Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile,
00776         // and call DbMpoolFile::close() rather than delete to release them.
00777         //
00778         DbMpoolFile();
00779 
00780         // Shut g++ up.
00781 protected:
00782         virtual ~DbMpoolFile();
00783 
00784 private:
00785         // no copying
00786         DbMpoolFile(const DbMpoolFile &);
00787         void operator = (const DbMpoolFile &);
00788 };
00789 
00790 //
00791 // This is filled in and returned by the DbEnv::txn_recover() method.
00792 //
00793 class _exported DbPreplist
00794 {
00795 public:
00796         DbTxn *txn;
00797         u_int8_t gid[DB_XIDDATASIZE];
00798 };
00799 
00800 //
00801 // A sequence record in a database
00802 //
00803 class _exported DbSequence
00804 {
00805 public:
00806         DbSequence(Db *db, u_int32_t flags);
00807         virtual ~DbSequence();
00808 
00809         int open(DbTxn *txnid, Dbt *key, u_int32_t flags);
00810         int initial_value(db_seq_t value);
00811         int close(u_int32_t flags);
00812         int remove(DbTxn *txnid, u_int32_t flags);
00813         int stat(DB_SEQUENCE_STAT **sp, u_int32_t flags);
00814         int stat_print(u_int32_t flags);
00815 
00816         int get(DbTxn *txnid, int32_t delta, db_seq_t *retp, u_int32_t flags);
00817         int get_cachesize(int32_t *sizep);
00818         int set_cachesize(int32_t size);
00819         int get_flags(u_int32_t *flagsp);
00820         int set_flags(u_int32_t flags);
00821         int get_range(db_seq_t *minp, db_seq_t *maxp);
00822         int set_range(db_seq_t min, db_seq_t max);
00823 
00824         Db *get_db();
00825         Dbt *get_key();
00826 
00827         virtual DB_SEQUENCE *get_DB_SEQUENCE()
00828         {
00829                 return imp_;
00830         }
00831 
00832         virtual const DB_SEQUENCE *get_const_DB_SEQUENCE() const
00833         {
00834                 return imp_;
00835         }
00836 
00837         static DbSequence* get_DbSequence(DB_SEQUENCE *seq)
00838         {
00839                 return (DbSequence *)seq->api_internal;
00840         }
00841 
00842         static const DbSequence* get_const_DbSequence(const DB_SEQUENCE *seq)
00843         {
00844                 return (const DbSequence *)seq->api_internal;
00845         }
00846 
00847         // For internal use only.
00848         static DbSequence* wrap_DB_SEQUENCE(DB_SEQUENCE *seq);
00849 
00850 private:
00851         DbSequence(DB_SEQUENCE *seq);
00852         // no copying
00853         DbSequence(const DbSequence &);
00854         DbSequence &operator = (const DbSequence &);
00855 
00856         DB_SEQUENCE *imp_;
00857         DBT key_;
00858 };
00859 
00860 //
00861 // Transaction
00862 //
00863 class _exported DbTxn
00864 {
00865         friend class DbEnv;
00866 
00867 public:
00868         int abort();
00869         int commit(u_int32_t flags);
00870         int discard(u_int32_t flags);
00871         u_int32_t id();
00872         int get_name(const char **namep);
00873         int prepare(u_int8_t *gid);
00874         int set_name(const char *name);
00875         int set_timeout(db_timeout_t timeout, u_int32_t flags);
00876 
00877         virtual DB_TXN *get_DB_TXN()
00878         {
00879                 return imp_;
00880         }
00881 
00882         virtual const DB_TXN *get_const_DB_TXN() const
00883         {
00884                 return imp_;
00885         }
00886 
00887         static DbTxn* get_DbTxn(DB_TXN *txn)
00888         {
00889                 return (DbTxn *)txn->api_internal;
00890         }
00891 
00892         static const DbTxn* get_const_DbTxn(const DB_TXN *txn)
00893         {
00894                 return (const DbTxn *)txn->api_internal;
00895         }
00896 
00897         // For internal use only.
00898         static DbTxn* wrap_DB_TXN(DB_TXN *txn);
00899 
00900 private:
00901         DB_TXN *imp_;
00902 
00903         // We can add data to this class if needed
00904         // since it is implemented via a pointer.
00905         // (see comment at top)
00906 
00907         // Note: use DbEnv::txn_begin() to get pointers to a DbTxn,
00908         // and call DbTxn::abort() or DbTxn::commit rather than
00909         // delete to release them.
00910         //
00911         DbTxn();
00912         // For internal use only.
00913         DbTxn(DB_TXN *txn);
00914         virtual ~DbTxn();
00915 
00916         // no copying
00917         DbTxn(const DbTxn &);
00918         void operator = (const DbTxn &);
00919 };
00920 
00921 //
00922 // A chunk of data, maybe a key or value.
00923 //
00924 class _exported Dbt : private DBT
00925 {
00926         friend class Db;
00927         friend class Dbc;
00928         friend class DbEnv;
00929         friend class DbLogc;
00930         friend class DbSequence;
00931 
00932 public:
00933         // key/data
00934         void *get_data() const                 { return data; }
00935         void set_data(void *value)             { data = value; }
00936 
00937         // key/data length
00938         u_int32_t get_size() const             { return size; }
00939         void set_size(u_int32_t value)         { size = value; }
00940 
00941         // RO: length of user buffer.
00942         u_int32_t get_ulen() const             { return ulen; }
00943         void set_ulen(u_int32_t value)         { ulen = value; }
00944 
00945         // RO: get/put record length.
00946         u_int32_t get_dlen() const             { return dlen; }
00947         void set_dlen(u_int32_t value)         { dlen = value; }
00948 
00949         // RO: get/put record offset.
00950         u_int32_t get_doff() const             { return doff; }
00951         void set_doff(u_int32_t value)         { doff = value; }
00952 
00953         // flags
00954         u_int32_t get_flags() const            { return flags; }
00955         void set_flags(u_int32_t value)        { flags = value; }
00956 
00957         // Conversion functions
00958         DBT *get_DBT()                         { return (DBT *)this; }
00959         const DBT *get_const_DBT() const       { return (const DBT *)this; }
00960 
00961         static Dbt* get_Dbt(DBT *dbt)          { return (Dbt *)dbt; }
00962         static const Dbt* get_const_Dbt(const DBT *dbt)
00963                                                { return (const Dbt *)dbt; }
00964 
00965         Dbt(void *data, u_int32_t size);
00966         Dbt();
00967         ~Dbt();
00968         Dbt(const Dbt &);
00969         Dbt &operator = (const Dbt &);
00970 
00971 private:
00972         // Note: no extra data appears in this class (other than
00973         // inherited from DBT) since we need DBT and Dbt objects
00974         // to have interchangable pointers.
00975         //
00976         // When subclassing this class, remember that callback
00977         // methods like bt_compare, bt_prefix, dup_compare may
00978         // internally manufacture DBT objects (which later are
00979         // cast to Dbt), so such callbacks might receive objects
00980         // not of your subclassed type.
00981 };
00982 
00985 //
00986 // multiple key/data/reco iterator classes
00987 //
00988 
00989 // DbMultipleIterator is a shared private base class for the three types
00990 // of bulk-return Iterator;  it should never be instantiated directly,
00991 // but it handles the functionality shared by its subclasses.
00992 class _exported DbMultipleIterator
00993 {
00994 public:
00995         DbMultipleIterator(const Dbt &dbt);
00996 protected:
00997         u_int8_t *data_;
00998         u_int32_t *p_;
00999 };
01000 
01001 class _exported DbMultipleKeyDataIterator : private DbMultipleIterator
01002 {
01003 public:
01004         DbMultipleKeyDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
01005         bool next(Dbt &key, Dbt &data);
01006 };
01007 
01008 class _exported DbMultipleRecnoDataIterator : private DbMultipleIterator
01009 {
01010 public:
01011         DbMultipleRecnoDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
01012         bool next(db_recno_t &recno, Dbt &data);
01013 };
01014 
01015 class _exported DbMultipleDataIterator : private DbMultipleIterator
01016 {
01017 public:
01018         DbMultipleDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
01019         bool next(Dbt &data);
01020 };
01021 
01024 //
01025 // Exception classes
01026 //
01027 
01028 // Almost any error in the DB library throws a DbException.
01029 // Every exception should be considered an abnormality
01030 // (e.g. bug, misuse of DB, file system error).
01031 //
01032 class _exported DbException : public __DB_STD(exception)
01033 {
01034 public:
01035         virtual ~DbException() throw();
01036         DbException(int err);
01037         DbException(const char *description);
01038         DbException(const char *description, int err);
01039         DbException(const char *prefix, const char *description, int err);
01040         int get_errno() const;
01041         virtual const char *what() const throw();
01042         DbEnv *get_env() const;
01043         void set_env(DbEnv *env);
01044 
01045         DbException(const DbException &);
01046         DbException &operator = (const DbException &);
01047 
01048 private:
01049         void describe(const char *prefix, const char *description);
01050 
01051         char *what_;
01052         int err_;                   // errno
01053         DbEnv *env_;
01054 };
01055 
01056 //
01057 // A specific sort of exception that occurs when
01058 // an operation is aborted to resolve a deadlock.
01059 //
01060 class _exported DbDeadlockException : public DbException
01061 {
01062 public:
01063         virtual ~DbDeadlockException() throw();
01064         DbDeadlockException(const char *description);
01065 
01066         DbDeadlockException(const DbDeadlockException &);
01067         DbDeadlockException &operator = (const DbDeadlockException &);
01068 };
01069 
01070 //
01071 // A specific sort of exception that occurs when
01072 // a lock is not granted, e.g. by lock_get or lock_vec.
01073 // Note that the Dbt is only live as long as the Dbt used
01074 // in the offending call.
01075 //
01076 class _exported DbLockNotGrantedException : public DbException
01077 {
01078 public:
01079         virtual ~DbLockNotGrantedException() throw();
01080         DbLockNotGrantedException(const char *prefix, db_lockop_t op,
01081             db_lockmode_t mode, const Dbt *obj, const DbLock lock, int index);
01082         DbLockNotGrantedException(const char *description);
01083 
01084         DbLockNotGrantedException(const DbLockNotGrantedException &);
01085         DbLockNotGrantedException &operator =
01086             (const DbLockNotGrantedException &);
01087 
01088         db_lockop_t get_op() const;
01089         db_lockmode_t get_mode() const;
01090         const Dbt* get_obj() const;
01091         DbLock *get_lock() const;
01092         int get_index() const;
01093 
01094 private:
01095         db_lockop_t op_;
01096         db_lockmode_t mode_;
01097         const Dbt *obj_;
01098         DbLock *lock_;
01099         int index_;
01100 };
01101 
01102 //
01103 // A specific sort of exception that occurs when
01104 // user declared memory is insufficient in a Dbt.
01105 //
01106 class _exported DbMemoryException : public DbException
01107 {
01108 public:
01109         virtual ~DbMemoryException() throw();
01110         DbMemoryException(Dbt *dbt);
01111         DbMemoryException(const char *prefix, Dbt *dbt);
01112 
01113         DbMemoryException(const DbMemoryException &);
01114         DbMemoryException &operator = (const DbMemoryException &);
01115 
01116         Dbt *get_dbt() const;
01117 private:
01118         Dbt *dbt_;
01119 };
01120 
01121 //
01122 // A specific sort of exception that occurs when a change of replication
01123 // master requires that all handles be re-opened.
01124 //
01125 class _exported DbRepHandleDeadException : public DbException
01126 {
01127 public:
01128         virtual ~DbRepHandleDeadException() throw();
01129         DbRepHandleDeadException(const char *description);
01130 
01131         DbRepHandleDeadException(const DbRepHandleDeadException &);
01132         DbRepHandleDeadException &operator = (const DbRepHandleDeadException &);
01133 };
01134 
01135 //
01136 // A specific sort of exception that occurs when
01137 // recovery is required before continuing DB activity.
01138 //
01139 class _exported DbRunRecoveryException : public DbException
01140 {
01141 public:
01142         virtual ~DbRunRecoveryException() throw();
01143         DbRunRecoveryException(const char *description);
01144 
01145         DbRunRecoveryException(const DbRunRecoveryException &);
01146         DbRunRecoveryException &operator = (const DbRunRecoveryException &);
01147 };
01148 #endif /* !_DB_CXX_H_ */

Generated on Sun Dec 25 12:14:17 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2