1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1997, 2013 Oracle and/or its affiliates.  All rights reserved.
5  *
6  * $Id$
7  */
8 
9 #include "db_config.h"
10 
11 #include "db_int.h"
12 
13 #include "db_cxx.h"
14 #include "dbinc/cxx_int.h"
15 
16 // Helper macros for simple methods that pass through to the
17 // underlying C method. It may return an error or raise an exception.
18 // Note this macro expects that input _argspec is an argument
19 // list element (e.g., "char *arg") and that _arglist is the arguments
20 // that should be passed through to the C method (e.g., "(mpf, arg)")
21 //
22 #define	DB_MPOOLFILE_METHOD(_name, _argspec, _arglist, _retok)		\
23 int DbMpoolFile::_name _argspec						\
24 {									\
25 	int ret;							\
26 	DB_MPOOLFILE *mpf = unwrap(this);				\
27 									\
28 	if (mpf == NULL)						\
29 		ret = EINVAL;						\
30 	else								\
31 		ret = mpf->_name _arglist;				\
32 	if (!_retok(ret))						\
33 		DB_ERROR(DbEnv::get_DbEnv(mpf->env->dbenv), 		\
34 			"DbMpoolFile::"#_name, ret, ON_ERROR_UNKNOWN);	\
35 	return (ret);							\
36 }
37 
38 #define	DB_MPOOLFILE_METHOD_VOID(_name, _argspec, _arglist)		\
39 void DbMpoolFile::_name _argspec					\
40 {									\
41 	DB_MPOOLFILE *mpf = unwrap(this);				\
42 									\
43 	mpf->_name _arglist;						\
44 }
45 
46 ////////////////////////////////////////////////////////////////////////
47 //                                                                    //
48 //                            DbMpoolFile                             //
49 //                                                                    //
50 ////////////////////////////////////////////////////////////////////////
51 
DbMpoolFile()52 DbMpoolFile::DbMpoolFile()
53 :	imp_(0)
54 {
55 }
56 
~DbMpoolFile()57 DbMpoolFile::~DbMpoolFile()
58 {
59 }
60 
close(u_int32_t flags)61 int DbMpoolFile::close(u_int32_t flags)
62 {
63 	DB_MPOOLFILE *mpf = unwrap(this);
64 	int ret;
65 	DbEnv *dbenv = DbEnv::get_DbEnv(mpf->env->dbenv);
66 
67 	if (mpf == NULL)
68 		ret = EINVAL;
69 	else
70 		ret = mpf->close(mpf, flags);
71 
72 	imp_ = 0;                   // extra safety
73 
74 	// This may seem weird, but is legal as long as we don't access
75 	// any data before returning.
76 	delete this;
77 
78 	if (!DB_RETOK_STD(ret))
79 		DB_ERROR(dbenv, "DbMpoolFile::close", ret, ON_ERROR_UNKNOWN);
80 
81 	return (ret);
82 }
83 
84 DB_MPOOLFILE_METHOD(get,
85     (db_pgno_t *pgnoaddr, DbTxn *txn, u_int32_t flags, void *pagep),
86     (mpf, pgnoaddr, unwrap(txn), flags, pagep), DB_RETOK_MPGET)
87 DB_MPOOLFILE_METHOD(open,
88     (const char *file, u_int32_t flags, int mode, size_t pagesize),
89     (mpf, file, flags, mode, pagesize), DB_RETOK_STD)
90 DB_MPOOLFILE_METHOD(put,
91     (void *pgaddr, DB_CACHE_PRIORITY priority, u_int32_t flags),
92     (mpf, pgaddr, priority, flags), DB_RETOK_STD)
93 DB_MPOOLFILE_METHOD(get_clear_len, (u_int32_t *lenp),
94     (mpf, lenp), DB_RETOK_STD)
95 DB_MPOOLFILE_METHOD(set_clear_len, (u_int32_t len),
96     (mpf, len), DB_RETOK_STD)
97 DB_MPOOLFILE_METHOD(get_fileid, (u_int8_t *fileid),
98     (mpf, fileid), DB_RETOK_STD)
99 DB_MPOOLFILE_METHOD(set_fileid, (u_int8_t *fileid),
100     (mpf, fileid), DB_RETOK_STD)
101 DB_MPOOLFILE_METHOD(get_flags, (u_int32_t *flagsp),
102     (mpf, flagsp), DB_RETOK_STD)
103 DB_MPOOLFILE_METHOD(set_flags, (u_int32_t flags, int onoff),
104     (mpf, flags, onoff), DB_RETOK_STD)
105 DB_MPOOLFILE_METHOD(get_ftype, (int *ftypep),
106     (mpf, ftypep), DB_RETOK_STD)
107 DB_MPOOLFILE_METHOD(set_ftype, (int ftype),
108     (mpf, ftype), DB_RETOK_STD)
109 DB_MPOOLFILE_METHOD(get_last_pgno, (db_pgno_t *pgnop),
110     (mpf, pgnop), DB_RETOK_STD)
111 DB_MPOOLFILE_METHOD(get_lsn_offset, (int32_t *offsetp),
112     (mpf, offsetp), DB_RETOK_STD)
113 DB_MPOOLFILE_METHOD(set_lsn_offset, (int32_t offset),
114     (mpf, offset), DB_RETOK_STD)
115 DB_MPOOLFILE_METHOD(get_maxsize, (u_int32_t *gbytesp, u_int32_t *bytesp),
116     (mpf, gbytesp, bytesp), DB_RETOK_STD)
117 DB_MPOOLFILE_METHOD(set_maxsize, (u_int32_t gbytes, u_int32_t bytes),
118     (mpf, gbytes, bytes), DB_RETOK_STD)
119 DB_MPOOLFILE_METHOD(get_pgcookie, (DBT *dbt),
120     (mpf, dbt), DB_RETOK_STD)
121 DB_MPOOLFILE_METHOD(set_pgcookie, (DBT *dbt),
122     (mpf, dbt), DB_RETOK_STD)
123 DB_MPOOLFILE_METHOD(get_priority, (DB_CACHE_PRIORITY *priorityp),
124     (mpf, priorityp), DB_RETOK_STD)
125 DB_MPOOLFILE_METHOD(set_priority, (DB_CACHE_PRIORITY priority),
126     (mpf, priority), DB_RETOK_STD)
127 DB_MPOOLFILE_METHOD(sync, (),
128     (mpf), DB_RETOK_STD)
129