1/* DO NOT EDIT: automatically built by dist/s_vxworks. */
2/*-
3 * See the file LICENSE for redistribution information.
4 *
5 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
6 *
7 * $Id: db_cxx.in,v 12.49 2008/01/12 13:42:37 bostic Exp $
8 */
9
10#ifndef _DB_CXX_H_
11#define	_DB_CXX_H_
12//
13// C++ assumptions:
14//
15// To ensure portability to many platforms, both new and old, we make
16// few assumptions about the C++ compiler and library.  For example,
17// we do not expect STL, templates or namespaces to be available.  The
18// "newest" C++ feature used is exceptions, which are used liberally
19// to transmit error information.  Even the use of exceptions can be
20// disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags
21// with the DbEnv or Db constructor.
22//
23// C++ naming conventions:
24//
25//  - All top level class names start with Db.
26//  - All class members start with lower case letter.
27//  - All private data members are suffixed with underscore.
28//  - Use underscores to divide names into multiple words.
29//  - Simple data accessors are named with get_ or set_ prefix.
30//  - All method names are taken from names of functions in the C
31//    layer of db (usually by dropping a prefix like "db_").
32//    These methods have the same argument types and order,
33//    other than dropping the explicit arg that acts as "this".
34//
35// As a rule, each DbFoo object has exactly one underlying DB_FOO struct
36// (defined in db.h) associated with it.  In some cases, we inherit directly
37// from the DB_FOO structure to make this relationship explicit.  Often,
38// the underlying C layer allocates and deallocates these structures, so
39// there is no easy way to add any data to the DbFoo class.  When you see
40// a comment about whether data is permitted to be added, this is what
41// is going on.  Of course, if we need to add data to such C++ classes
42// in the future, we will arrange to have an indirect pointer to the
43// DB_FOO struct (as some of the classes already have).
44//
45
46////////////////////////////////////////////////////////////////
47////////////////////////////////////////////////////////////////
48//
49// Forward declarations
50//
51
52#include <stdarg.h>
53
54#define	HAVE_CXX_STDHEADERS 1
55#ifdef HAVE_CXX_STDHEADERS
56#include <iostream>
57#include <exception>
58#define	__DB_STD(x)	std::x
59#else
60#include <iostream.h>
61#include <exception.h>
62#define	__DB_STD(x)	x
63#endif
64
65#include "db.h"
66
67class Db;                                        // forward
68class Dbc;                                       // forward
69class DbEnv;                                     // forward
70class DbInfo;                                    // forward
71class DbLock;                                    // forward
72class DbLogc;                                    // forward
73class DbLsn;                                     // forward
74class DbMpoolFile;                               // forward
75class DbPreplist;                                // forward
76class DbSequence;                                // forward
77class Dbt;                                       // forward
78class DbTxn;                                     // forward
79
80class DbMultipleIterator;                        // forward
81class DbMultipleKeyDataIterator;                 // forward
82class DbMultipleRecnoDataIterator;               // forward
83class DbMultipleDataIterator;                    // forward
84
85class DbException;                               // forward
86class DbDeadlockException;                       // forward
87class DbLockNotGrantedException;                 // forward
88class DbMemoryException;                         // forward
89class DbRepHandleDeadException;                  // forward
90class DbRunRecoveryException;                    // forward
91
92////////////////////////////////////////////////////////////////
93////////////////////////////////////////////////////////////////
94//
95// Turn off inappropriate compiler warnings
96//
97
98#ifdef _MSC_VER
99
100// These are level 4 warnings that are explicitly disabled.
101// With Visual C++, by default you do not see above level 3 unless
102// you use /W4.  But we like to compile with the highest level
103// warnings to catch other errors.
104//
105// 4201: nameless struct/union
106//       triggered by standard include file <winnt.h>
107//
108// 4514: unreferenced inline function has been removed
109//       certain include files in MSVC define methods that are not called
110//
111#pragma warning(push)
112#pragma warning(disable: 4201 4514)
113
114#endif
115
116////////////////////////////////////////////////////////////////
117////////////////////////////////////////////////////////////////
118//
119// Mechanisms for declaring classes
120//
121
122//
123// Every class defined in this file has an _exported next to the class name.
124// This is needed for WinTel machines so that the class methods can
125// be exported or imported in a DLL as appropriate.  Users of the DLL
126// use the define DB_USE_DLL.  When the DLL is built, DB_CREATE_DLL
127// must be defined.
128//
129#if defined(_MSC_VER)
130
131#  if defined(DB_CREATE_DLL)
132#    define _exported __declspec(dllexport)      // creator of dll
133#  elif defined(DB_USE_DLL)
134#    define _exported __declspec(dllimport)      // user of dll
135#  else
136#    define _exported                            // static lib creator or user
137#  endif
138
139#else /* _MSC_VER */
140
141#  define _exported
142
143#endif /* _MSC_VER */
144
145// Some interfaces can be customized by allowing users to define
146// callback functions.  For performance and logistical reasons, some
147// callback functions must be declared in extern "C" blocks.  For others,
148// we allow you to declare the callbacks in C++ or C (or an extern "C"
149// block) as you wish.  See the set methods for the callbacks for
150// the choices.
151//
152extern "C" {
153	typedef void * (*db_malloc_fcn_type)
154		(size_t);
155	typedef void * (*db_realloc_fcn_type)
156		(void *, size_t);
157	typedef void (*db_free_fcn_type)
158		(void *);
159	typedef int (*bt_compare_fcn_type)          /*C++ version available*/
160		(DB *, const DBT *, const DBT *);
161	typedef size_t (*bt_prefix_fcn_type)        /*C++ version available*/
162		(DB *, const DBT *, const DBT *);
163	typedef int (*dup_compare_fcn_type)         /*C++ version available*/
164		(DB *, const DBT *, const DBT *);
165	typedef int (*h_compare_fcn_type)          /*C++ version available*/
166		(DB *, const DBT *, const DBT *);
167	typedef u_int32_t (*h_hash_fcn_type)        /*C++ version available*/
168		(DB *, const void *, u_int32_t);
169	typedef int (*pgin_fcn_type)
170		(DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
171	typedef int (*pgout_fcn_type)
172		(DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
173}
174
175//
176// Represents a database table = a set of keys with associated values.
177//
178class _exported Db
179{
180	friend class DbEnv;
181
182public:
183	Db(DbEnv*, u_int32_t);      // Create a Db object.
184	virtual ~Db();              // Calls close() if the user hasn't.
185
186	// These methods exactly match those in the C interface.
187	//
188	virtual int associate(DbTxn *txn, Db *secondary, int (*callback)
189	    (Db *, const Dbt *, const Dbt *, Dbt *), u_int32_t flags);
190	virtual int close(u_int32_t flags);
191	virtual int compact(DbTxn *txnid, Dbt *start,
192	    Dbt *stop, DB_COMPACT *c_data, u_int32_t flags, Dbt *end);
193	virtual int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
194	virtual int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
195	virtual void err(int, const char *, ...);
196	virtual void errx(const char *, ...);
197	virtual int exists(DbTxn *txnid, Dbt *key, u_int32_t flags);
198	virtual int fd(int *fdp);
199	virtual int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
200	virtual int get_bt_minkey(u_int32_t *);
201	virtual int get_byteswapped(int *);
202	virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
203	virtual int get_dbname(const char **, const char **);
204	virtual int get_encrypt_flags(u_int32_t *);
205	virtual void get_errfile(FILE **);
206	virtual void get_errpfx(const char **);
207	virtual int get_flags(u_int32_t *);
208	virtual int get_h_ffactor(u_int32_t *);
209	virtual int get_h_nelem(u_int32_t *);
210	virtual int get_lorder(int *);
211	virtual void get_msgfile(FILE **);
212	virtual int get_multiple();
213	virtual int get_open_flags(u_int32_t *);
214	virtual int get_pagesize(u_int32_t *);
215	virtual int get_priority(DB_CACHE_PRIORITY *);
216	virtual int get_q_extentsize(u_int32_t *);
217	virtual int get_re_delim(int *);
218	virtual int get_re_len(u_int32_t *);
219	virtual int get_re_pad(int *);
220	virtual int get_re_source(const char **);
221	virtual int get_transactional();
222	virtual int get_type(DBTYPE *);
223	virtual int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);
224	virtual int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t);
225	virtual int open(DbTxn *txnid,
226	    const char *, const char *subname, DBTYPE, u_int32_t, int);
227	virtual int pget(DbTxn *txnid,
228	    Dbt *key, Dbt *pkey, Dbt *data, u_int32_t flags);
229	virtual int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
230	virtual int remove(const char *, const char *, u_int32_t);
231	virtual int rename(const char *, const char *, const char *, u_int32_t);
232	virtual int set_alloc(
233	    db_malloc_fcn_type, db_realloc_fcn_type, db_free_fcn_type);
234	virtual void set_app_private(void *);
235	virtual int set_append_recno(int (*)(Db *, Dbt *, db_recno_t));
236	virtual int set_bt_compare(bt_compare_fcn_type); /*deprecated*/
237	virtual int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
238	virtual int set_bt_minkey(u_int32_t);
239	virtual int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/
240	virtual int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *));
241	virtual int set_cachesize(u_int32_t, u_int32_t, int);
242	virtual int set_dup_compare(dup_compare_fcn_type); /*deprecated*/
243	virtual int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
244	virtual int set_encrypt(const char *, u_int32_t);
245	virtual void set_errcall(
246	    void (*)(const DbEnv *, const char *, const char *));
247	virtual void set_errfile(FILE *);
248	virtual void set_errpfx(const char *);
249	virtual int set_feedback(void (*)(Db *, int, int));
250	virtual int set_flags(u_int32_t);
251	virtual int set_h_compare(h_compare_fcn_type); /*deprecated*/
252	virtual int set_h_compare(int (*)(Db *, const Dbt *, const Dbt *));
253	virtual int set_h_ffactor(u_int32_t);
254	virtual int set_h_hash(h_hash_fcn_type); /*deprecated*/
255	virtual int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t));
256	virtual int set_h_nelem(u_int32_t);
257	virtual int set_lorder(int);
258	virtual void set_msgcall(void (*)(const DbEnv *, const char *));
259	virtual void set_msgfile(FILE *);
260	virtual int set_pagesize(u_int32_t);
261	virtual int set_paniccall(void (*)(DbEnv *, int));
262	virtual int set_priority(DB_CACHE_PRIORITY);
263	virtual int set_q_extentsize(u_int32_t);
264	virtual int set_re_delim(int);
265	virtual int set_re_len(u_int32_t);
266	virtual int set_re_pad(int);
267	virtual int set_re_source(const char *);
268	virtual int stat(DbTxn *, void *sp, u_int32_t flags);
269	virtual int stat_print(u_int32_t flags);
270	virtual int sync(u_int32_t flags);
271	virtual int truncate(DbTxn *, u_int32_t *, u_int32_t);
272	virtual int upgrade(const char *name, u_int32_t flags);
273	virtual int verify(
274	    const char *, const char *, __DB_STD(ostream) *, u_int32_t);
275
276	// These additional methods are not in the C interface, and
277	// are only available for C++.
278	//
279	virtual void *get_app_private() const;
280	virtual __DB_STD(ostream) *get_error_stream();
281	virtual void set_error_stream(__DB_STD(ostream) *);
282	virtual __DB_STD(ostream) *get_message_stream();
283	virtual void set_message_stream(__DB_STD(ostream) *);
284
285	virtual DbEnv *get_env();
286	virtual DbMpoolFile *get_mpf();
287
288	virtual ENV *get_ENV()
289	{
290		return imp_->env;
291	}
292
293	virtual DB *get_DB()
294	{
295		return imp_;
296	}
297
298	virtual const DB *get_const_DB() const
299	{
300		return imp_;
301	}
302
303	static Db* get_Db(DB *db)
304	{
305		return (Db *)db->api_internal;
306	}
307
308	static const Db* get_const_Db(const DB *db)
309	{
310		return (const Db *)db->api_internal;
311	}
312
313private:
314	// no copying
315	Db(const Db &);
316	Db &operator = (const Db &);
317
318	void cleanup();
319	int initialize();
320	int error_policy();
321
322	// instance data
323	DB *imp_;
324	DbEnv *dbenv_;
325	DbMpoolFile *mpf_;
326	int construct_error_;
327	u_int32_t flags_;
328	u_int32_t construct_flags_;
329
330public:
331	// These are public only because they need to be called
332	// via C callback functions.  They should never be used by
333	// external users of this class.
334	//
335	int (*append_recno_callback_)(Db *, Dbt *, db_recno_t);
336	int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *);
337	int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *);
338	size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *);
339	int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *);
340	void (*feedback_callback_)(Db *, int, int);
341	int (*h_compare_callback_)(Db *, const Dbt *, const Dbt *);
342	u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t);
343};
344
345//
346// Cursor
347//
348class _exported Dbc : protected DBC
349{
350	friend class Db;
351
352public:
353	int close();
354	int count(db_recno_t *countp, u_int32_t flags);
355	int del(u_int32_t flags);
356	int dup(Dbc** cursorp, u_int32_t flags);
357	int get(Dbt* key, Dbt *data, u_int32_t flags);
358	int get_priority(DB_CACHE_PRIORITY *priorityp);
359	int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags);
360	int put(Dbt* key, Dbt *data, u_int32_t flags);
361	int set_priority(DB_CACHE_PRIORITY priority);
362
363private:
364	// No data is permitted in this class (see comment at top)
365
366	// Note: use Db::cursor() to get pointers to a Dbc,
367	// and call Dbc::close() rather than delete to release them.
368	//
369	Dbc();
370	~Dbc();
371
372	// no copying
373	Dbc(const Dbc &);
374	Dbc &operator = (const Dbc &);
375};
376
377//
378// Berkeley DB environment class.  Provides functions for opening databases.
379// User of this library can use this class as a starting point for
380// developing a DB application - derive their application class from
381// this one, add application control logic.
382//
383// Note that if you use the default constructor, you must explicitly
384// call appinit() before any other db activity (e.g. opening files)
385//
386class _exported DbEnv
387{
388	friend class Db;
389	friend class DbLock;
390	friend class DbMpoolFile;
391
392public:
393	// After using this constructor, you can set any needed
394	// parameters for the environment using the set_* methods.
395	// Then call open() to finish initializing the environment
396	// and attaching it to underlying files.
397	//
398	DbEnv(u_int32_t flags);
399
400	virtual ~DbEnv();
401
402	// These methods match those in the C interface.
403	//
404	virtual int cdsgroup_begin(DbTxn **tid);
405	virtual int close(u_int32_t);
406	virtual int dbremove(DbTxn *txn, const char *name, const char *subdb,
407	    u_int32_t flags);
408	virtual int dbrename(DbTxn *txn, const char *name, const char *subdb,
409	    const char *newname, u_int32_t flags);
410	virtual void err(int, const char *, ...);
411	virtual void errx(const char *, ...);
412	virtual int failchk(u_int32_t);
413	virtual int fileid_reset(const char *, u_int32_t);
414	virtual void *get_app_private() const;
415	virtual int get_home(const char **);
416	virtual int get_open_flags(u_int32_t *);
417	virtual int open(const char *, u_int32_t, int);
418	virtual int remove(const char *, u_int32_t);
419	virtual int stat_print(u_int32_t flags);
420
421	virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
422			      db_free_fcn_type);
423	virtual void set_app_private(void *);
424	virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
425	virtual int set_cachesize(u_int32_t, u_int32_t, int);
426	virtual int get_cache_max(u_int32_t *, u_int32_t *);
427	virtual int set_cache_max(u_int32_t, u_int32_t);
428	virtual int get_data_dirs(const char ***);
429	virtual int set_data_dir(const char *);
430	virtual int get_encrypt_flags(u_int32_t *);
431	virtual int get_intermediate_dir_mode(const char **);
432	virtual int set_intermediate_dir_mode(const char *);
433	virtual int set_isalive(
434			int (*)(DbEnv *, pid_t, db_threadid_t, u_int32_t));
435	virtual int set_encrypt(const char *, u_int32_t);
436	virtual void set_errcall(
437			void (*)(const DbEnv *, const char *, const char *));
438	virtual void get_errfile(FILE **);
439	virtual void set_errfile(FILE *);
440	virtual void get_errpfx(const char **);
441	virtual void set_errpfx(const char *);
442	virtual int set_event_notify(void (*)(DbEnv *, u_int32_t, void *));
443	virtual int get_flags(u_int32_t *);
444	virtual int set_flags(u_int32_t, int);
445	virtual bool is_bigendian();
446	virtual int lsn_reset(const char *, u_int32_t);
447	virtual int set_feedback(void (*)(DbEnv *, int, int));
448	virtual int get_lg_bsize(u_int32_t *);
449	virtual int set_lg_bsize(u_int32_t);
450	virtual int get_lg_dir(const char **);
451	virtual int set_lg_dir(const char *);
452	virtual int get_lg_filemode(int *);
453	virtual int set_lg_filemode(int);
454	virtual int get_lg_max(u_int32_t *);
455	virtual int set_lg_max(u_int32_t);
456	virtual int get_lg_regionmax(u_int32_t *);
457	virtual int set_lg_regionmax(u_int32_t);
458	virtual int get_lk_conflicts(const u_int8_t **, int *);
459	virtual int set_lk_conflicts(u_int8_t *, int);
460	virtual int get_lk_detect(u_int32_t *);
461	virtual int set_lk_detect(u_int32_t);
462	virtual int get_lk_max_lockers(u_int32_t *);
463	virtual int set_lk_max_lockers(u_int32_t);
464	virtual int get_lk_max_locks(u_int32_t *);
465	virtual int set_lk_max_locks(u_int32_t);
466	virtual int get_lk_max_objects(u_int32_t *);
467	virtual int set_lk_max_objects(u_int32_t);
468	virtual int get_mp_mmapsize(size_t *);
469	virtual int set_mp_mmapsize(size_t);
470	virtual int get_mp_max_openfd(int *);
471	virtual int set_mp_max_openfd(int);
472	virtual int get_mp_max_write(int *, db_timeout_t *);
473	virtual int set_mp_max_write(int, db_timeout_t);
474	virtual void set_msgcall(void (*)(const DbEnv *, const char *));
475	virtual void get_msgfile(FILE **);
476	virtual void set_msgfile(FILE *);
477	virtual int set_paniccall(void (*)(DbEnv *, int));
478	virtual int set_rpc_server(void *, char *, long, long, u_int32_t);
479	virtual int get_shm_key(long *);
480	virtual int set_shm_key(long);
481	virtual int get_timeout(db_timeout_t *, u_int32_t);
482	virtual int set_timeout(db_timeout_t, u_int32_t);
483	virtual int get_tmp_dir(const char **);
484	virtual int set_tmp_dir(const char *);
485	virtual int get_tx_max(u_int32_t *);
486	virtual int set_tx_max(u_int32_t);
487	virtual int set_app_dispatch(int (*)(DbEnv *,
488	    Dbt *, DbLsn *, db_recops));
489	virtual int get_tx_timestamp(time_t *);
490	virtual int set_tx_timestamp(time_t *);
491	virtual int get_verbose(u_int32_t which, int *);
492	virtual int set_verbose(u_int32_t which, int);
493
494	// Version information.  A static method so it can be obtained anytime.
495	//
496	static char *version(int *major, int *minor, int *patch);
497
498	// Convert DB errors to strings
499	static char *strerror(int);
500
501	// If an error is detected and the error call function
502	// or stream is set, a message is dispatched or printed.
503	// If a prefix is set, each message is prefixed.
504	//
505	// You can use set_errcall() or set_errfile() above to control
506	// error functionality.  Alternatively, you can call
507	// set_error_stream() to force all errors to a C++ stream.
508	// It is unwise to mix these approaches.
509	//
510	virtual __DB_STD(ostream) *get_error_stream();
511	virtual void set_error_stream(__DB_STD(ostream) *);
512	virtual __DB_STD(ostream) *get_message_stream();
513	virtual void set_message_stream(__DB_STD(ostream) *);
514
515	// used internally
516	static void runtime_error(DbEnv *dbenv, const char *caller, int err,
517				  int error_policy);
518	static void runtime_error_dbt(DbEnv *dbenv, const char *caller, Dbt *dbt,
519				  int error_policy);
520	static void runtime_error_lock_get(DbEnv *dbenv, const char *caller,
521				  int err, db_lockop_t op, db_lockmode_t mode,
522				  const Dbt *obj, DbLock lock, int index,
523				  int error_policy);
524
525	// Lock functions
526	//
527	virtual int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted);
528	virtual int lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
529		     db_lockmode_t lock_mode, DbLock *lock);
530	virtual int lock_id(u_int32_t *idp);
531	virtual int lock_id_free(u_int32_t id);
532	virtual int lock_put(DbLock *lock);
533	virtual int lock_stat(DB_LOCK_STAT **statp, u_int32_t flags);
534	virtual int lock_stat_print(u_int32_t flags);
535	virtual int lock_vec(u_int32_t locker, u_int32_t flags,
536		     DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);
537
538	// Log functions
539	//
540	virtual int log_archive(char **list[], u_int32_t flags);
541	static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1);
542	virtual int log_cursor(DbLogc **cursorp, u_int32_t flags);
543	virtual int log_file(DbLsn *lsn, char *namep, size_t len);
544	virtual int log_flush(const DbLsn *lsn);
545	virtual int log_get_config(u_int32_t, int *);
546	virtual int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags);
547	virtual int log_printf(DbTxn *, const char *, ...);
548	virtual int log_set_config(u_int32_t, int);
549	virtual int log_stat(DB_LOG_STAT **spp, u_int32_t flags);
550	virtual int log_stat_print(u_int32_t flags);
551
552	// Mpool functions
553	//
554	virtual int memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags);
555	virtual int memp_register(int ftype,
556			  pgin_fcn_type pgin_fcn,
557			  pgout_fcn_type pgout_fcn);
558	virtual int memp_stat(DB_MPOOL_STAT
559		      **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags);
560	virtual int memp_stat_print(u_int32_t flags);
561	virtual int memp_sync(DbLsn *lsn);
562	virtual int memp_trickle(int pct, int *nwrotep);
563
564	// Mpool functions
565	//
566	virtual int mutex_alloc(u_int32_t, db_mutex_t *);
567	virtual int mutex_free(db_mutex_t);
568	virtual int mutex_get_align(u_int32_t *);
569	virtual int mutex_get_increment(u_int32_t *);
570	virtual int mutex_get_max(u_int32_t *);
571	virtual int mutex_get_tas_spins(u_int32_t *);
572	virtual int mutex_lock(db_mutex_t);
573	virtual int mutex_set_align(u_int32_t);
574	virtual int mutex_set_increment(u_int32_t);
575	virtual int mutex_set_max(u_int32_t);
576	virtual int mutex_set_tas_spins(u_int32_t);
577	virtual int mutex_stat(DB_MUTEX_STAT **, u_int32_t);
578	virtual int mutex_stat_print(u_int32_t);
579	virtual int mutex_unlock(db_mutex_t);
580
581	// Transaction functions
582	//
583	virtual int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags);
584	virtual int txn_checkpoint(u_int32_t kbyte, u_int32_t min,
585			u_int32_t flags);
586	virtual int txn_recover(DbPreplist *preplist, long count,
587			long *retp, u_int32_t flags);
588	virtual int txn_stat(DB_TXN_STAT **statp, u_int32_t flags);
589	virtual int txn_stat_print(u_int32_t flags);
590
591	// Replication functions
592	//
593	virtual int rep_elect(u_int32_t, u_int32_t, u_int32_t);
594	virtual int rep_flush();
595	virtual int rep_process_message(Dbt *, Dbt *, int, DbLsn *);
596	virtual int rep_start(Dbt *, u_int32_t);
597	virtual int rep_stat(DB_REP_STAT **statp, u_int32_t flags);
598	virtual int rep_stat_print(u_int32_t flags);
599	virtual int rep_get_clockskew(u_int32_t *, u_int32_t *);
600	virtual int rep_set_clockskew(u_int32_t, u_int32_t);
601	virtual int rep_get_limit(u_int32_t *, u_int32_t *);
602	virtual int rep_set_limit(u_int32_t, u_int32_t);
603	virtual int rep_set_transport(int, int (*)(DbEnv *,
604	    const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t));
605	virtual int rep_set_request(u_int32_t, u_int32_t);
606	virtual int rep_get_request(u_int32_t *, u_int32_t *);
607	virtual int get_thread_count(u_int32_t *);
608	virtual int set_thread_count(u_int32_t);
609	virtual int set_thread_id(void (*)(DbEnv *, pid_t *, db_threadid_t *));
610	virtual int set_thread_id_string(char *(*)(DbEnv *,
611	    pid_t, db_threadid_t, char *));
612	virtual int rep_set_config(u_int32_t, int);
613	virtual int rep_get_config(u_int32_t, int *);
614	virtual int rep_sync(u_int32_t flags);
615
616	// Advanced replication functions
617	//
618	virtual int rep_get_nsites(u_int32_t *n);
619	virtual int rep_set_nsites(u_int32_t n);
620	virtual int rep_get_priority(u_int32_t *priorityp);
621	virtual int rep_set_priority(u_int32_t priority);
622	virtual int rep_get_timeout(int which, db_timeout_t *timeout);
623	virtual int rep_set_timeout(int which, db_timeout_t timeout);
624	virtual int repmgr_add_remote_site(const char * host, u_int16_t port,
625	    int *eidp, u_int32_t flags);
626	virtual int repmgr_get_ack_policy(int *policy);
627	virtual int repmgr_set_ack_policy(int policy);
628	virtual int repmgr_set_local_site(const char * host, u_int16_t port,
629	    u_int32_t flags);
630	virtual int repmgr_site_list(u_int *countp, DB_REPMGR_SITE **listp);
631	virtual int repmgr_start(int nthreads, u_int32_t flags);
632	virtual int repmgr_stat(DB_REPMGR_STAT **statp, u_int32_t flags);
633	virtual int repmgr_stat_print(u_int32_t flags);
634
635	// Conversion functions
636	//
637	virtual ENV *get_ENV()
638	{
639		return imp_->env;
640	}
641
642	virtual DB_ENV *get_DB_ENV()
643	{
644		return imp_;
645	}
646
647	virtual const DB_ENV *get_const_DB_ENV() const
648	{
649		return imp_;
650	}
651
652	static DbEnv* get_DbEnv(DB_ENV *dbenv)
653	{
654		return dbenv ? (DbEnv *)dbenv->api1_internal : 0;
655	}
656
657	static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv)
658	{
659		return dbenv ? (const DbEnv *)dbenv->api1_internal : 0;
660	}
661
662	// For internal use only.
663	static DbEnv* wrap_DB_ENV(DB_ENV *dbenv);
664
665	// These are public only because they need to be called
666	// via C functions.  They should never be called by users
667	// of this class.
668	//
669	static int _app_dispatch_intercept(DB_ENV *dbenv, DBT *dbt, DB_LSN *lsn,
670				       db_recops op);
671	static void _paniccall_intercept(DB_ENV *dbenv, int errval);
672	static void _feedback_intercept(DB_ENV *dbenv, int opcode, int pct);
673	static void  _event_func_intercept(DB_ENV *dbenv, u_int32_t, void *);
674	static int _isalive_intercept(DB_ENV *dbenv, pid_t pid,
675	    db_threadid_t thrid, u_int32_t flags);
676	static int _rep_send_intercept(DB_ENV *dbenv, const DBT *cntrl,
677	    const DBT *data, const DB_LSN *lsn, int id, u_int32_t flags);
678	static void _stream_error_function(const DB_ENV *dbenv,
679	    const char *prefix, const char *message);
680	static void _stream_message_function(const DB_ENV *dbenv,
681	    const char *message);
682	static void _thread_id_intercept(DB_ENV *dbenv, pid_t *pidp,
683	    db_threadid_t *thridp);
684	static char *_thread_id_string_intercept(DB_ENV *dbenv, pid_t pid,
685	    db_threadid_t thrid, char *buf);
686
687private:
688	void cleanup();
689	int initialize(DB_ENV *dbenv);
690	int error_policy();
691
692	// For internal use only.
693	DbEnv(DB_ENV *, u_int32_t flags);
694
695	// no copying
696	DbEnv(const DbEnv &);
697	void operator = (const DbEnv &);
698
699	// instance data
700	DB_ENV *imp_;
701	int construct_error_;
702	u_int32_t construct_flags_;
703	__DB_STD(ostream) *error_stream_;
704	__DB_STD(ostream) *message_stream_;
705
706	int (*app_dispatch_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops);
707	int (*isalive_callback_)(DbEnv *, pid_t, db_threadid_t, u_int32_t);
708	void (*error_callback_)(const DbEnv *, const char *, const char *);
709	void (*feedback_callback_)(DbEnv *, int, int);
710	void (*message_callback_)(const DbEnv *, const char *);
711	void (*paniccall_callback_)(DbEnv *, int);
712	void (*event_func_callback_)(DbEnv *, u_int32_t, void *);
713	int (*rep_send_callback_)(DbEnv *, const Dbt *, const Dbt *,
714	    const DbLsn *, int, u_int32_t);
715	void (*thread_id_callback_)(DbEnv *, pid_t *, db_threadid_t *);
716	char *(*thread_id_string_callback_)(DbEnv *, pid_t, db_threadid_t,
717	    char *);
718};
719
720//
721// Lock
722//
723class _exported DbLock
724{
725	friend class DbEnv;
726
727public:
728	DbLock();
729	DbLock(const DbLock &);
730	DbLock &operator = (const DbLock &);
731
732protected:
733	// We can add data to this class if needed
734	// since its contained class is not allocated by db.
735	// (see comment at top)
736
737	DbLock(DB_LOCK);
738	DB_LOCK lock_;
739};
740
741//
742// Log cursor
743//
744class _exported DbLogc : protected DB_LOGC
745{
746	friend class DbEnv;
747
748public:
749	int close(u_int32_t _flags);
750	int get(DbLsn *lsn, Dbt *data, u_int32_t _flags);
751	int version(u_int32_t *versionp, u_int32_t _flags);
752
753private:
754	// No data is permitted in this class (see comment at top)
755
756	// Note: use Db::cursor() to get pointers to a Dbc,
757	// and call Dbc::close() rather than delete to release them.
758	//
759	DbLogc();
760	~DbLogc();
761
762	// no copying
763	DbLogc(const Dbc &);
764	DbLogc &operator = (const Dbc &);
765};
766
767//
768// Log sequence number
769//
770class _exported DbLsn : public DB_LSN
771{
772	friend class DbEnv;          // friendship needed to cast to base class
773	friend class DbLogc;         // friendship needed to cast to base class
774};
775
776//
777// Memory pool file
778//
779class _exported DbMpoolFile
780{
781	friend class DbEnv;
782	friend class Db;
783
784public:
785	int close(u_int32_t flags);
786	int get(db_pgno_t *pgnoaddr, DbTxn *txn, u_int32_t flags, void *pagep);
787	int get_clear_len(u_int32_t *len);
788	int get_fileid(u_int8_t *fileid);
789	int get_flags(u_int32_t *flagsp);
790	int get_ftype(int *ftype);
791	int get_last_pgno(db_pgno_t *pgnop);
792	int get_lsn_offset(int32_t *offsetp);
793	int get_maxsize(u_int32_t *gbytes, u_int32_t *bytes);
794	int get_pgcookie(DBT *dbt);
795	int get_priority(DB_CACHE_PRIORITY *priorityp);
796	int get_transactional(void);
797	int open(const char *file, u_int32_t flags, int mode, size_t pagesize);
798	int put(void *pgaddr, DB_CACHE_PRIORITY priority, u_int32_t flags);
799	int set_clear_len(u_int32_t len);
800	int set_fileid(u_int8_t *fileid);
801	int set_flags(u_int32_t flags, int onoff);
802	int set_ftype(int ftype);
803	int set_lsn_offset(int32_t offset);
804	int set_maxsize(u_int32_t gbytes, u_int32_t bytes);
805	int set_pgcookie(DBT *dbt);
806	int set_priority(DB_CACHE_PRIORITY priority);
807	int sync();
808
809	virtual DB_MPOOLFILE *get_DB_MPOOLFILE()
810	{
811		return imp_;
812	}
813
814	virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const
815	{
816		return imp_;
817	}
818
819private:
820	DB_MPOOLFILE *imp_;
821
822	// We can add data to this class if needed
823	// since it is implemented via a pointer.
824	// (see comment at top)
825
826	// Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile,
827	// and call DbMpoolFile::close() rather than delete to release them.
828	//
829	DbMpoolFile();
830
831	// Shut g++ up.
832protected:
833	virtual ~DbMpoolFile();
834
835private:
836	// no copying
837	DbMpoolFile(const DbMpoolFile &);
838	void operator = (const DbMpoolFile &);
839};
840
841//
842// This is filled in and returned by the DbEnv::txn_recover() method.
843//
844class _exported DbPreplist
845{
846public:
847	DbTxn *txn;
848	u_int8_t gid[DB_XIDDATASIZE];
849};
850
851//
852// A sequence record in a database
853//
854class _exported DbSequence
855{
856public:
857	DbSequence(Db *db, u_int32_t flags);
858	virtual ~DbSequence();
859
860	int open(DbTxn *txnid, Dbt *key, u_int32_t flags);
861	int initial_value(db_seq_t value);
862	int close(u_int32_t flags);
863	int remove(DbTxn *txnid, u_int32_t flags);
864	int stat(DB_SEQUENCE_STAT **sp, u_int32_t flags);
865	int stat_print(u_int32_t flags);
866
867	int get(DbTxn *txnid, int32_t delta, db_seq_t *retp, u_int32_t flags);
868	int get_cachesize(int32_t *sizep);
869	int set_cachesize(int32_t size);
870	int get_flags(u_int32_t *flagsp);
871	int set_flags(u_int32_t flags);
872	int get_range(db_seq_t *minp, db_seq_t *maxp);
873	int set_range(db_seq_t min, db_seq_t max);
874
875	Db *get_db();
876	Dbt *get_key();
877
878	virtual DB_SEQUENCE *get_DB_SEQUENCE()
879	{
880		return imp_;
881	}
882
883	virtual const DB_SEQUENCE *get_const_DB_SEQUENCE() const
884	{
885		return imp_;
886	}
887
888	static DbSequence* get_DbSequence(DB_SEQUENCE *seq)
889	{
890		return (DbSequence *)seq->api_internal;
891	}
892
893	static const DbSequence* get_const_DbSequence(const DB_SEQUENCE *seq)
894	{
895		return (const DbSequence *)seq->api_internal;
896	}
897
898	// For internal use only.
899	static DbSequence* wrap_DB_SEQUENCE(DB_SEQUENCE *seq);
900
901private:
902	DbSequence(DB_SEQUENCE *seq);
903	// no copying
904	DbSequence(const DbSequence &);
905	DbSequence &operator = (const DbSequence &);
906
907	DB_SEQUENCE *imp_;
908	DBT key_;
909};
910
911//
912// Transaction
913//
914class _exported DbTxn
915{
916	friend class DbEnv;
917
918public:
919	int abort();
920	int commit(u_int32_t flags);
921	int discard(u_int32_t flags);
922	u_int32_t id();
923	int get_name(const char **namep);
924	int prepare(u_int8_t *gid);
925	int set_name(const char *name);
926	int set_timeout(db_timeout_t timeout, u_int32_t flags);
927
928	virtual DB_TXN *get_DB_TXN()
929	{
930		return imp_;
931	}
932
933	virtual const DB_TXN *get_const_DB_TXN() const
934	{
935		return imp_;
936	}
937
938	static DbTxn* get_DbTxn(DB_TXN *txn)
939	{
940		return (DbTxn *)txn->api_internal;
941	}
942
943	static const DbTxn* get_const_DbTxn(const DB_TXN *txn)
944	{
945		return (const DbTxn *)txn->api_internal;
946	}
947
948	// For internal use only.
949	static DbTxn* wrap_DB_TXN(DB_TXN *txn);
950
951private:
952	DB_TXN *imp_;
953
954	// We can add data to this class if needed
955	// since it is implemented via a pointer.
956	// (see comment at top)
957
958	// Note: use DbEnv::txn_begin() to get pointers to a DbTxn,
959	// and call DbTxn::abort() or DbTxn::commit rather than
960	// delete to release them.
961	//
962	DbTxn();
963	// For internal use only.
964	DbTxn(DB_TXN *txn);
965	virtual ~DbTxn();
966
967	// no copying
968	DbTxn(const DbTxn &);
969	void operator = (const DbTxn &);
970};
971
972//
973// A chunk of data, maybe a key or value.
974//
975class _exported Dbt : private DBT
976{
977	friend class Db;
978	friend class Dbc;
979	friend class DbEnv;
980	friend class DbLogc;
981	friend class DbSequence;
982
983public:
984	// key/data
985	void *get_data() const                 { return data; }
986	void set_data(void *value)             { data = value; }
987
988	// key/data length
989	u_int32_t get_size() const             { return size; }
990	void set_size(u_int32_t value)         { size = value; }
991
992	// RO: length of user buffer.
993	u_int32_t get_ulen() const             { return ulen; }
994	void set_ulen(u_int32_t value)         { ulen = value; }
995
996	// RO: get/put record length.
997	u_int32_t get_dlen() const             { return dlen; }
998	void set_dlen(u_int32_t value)         { dlen = value; }
999
1000	// RO: get/put record offset.
1001	u_int32_t get_doff() const             { return doff; }
1002	void set_doff(u_int32_t value)         { doff = value; }
1003
1004	// flags
1005	u_int32_t get_flags() const            { return flags; }
1006	void set_flags(u_int32_t value)        { flags = value; }
1007
1008	// Conversion functions
1009	DBT *get_DBT()                         { return (DBT *)this; }
1010	const DBT *get_const_DBT() const       { return (const DBT *)this; }
1011
1012	static Dbt* get_Dbt(DBT *dbt)          { return (Dbt *)dbt; }
1013	static const Dbt* get_const_Dbt(const DBT *dbt)
1014					       { return (const Dbt *)dbt; }
1015
1016	Dbt(void *data, u_int32_t size);
1017	Dbt();
1018	~Dbt();
1019	Dbt(const Dbt &);
1020	Dbt &operator = (const Dbt &);
1021
1022private:
1023	// Note: no extra data appears in this class (other than
1024	// inherited from DBT) since we need DBT and Dbt objects
1025	// to have interchangable pointers.
1026	//
1027	// When subclassing this class, remember that callback
1028	// methods like bt_compare, bt_prefix, dup_compare may
1029	// internally manufacture DBT objects (which later are
1030	// cast to Dbt), so such callbacks might receive objects
1031	// not of your subclassed type.
1032};
1033
1034////////////////////////////////////////////////////////////////
1035////////////////////////////////////////////////////////////////
1036//
1037// multiple key/data/reco iterator classes
1038//
1039
1040// DbMultipleIterator is a shared private base class for the three types
1041// of bulk-return Iterator;  it should never be instantiated directly,
1042// but it handles the functionality shared by its subclasses.
1043class _exported DbMultipleIterator
1044{
1045public:
1046	DbMultipleIterator(const Dbt &dbt);
1047protected:
1048	u_int8_t *data_;
1049	u_int32_t *p_;
1050};
1051
1052class _exported DbMultipleKeyDataIterator : private DbMultipleIterator
1053{
1054public:
1055	DbMultipleKeyDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
1056	bool next(Dbt &key, Dbt &data);
1057};
1058
1059class _exported DbMultipleRecnoDataIterator : private DbMultipleIterator
1060{
1061public:
1062	DbMultipleRecnoDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
1063	bool next(db_recno_t &recno, Dbt &data);
1064};
1065
1066class _exported DbMultipleDataIterator : private DbMultipleIterator
1067{
1068public:
1069	DbMultipleDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
1070	bool next(Dbt &data);
1071};
1072
1073////////////////////////////////////////////////////////////////
1074////////////////////////////////////////////////////////////////
1075//
1076// Exception classes
1077//
1078
1079// Almost any error in the DB library throws a DbException.
1080// Every exception should be considered an abnormality
1081// (e.g. bug, misuse of DB, file system error).
1082//
1083class _exported DbException : public __DB_STD(exception)
1084{
1085public:
1086	virtual ~DbException() throw();
1087	DbException(int err);
1088	DbException(const char *description);
1089	DbException(const char *description, int err);
1090	DbException(const char *prefix, const char *description, int err);
1091	int get_errno() const;
1092	virtual const char *what() const throw();
1093	DbEnv *get_env() const;
1094	void set_env(DbEnv *dbenv);
1095
1096	DbException(const DbException &);
1097	DbException &operator = (const DbException &);
1098
1099private:
1100	void describe(const char *prefix, const char *description);
1101
1102	char *what_;
1103	int err_;                   // errno
1104	DbEnv *dbenv_;
1105};
1106
1107//
1108// A specific sort of exception that occurs when
1109// an operation is aborted to resolve a deadlock.
1110//
1111class _exported DbDeadlockException : public DbException
1112{
1113public:
1114	virtual ~DbDeadlockException() throw();
1115	DbDeadlockException(const char *description);
1116
1117	DbDeadlockException(const DbDeadlockException &);
1118	DbDeadlockException &operator = (const DbDeadlockException &);
1119};
1120
1121//
1122// A specific sort of exception that occurs when
1123// a lock is not granted, e.g. by lock_get or lock_vec.
1124// Note that the Dbt is only live as long as the Dbt used
1125// in the offending call.
1126//
1127class _exported DbLockNotGrantedException : public DbException
1128{
1129public:
1130	virtual ~DbLockNotGrantedException() throw();
1131	DbLockNotGrantedException(const char *prefix, db_lockop_t op,
1132	    db_lockmode_t mode, const Dbt *obj, const DbLock lock, int index);
1133	DbLockNotGrantedException(const char *description);
1134
1135	DbLockNotGrantedException(const DbLockNotGrantedException &);
1136	DbLockNotGrantedException &operator =
1137	    (const DbLockNotGrantedException &);
1138
1139	db_lockop_t get_op() const;
1140	db_lockmode_t get_mode() const;
1141	const Dbt* get_obj() const;
1142	DbLock *get_lock() const;
1143	int get_index() const;
1144
1145private:
1146	db_lockop_t op_;
1147	db_lockmode_t mode_;
1148	const Dbt *obj_;
1149	DbLock *lock_;
1150	int index_;
1151};
1152
1153//
1154// A specific sort of exception that occurs when
1155// user declared memory is insufficient in a Dbt.
1156//
1157class _exported DbMemoryException : public DbException
1158{
1159public:
1160	virtual ~DbMemoryException() throw();
1161	DbMemoryException(Dbt *dbt);
1162	DbMemoryException(const char *prefix, Dbt *dbt);
1163
1164	DbMemoryException(const DbMemoryException &);
1165	DbMemoryException &operator = (const DbMemoryException &);
1166
1167	Dbt *get_dbt() const;
1168private:
1169	Dbt *dbt_;
1170};
1171
1172//
1173// A specific sort of exception that occurs when a change of replication
1174// master requires that all handles be re-opened.
1175//
1176class _exported DbRepHandleDeadException : public DbException
1177{
1178public:
1179	virtual ~DbRepHandleDeadException() throw();
1180	DbRepHandleDeadException(const char *description);
1181
1182	DbRepHandleDeadException(const DbRepHandleDeadException &);
1183	DbRepHandleDeadException &operator = (const DbRepHandleDeadException &);
1184};
1185
1186//
1187// A specific sort of exception that occurs when
1188// recovery is required before continuing DB activity.
1189//
1190class _exported DbRunRecoveryException : public DbException
1191{
1192public:
1193	virtual ~DbRunRecoveryException() throw();
1194	DbRunRecoveryException(const char *description);
1195
1196	DbRunRecoveryException(const DbRunRecoveryException &);
1197	DbRunRecoveryException &operator = (const DbRunRecoveryException &);
1198};
1199
1200//
1201// A specific sort of exception that occurs when
1202
1203////////////////////////////////////////////////////////////////
1204////////////////////////////////////////////////////////////////
1205//
1206// Restore default compiler warnings
1207//
1208#ifdef _MSC_VER
1209#pragma warning(pop)
1210#endif
1211
1212#endif /* !_DB_CXX_H_ */
1213