diff options
Diffstat (limited to 'lang/csharp/libdb_csharp/db.i')
-rw-r--r-- | lang/csharp/libdb_csharp/db.i | 325 |
1 files changed, 282 insertions, 43 deletions
diff --git a/lang/csharp/libdb_csharp/db.i b/lang/csharp/libdb_csharp/db.i index 8ad73bc2..dc6c5cb2 100644 --- a/lang/csharp/libdb_csharp/db.i +++ b/lang/csharp/libdb_csharp/db.i @@ -20,6 +20,7 @@ typedef uintptr_t roff_t; typedef u_int32_t uintptr_t; typedef int int32_t; typedef int64_t db_seq_t; +typedef int64_t db_off_t; typedef int64_t off_t; typedef long long int int64_t; typedef u_int32_t DB_BACKUP_CONFIG; @@ -79,22 +80,6 @@ typedef enum { DB_TXN_PRINT=7 /* Public. */ } db_recops; -struct __db; typedef struct __db DB; -struct __db_channel; typedef struct __db_channel DB_CHANNEL; -struct __db_compact; typedef struct __db_compact DB_COMPACT; -struct __db_lock_u; typedef struct __db_lock_u DB_LOCK; -struct __db_lsn; typedef struct __db_lsn DB_LSN; -struct __db_preplist; typedef struct __db_preplist DB_PREPLIST; -struct __db_repmgrsite; typedef struct __db_repmgrsite DB_REPMGR_SITE; -struct __db_sequence; typedef struct __db_sequence DB_SEQUENCE; -struct __db_site; typedef struct __db_site DB_SITE; -struct __dbc; typedef struct __dbc DBC; -struct __dbenv; typedef struct __dbenv DB_ENV; -struct __dbt; typedef struct __dbt DBT; -struct __dbtxn; typedef struct __dbtxn DB_TXN; -struct __key_range; typedef struct __key_range DB_KEY_RANGE; -struct __db_txn_token; typedef struct __db_txn_token DB_TXN_TOKEN; - %typemap(cstype) char ** "out IntPtr" %typemap(imtype) char ** "out IntPtr" %typemap(csin) char ** "out $csinput" @@ -131,12 +116,21 @@ struct __db_txn_token; typedef struct __db_txn_token DB_TXN_TOKEN; %typemap(cstype) db_seq_t * "ref Int64" %typemap(imtype) db_seq_t * "ref Int64" %typemap(csin) db_seq_t * "ref $csinput" +%typemap(cstype) db_off_t "Int64" +%typemap(imtype) db_off_t "Int64" +%typemap(csin) db_off_t "$csinput" +%typemap(cstype) db_off_t * "ref Int64" +%typemap(imtype) db_off_t * "ref Int64" +%typemap(csin) db_off_t * "ref $csinput" %typemap(cstype) u_int8_t [DB_GID_SIZE] "byte[]" %typemap(imtype) u_int8_t [DB_GID_SIZE] "byte[]" %typemap(csin) u_int8_t [DB_GID_SIZE] "$csinput" %typemap(cstype) u_int8_t * "byte[,]" %typemap(imtype) u_int8_t * "byte[,]" %typemap(csin) u_int8_t * "$csinput" +%typemap(cstype) void * "IntPtr" +%typemap(csin) void * "$csinput" +%typemap(csout, excode=SWIGEXCODE) void * "{IntPtr res = $imcall; $excode; return res;}" %typemap(cstype) DBT * "DatabaseEntry" %typemap(csin, post=" GC.KeepAlive($csinput);") DBT * "$csclassname.getCPtr(DatabaseEntry.getDBT($csinput))" @@ -199,7 +193,20 @@ struct __db_txn_token; typedef struct __db_txn_token DB_TXN_TOKEN; return ret; } - + +%typemap(csout) DBT *get_partition_keys(u_int *countp, u_int *sizep, int *err) { + IntPtr cPtr = $imcall; + if (cPtr == IntPtr.Zero) + return null; + + DatabaseEntry[] ret = new DatabaseEntry[countp - 1]; + IntPtr val; + for (int i = 0; i < (countp - 1); i++) { + val = new IntPtr((IntPtr.Size == 4 ? cPtr.ToInt32() : cPtr.ToInt64()) + i * sizep); + ret[i] = DatabaseEntry.fromDBT(new DBT(val, false)); + } + return ret; +} %typemap(csout) int is_transaction_applied{ return $imcall; } @@ -316,7 +323,7 @@ struct __db_txn_token; typedef struct __db_txn_token DB_TXN_TOKEN; return ret; } -typedef struct __db_channel +typedef struct { %extend { int close(u_int32_t flags) { @@ -347,7 +354,7 @@ typedef struct __db_channel } } DB_CHANNEL; -typedef struct __db_compact { +typedef struct { /* Input Parameters. */ %typemap(csvarout) u_int32_t compact_fillpercent %{%} u_int32_t compact_fillpercent; /* Desired fillfactor: 1-100 */ @@ -370,12 +377,20 @@ typedef struct __db_compact { db_pgno_t compact_pages_truncated; /* Pages truncated to OS. */ } DB_COMPACT; -typedef struct __db_lsn { +typedef struct { u_int32_t file; u_int32_t offset; } DB_LSN; %typemap(cscode) DB %{ + internal DatabaseEntry[] get_partition_keys() { + uint count = 0; + int err = 0; + uint size = 0; + DatabaseEntry[] ret = get_partition_keys(ref count, ref size, ref err); + DatabaseException.ThrowException(err); + return ret; + } internal DBC cursor(DB_TXN txn, uint flags) { int err = 0; DBC ret = cursor(txn, flags, ref err); @@ -423,6 +438,22 @@ typedef struct __db_lsn { return ret; } + internal int get_blob_dir(out string dir) { + int ret; + IntPtr dirp; + ret = get_blob_dir(out dirp); + dir = Marshal.PtrToStringAnsi(dirp); + return ret; + } + + internal int get_blob_sub_dir(out string dir) { + int ret; + IntPtr dirp; + ret = get_blob_sub_dir(out dirp); + dir = Marshal.PtrToStringAnsi(dirp); + return ret; + } + internal int get_dbname(out string filenamep, out string dbnamep) { int ret; IntPtr fp, dp; @@ -441,7 +472,7 @@ typedef struct __db_lsn { return ret; } %} -typedef struct __db +typedef struct { %typemap(cstype) void *api_internal "BaseDatabase" %typemap(imtype) void *api_internal "BaseDatabase" @@ -583,10 +614,28 @@ typedef struct __db return self->set_append_recno(self, callback); } - %typemap(cstype) int (*)(DB*, const DBT*, const DBT*) "BDB_CompareDelegate" - %typemap(imtype) int (*)(DB*, const DBT*, const DBT*) "BDB_CompareDelegate" - %typemap(csin) int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2) "callback" - int set_bt_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2)) { + int get_blob_dir(const char **dir) { + return self->get_blob_dir(self, dir); + } + int set_blob_dir(const char *dir) { + return self->set_blob_dir(self, dir); + } + + int get_blob_sub_dir(const char **dir) { + return self->get_blob_sub_dir(self, dir); + } + + int get_blob_threshold(u_int32_t *bytes) { + return self->get_blob_threshold(self, bytes); + } + int set_blob_threshold(u_int32_t bytes, u_int32_t flags) { + return self->set_blob_threshold(self, bytes, flags); + } + + %typemap(cstype) int (*)(DB*, const DBT*, const DBT*, size_t *) "BDB_CompareDelegate" + %typemap(imtype) int (*)(DB*, const DBT*, const DBT*, size_t *) "BDB_CompareDelegate" + %typemap(csin) int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2, size_t *locp) "callback" + int set_bt_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2, size_t *locp)) { return self->set_bt_compare(self, callback); } @@ -621,7 +670,7 @@ typedef struct __db return self->set_cachesize(self, gbytes, bytes, ncache); } - int set_dup_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2)) { + int set_dup_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2, size_t *locp)) { return self->set_dup_compare(self, callback); } @@ -667,7 +716,7 @@ typedef struct __db return self->set_heap_regionsize(self, npages); } - int set_h_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2)) { + int set_h_compare(int (*callback)(DB *dbp, const DBT *dbt1, const DBT *dbt2, size_t *locp)) { return self->set_h_compare(self, callback); } @@ -712,6 +761,89 @@ typedef struct __db int set_pagesize(u_int32_t pgsz) { return self->set_pagesize(self, pgsz); } + + %typemap(cstype) void (*)(const DB_ENV *, const char *) "BDB_MsgcallDelegate" + %typemap(imtype) void (*)(const DB_ENV *, const char *) "BDB_MsgcallDelegate" + %typemap(csin) void (*db_msgcall_fcn)(const DB_ENV *dbenv, const char *msg) "db_msgcall_fcn" + void set_msgcall(void (*db_msgcall_fcn)(const DB_ENV *dbenv, const char *msg)) { + self->set_msgcall(self, db_msgcall_fcn); + } + + int set_msgfile(char *msgfile) { + int ret; + FILE *fmsg; + ret = 0; + fmsg = NULL; + self->get_msgfile(self, &fmsg); + if (fmsg != NULL && fmsg != stdout && fmsg != stderr) { + fclose(fmsg); + fmsg = NULL; + } + if (strcmp(msgfile, "") == 0 || msgfile == NULL) + self->set_msgfile(self, NULL); + else if (strcmp(msgfile, "stdout") == 0) + self->set_msgfile(self, stdout); + else if (strcmp(msgfile, "stderr") == 0) + self->set_msgfile(self, stderr); + else { + fmsg = fopen(msgfile, "a"); + if (fmsg != NULL) { + self->set_msgfile(self, fmsg); + } + else + ret = 1; + } + return ret; + } + + %typemap(cstype) DBT *get_partition_keys "DatabaseEntry[]" + %typemap(imtype) DBT *get_partition_keys "IntPtr" + %csmethodmodifiers get_partition_keys "private" + DBT *get_partition_keys(u_int *countp, u_int32_t *sizep, int *err) { + DBT *keys = NULL; + *err = self->get_partition_keys(self, countp, &keys); + *sizep = sizeof(DBT); + return keys; + } + int get_partition_parts(u_int32_t *parts) { + int ret; + ret = self->get_partition_keys(self, parts, NULL); + if (*parts == 0) + ret = self->get_partition_callback(self, parts, NULL); + return ret; + } + %typemap(cstype) DBT *keys "IntPtr[]" + %typemap(imtype) DBT *keys "IntPtr[]" + %typemap(csin) DBT *keys "$csinput" + %typemap(cstype) u_int32_t (*)(DB *dbp, DBT *key) "BDB_PartitionDelegate" + %typemap(imtype) u_int32_t (*)(DB *dbp, DBT *key) "BDB_PartitionDelegate" + %typemap(csin) u_int32_t (*partition)(DB *dbp, DBT *key) "partition" + int set_partition(u_int32_t parts, DBT *keys, u_int32_t (*partition)(DB *dbp, DBT *key)) { + DBT *dbt; + DBT **ptr; + size_t dbt_size; + int i, ret; + + i = 0; + dbt = NULL; + ptr = (DBT **)keys; + if (keys != NULL) { + dbt_size = sizeof(DBT); + if ((ret = __os_malloc(NULL, (parts - 1) * dbt_size, &dbt)) != 0) + return ret; + do { + if ((ret = __dbt_usercopy(self->env, ptr[i])) != 0) + goto err; + memcpy(&dbt[i], ptr[i], dbt_size); + } while (++i < (int)(parts - 1)); + } + ret = self->set_partition(self, parts, dbt, partition); + + err: while (--i >= 0) + __os_ufree(self->env, ptr[i]->data); + __os_free(NULL, dbt); + return ret; + } int get_priority(DB_CACHE_PRIORITY *flags) { return self->get_priority(self, flags); @@ -805,8 +937,14 @@ typedef struct __db DatabaseException.ThrowException(err); return ret; } + internal DB_STREAM db_stream(uint flags) { + int err = 0; + DB_STREAM ret = db_stream(flags, ref err); + DatabaseException.ThrowException(err); + return ret; + } %} -typedef struct __dbc +typedef struct { %extend { int close() { @@ -825,6 +963,13 @@ typedef struct __dbc return self->count(self, cnt, flags); } + %csmethodmodifiers db_stream "private" + DB_STREAM *db_stream(u_int32_t flags, int *err) { + DB_STREAM *dbs = NULL; + *err = self->db_stream(self, &dbs, flags); + return dbs; + } + int del(u_int32_t flags) { return self->del(self, flags); } @@ -865,11 +1010,12 @@ typedef struct __dbc } %} -typedef struct __db_txn_token +typedef struct { %typemap(cstype) u_int8_t [DB_TXN_TOKEN_SIZE] "byte[]" %typemap(imtype, out = "IntPtr") u_int8_t [DB_TXN_TOKEN_SIZE] "byte[]" %typemap(csin) u_int8_t [DB_TXN_TOKEN_SIZE] "$csinput" +%typemap(csout, excode=SWIGEXCODE) u_int8_t [DB_TXN_TOKEN_SIZE] "{byte[] res = (byte [])($imcall); $excode; return res;}" %typemap(csvarout) u_int8_t [DB_TXN_TOKEN_SIZE] %{ get { byte[] ret = new byte[DbConstants.DB_TXN_TOKEN_SIZE]; @@ -891,7 +1037,7 @@ u_int8_t buf[DB_TXN_TOKEN_SIZE]; } } %} -typedef struct __dbt +typedef struct { u_int32_t dlen; u_int32_t doff; @@ -953,7 +1099,7 @@ typedef struct __dbt } %} -typedef struct __db_site +typedef struct { %extend { int close() { @@ -982,7 +1128,28 @@ typedef struct __db_site } } DB_SITE; -typedef struct __db_repmgrsite +typedef struct +{ +%extend { + int close(u_int32_t flags) { + return self->close(self, flags); + } + + int read(DBT *data, db_off_t offset, u_int32_t size, u_int32_t flags) { + return self->read(self, data, offset, size, flags); + } + + int size(db_off_t *size, u_int32_t flags) { + return self->size(self, size, flags); + } + + int write(DBT *data, db_off_t offset, u_int32_t flags) { + return self->write(self, data, offset, flags); + } +} +} DB_STREAM; + +typedef struct { %typemap(csvarin) int eid %{%} int eid; @@ -1006,7 +1173,7 @@ typedef struct __db_repmgrsite } %} -typedef struct __dbtxn +typedef struct { %extend { int abort() { @@ -1252,6 +1419,13 @@ typedef struct __dbtxn return ret; } + internal int get_blob_dir(out string dir) { + int ret; + IntPtr dirp; + ret = get_blob_dir(out dirp); + dir = Marshal.PtrToStringAnsi(dirp); + return ret; + } internal int get_home(out string file) { int ret; IntPtr fp; @@ -1292,7 +1466,7 @@ typedef struct __dbtxn %typemap(csimports) DB_ENV "using System; using System.Runtime.InteropServices; using System.Collections.Generic;" -typedef struct __dbenv +typedef struct { %typemap(cstype) void *api2_internal "DatabaseEnvironment" @@ -1608,6 +1782,13 @@ typedef struct __dbenv return self->repmgr_get_ack_policy(self, ack_policy); } + int repmgr_get_incoming_queue_max(u_int32_t *gbytes, u_int32_t *bytes) { + return self->repmgr_get_incoming_queue_max(self, gbytes, bytes); + } + int repmgr_set_incoming_queue_max(u_int32_t gbytes, u_int32_t bytes) { + return self->repmgr_set_incoming_queue_max(self, gbytes, bytes); + } + DB_CHANNEL *repmgr_channel(int eid, u_int32_t flags, int *err) { DB_CHANNEL *channel = NULL; *err = self->repmgr_channel(self, eid, &channel, flags); @@ -1751,6 +1932,13 @@ typedef struct __dbenv return self->rep_set_transport(self, envid, send); } + %typemap(cstype) int (*)(DB_ENV *, const char *, int *, u_int32_t) "BDB_ReplicationViewDelegate" + %typemap(imtype) int (*)(DB_ENV *, const char *, int *, u_int32_t) "BDB_ReplicationViewDelegate" + %typemap(csin) int (*f_repview)(DB_ENV *, const char *, int *, u_int32_t) "f_repview" + int rep_set_view(int (*f_repview)(DB_ENV *, const char *, int *, u_int32_t)) { + return self->rep_set_view(self, f_repview); + } + %typemap(cstype) int (*)(DB_ENV*, const char *dbname, void *handle) "BDB_BackupCloseDelegate" %typemap(imtype) int (*)(DB_ENV*, const char *dbname, void *handle) "BDB_BackupCloseDelegate" %typemap(csin) int (*close_func)(DB_ENV *, const char *dbname, void *handle) "close_func" @@ -1771,6 +1959,20 @@ typedef struct __dbenv return self->set_backup_config(self, cfg, value); } + int get_blob_dir(const char **dirp) { + return self->get_blob_dir(self, dirp); + } + int set_blob_dir(const char *dir) { + return self->set_blob_dir(self, dir); + } + + int get_blob_threshold(u_int32_t *bytes) { + return self->get_blob_threshold(self, bytes); + } + int set_blob_threshold(u_int32_t bytes, u_int32_t flags) { + return self->set_blob_threshold(self, bytes, flags); + } + int get_cachesize(u_int32_t *gbytes, u_int32_t *bytes, int *ncache) { return self->get_cachesize(self, gbytes, bytes, ncache); } @@ -1848,7 +2050,7 @@ typedef struct __dbenv %typemap(cstype) char ** "out IntPtr" %typemap(imtype) char ** "out IntPtr" %typemap(csin) char ** "out $csinput" - %csmethodmodifiers get_data_dirs "private" + %csmethodmodifiers get_intermediate_dir_mode "private" int get_intermediate_dir_mode(const char **mode) { return self->get_intermediate_dir_mode(self, mode); } @@ -2005,6 +2207,40 @@ typedef struct __dbenv int set_mp_mmapsize(size_t mp_mmapsize) { return self->set_mp_mmapsize(self, mp_mmapsize); } + + %typemap(cstype) void (*)(const DB_ENV *, const char *) "BDB_MsgcallDelegate" + %typemap(imtype) void (*)(const DB_ENV *, const char *) "BDB_MsgcallDelegate" + %typemap(csin) void (*db_msgcall_fcn)(const DB_ENV *dbenv, const char *msg) "db_msgcall_fcn" + void set_msgcall(void (*db_msgcall_fcn)(const DB_ENV *dbenv, const char *msg)) { + self->set_msgcall(self, db_msgcall_fcn); + } + + int set_msgfile(char *msgfile) { + int ret; + FILE *fmsg; + ret = 0; + fmsg = NULL; + self->get_msgfile(self, &fmsg); + if (fmsg != NULL && fmsg != stdout && fmsg != stderr) { + fclose(fmsg); + fmsg = NULL; + } + if (strcmp(msgfile, "") == 0 || msgfile == NULL) + self->set_msgfile(self, NULL); + else if (strcmp(msgfile, "stdout") == 0) + self->set_msgfile(self, stdout); + else if (strcmp(msgfile, "stderr") == 0) + self->set_msgfile(self, stderr); + else { + fmsg = fopen(msgfile, "a"); + if (fmsg != NULL) { + self->set_msgfile(self, fmsg); + } + else + ret = 1; + } + return ret; + } int get_thread_count(u_int32_t *count) { return self->get_thread_count(self, count); @@ -2213,7 +2449,7 @@ typedef struct __dbenv } } DB_ENV; -typedef struct __key_range { +typedef struct { %typemap(csvarin) double less %{%} double less; %typemap(csvarin) double equal %{%} @@ -2222,7 +2458,7 @@ typedef struct __key_range { double greater; } DB_KEY_RANGE; -typedef struct __db_lock_u { +typedef struct { roff_t off; /* Offset of the lock in the region */ u_int32_t ndx; /* Index of the object referenced by * this lock; used for locking. */ @@ -2230,7 +2466,7 @@ typedef struct __db_lock_u { db_lockmode_t mode; /* mode of this lock. */ } DB_LOCK; -typedef struct __db_lockreq { +typedef struct { db_lockop_t op; /* Operation. */ db_lockmode_t mode; /* Requested mode. */ db_timeout_t timeout; /* Time to expire lock. */ @@ -2285,7 +2521,10 @@ size_t alloc_dbt_arr(DB_ENV *dbenv, int num_dbt, void **ptr) { -typedef struct __db_preplist { +typedef struct { + %typemap(cstype) u_int8_t [DB_GID_SIZE] "byte[]" + %typemap(imtype) u_int8_t [DB_GID_SIZE] "byte[]" + %typemap(csout, excode=SWIGEXCODE) u_int8_t [DB_GID_SIZE] "{byte[] res = (byte [])($imcall); $excode; return res;}" %typemap(csvarin) u_int8_t gid[DB_GID_SIZE] %{%} %typemap(csvarout) u_int8_t gid[DB_GID_SIZE] %{ get { @@ -2311,7 +2550,7 @@ typedef struct __db_preplist { return ret; } %} -typedef struct __db_sequence { +typedef struct { %extend { DB_SEQUENCE(DB *dbp, u_int32_t flags) { DB_SEQUENCE *seq = NULL; @@ -2330,7 +2569,7 @@ typedef struct __db_sequence { return self->close(self, flags); } - int get(DB_TXN *txn, int32_t delta, db_seq_t *retp, u_int32_t flags) { + int get(DB_TXN *txn, u_int32_t delta, db_seq_t *retp, u_int32_t flags) { return self->get(self, txn, delta, retp, flags); } @@ -2357,10 +2596,10 @@ typedef struct __db_sequence { return self->remove(self, txn, flags); } - int get_cachesize(int32_t *size) { + int get_cachesize(u_int32_t *size) { return self->get_cachesize(self, size); } - int set_cachesize(int32_t size) { + int set_cachesize(u_int32_t size) { return self->set_cachesize(self, size); } |