File: cxx_mpool.cpp

package info (click to toggle)
evolution-data-server 1.0.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 39,504 kB
  • ctags: 26,423
  • sloc: ansic: 175,347; tcl: 30,499; sh: 20,699; perl: 11,320; xml: 9,039; java: 7,653; cpp: 6,029; makefile: 4,866; awk: 1,338; yacc: 1,103; sed: 772; cs: 505; lex: 134; asm: 14
file content (110 lines) | stat: -rw-r--r-- 3,312 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1997-2002
 *	Sleepycat Software.  All rights reserved.
 */

#include "db_config.h"

#ifndef lint
static const char revid[] = "$Id: cxx_mpool.cpp,v 1.1.1.1 2003/11/20 22:13:11 toshok Exp $";
#endif /* not lint */

#include <errno.h>

#include "db_cxx.h"
#include "dbinc/cxx_int.h"

#include "db_int.h"

// Helper macros 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., "(mpf, arg)")
//
#define	DB_MPOOLFILE_METHOD(_name, _argspec, _arglist, _retok)		\
int DbMpoolFile::_name _argspec						\
{									\
	int ret;							\
	DB_MPOOLFILE *mpf = unwrap(this);				\
									\
	if (mpf == NULL)						\
		ret = EINVAL;						\
	else								\
		ret = mpf->_name _arglist;				\
	if (!_retok(ret))						\
		DB_ERROR("DbMpoolFile::"#_name, ret, ON_ERROR_UNKNOWN);	\
	return (ret);							\
}

#define	DB_MPOOLFILE_METHOD_VOID(_name, _argspec, _arglist)		\
void DbMpoolFile::_name _argspec					\
{									\
	DB_MPOOLFILE *mpf = unwrap(this);				\
									\
	mpf->_name _arglist;						\
}

////////////////////////////////////////////////////////////////////////
//                                                                    //
//                            DbMpoolFile                             //
//                                                                    //
////////////////////////////////////////////////////////////////////////

DbMpoolFile::DbMpoolFile()
:	imp_(0)
{
}

DbMpoolFile::~DbMpoolFile()
{
}

int DbMpoolFile::close(u_int32_t flags)
{
	DB_MPOOLFILE *mpf = unwrap(this);
	int ret;

	if (mpf == NULL)
		ret = EINVAL;
	else
		ret = mpf->close(mpf, flags);

	imp_ = 0;                   // extra safety

	// This may seem weird, but is legal as long as we don't access
	// any data before returning.
	delete this;

	if (!DB_RETOK_STD(ret))
		DB_ERROR("DbMpoolFile::close", ret, ON_ERROR_UNKNOWN);

	return (ret);
}

DB_MPOOLFILE_METHOD(get, (db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep),
    (mpf, pgnoaddr, flags, pagep), DB_RETOK_MPGET)
DB_MPOOLFILE_METHOD_VOID(last_pgno, (db_pgno_t *pgnoaddr), (mpf, pgnoaddr))
DB_MPOOLFILE_METHOD(open,
    (const char *file, u_int32_t flags, int mode, size_t pagesize),
    (mpf, file, flags, mode, pagesize), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(put, (void *pgaddr, u_int32_t flags),
    (mpf, pgaddr, flags), DB_RETOK_STD)
DB_MPOOLFILE_METHOD_VOID(refcnt, (db_pgno_t *pgnoaddr), (mpf, pgnoaddr))
DB_MPOOLFILE_METHOD(set, (void *pgaddr, u_int32_t flags),
    (mpf, pgaddr, flags), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_clear_len, (u_int32_t len),
    (mpf, len), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_fileid, (u_int8_t *fileid),
    (mpf, fileid), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_ftype, (int ftype),
    (mpf, ftype), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_lsn_offset, (int32_t offset),
    (mpf, offset), DB_RETOK_STD)
DB_MPOOLFILE_METHOD(set_pgcookie, (DBT *dbt),
    (mpf, dbt), DB_RETOK_STD)
DB_MPOOLFILE_METHOD_VOID(set_unlink, (int ul), (mpf, ul))
DB_MPOOLFILE_METHOD(sync, (),
    (mpf), DB_RETOK_STD)