cxx_txn.cpp 1.86 KB
Newer Older
unknown's avatar
unknown committed
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
unknown's avatar
unknown committed
4
 * Copyright (c) 1997-2002
unknown's avatar
unknown committed
5 6 7 8 9 10
 *	Sleepycat Software.  All rights reserved.
 */

#include "db_config.h"

#ifndef lint
unknown's avatar
unknown committed
11
static const char revid[] = "$Id: cxx_txn.cpp,v 11.27 2002/07/20 13:50:11 dda Exp $";
unknown's avatar
unknown committed
12 13 14 15 16
#endif /* not lint */

#include <errno.h>

#include "db_cxx.h"
unknown's avatar
unknown committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include "dbinc/cxx_int.h"

#include "db_int.h"

// Helper macro for simple methods that pass through to the
// underlying C method. It may return an error or raise an exception.
// Note this macro expects that input _argspec is an argument
// list element (e.g., "char *arg") and that _arglist is the arguments
// that should be passed through to the C method (e.g., "(db, arg)")
//
#define	DBTXN_METHOD(_name, _delete, _argspec, _arglist)		\
int DbTxn::_name _argspec						\
{									\
	int ret;							\
	DB_TXN *txn = unwrap(this);					\
									\
	ret = txn->_name _arglist;					\
	/* Weird, but safe if we don't access this again. */		\
	if (_delete)							\
		delete this;						\
	if (!DB_RETOK_STD(ret))						\
		DB_ERROR("DbTxn::" # _name, ret, ON_ERROR_UNKNOWN);	\
	return (ret);							\
unknown's avatar
unknown committed
40 41
}

unknown's avatar
unknown committed
42
// private constructor, never called but needed by some C++ linkers
unknown's avatar
unknown committed
43 44 45 46 47
DbTxn::DbTxn()
:	imp_(0)
{
}

unknown's avatar
unknown committed
48 49
DbTxn::DbTxn(DB_TXN *txn)
:	imp_(wrap(txn))
unknown's avatar
unknown committed
50
{
unknown's avatar
unknown committed
51
	txn->api_internal = this;
unknown's avatar
unknown committed
52 53
}

unknown's avatar
unknown committed
54
DbTxn::~DbTxn()
unknown's avatar
unknown committed
55 56 57
{
}

unknown's avatar
unknown committed
58 59 60
DBTXN_METHOD(abort, 1, (), (txn))
DBTXN_METHOD(commit, 1, (u_int32_t flags), (txn, flags))
DBTXN_METHOD(discard, 1, (u_int32_t flags), (txn, flags))
unknown's avatar
unknown committed
61 62 63 64 65 66

u_int32_t DbTxn::id()
{
	DB_TXN *txn;

	txn = unwrap(this);
unknown's avatar
unknown committed
67
	return (txn->id(txn));		// no error
unknown's avatar
unknown committed
68 69
}

unknown's avatar
unknown committed
70 71 72
DBTXN_METHOD(prepare, 0, (u_int8_t *gid), (txn, gid))
DBTXN_METHOD(set_timeout, 0, (db_timeout_t timeout, u_int32_t flags),
    (txn, timeout, flags))
unknown's avatar
unknown committed
73

unknown's avatar
unknown committed
74 75 76 77 78 79 80
// static method
DbTxn *DbTxn::wrap_DB_TXN(DB_TXN *txn)
{
	DbTxn *wrapped_txn = get_DbTxn(txn);
	if (wrapped_txn == NULL)
		wrapped_txn = new DbTxn(txn);
	return wrapped_txn;
unknown's avatar
unknown committed
81
}