private BDbcMethods(IntPtr pdbc, BDbOffsetOf offsetOf, BerkeleyDbType dbType)
        {
            _offsetOf = offsetOf;
            _dbType   = dbType;

            foreach (BDbOffsetOfItem offsetOfItem in offsetOf.Dbc)
            {
                IntPtr funcptr = Marshal.ReadIntPtr(pdbc + offsetOfItem.Offset);
                switch (offsetOfItem.Name)
                {
                case "close":
                    _close = (close)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(close));
                    break;

                case "del":
                    _del = (del)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(del));
                    break;

                case "get":
                    _get = (get)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(get));
                    break;

                case "put":
                    _put = (put)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(put));
                    break;
                }
            }
        }
        public static BerkeleyDbError Create(BDbOffsetOf offsetOf, out IntPtr pdbenv)
        {
            var error = (BerkeleyDbError)env_create(out pdbenv, 0);

            if (error == 0)
            {
                CreateMethods(pdbenv, offsetOf);
            }
            return(error);
        }
        public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr pdb, BerkeleyDbType dbType, BerkeleyDbCursorFlags flags, out IntPtr pdbc)
        {
            BDbMethods      dbMethods = BDbMethods.GetMethods(dbType);
            BerkeleyDbError error     = dbMethods.Cursor(pdb, flags, out pdbc);

            if (error == 0)
            {
                CreateMethods(dbType, pdbc, offsetOf);
            }
            return(error);
        }
 private static BDbenvMethods CreateMethods(IntPtr pdbenv, BDbOffsetOf offsetOf)
 {
     if (_methods == null)
     {
         lock (typeof(BDbenvMethods))
         {
             if (_methods == null)
             {
                 _methods = new BDbenvMethods(pdbenv, offsetOf.Dbenv);
             }
         }
     }
     return(_methods);
 }
        private static BDbcMethods CreateMethods(BerkeleyDbType dbType, IntPtr pdbc, BDbOffsetOf offsetOf)
        {
            BDbcMethods dbcMethods = GetMethodsInternal(dbType);

            if (dbcMethods == null)
            {
                lock (typeof(BDbcMethods))
                {
                    dbcMethods = GetMethodsInternal(dbType);
                    if (dbcMethods == null)
                    {
                        dbcMethods = new BDbcMethods(pdbc, offsetOf, dbType);
                        switch (dbType)
                        {
                        case BerkeleyDbType.DB_BTREE:
                            _btree = dbcMethods;
                            break;

                        case BerkeleyDbType.DB_HASH:
                            _hash = dbcMethods;
                            break;

                        case BerkeleyDbType.DB_RECNO:
                            _recno = dbcMethods;
                            break;

                        case BerkeleyDbType.DB_QUEUE:
                            _queue = dbcMethods;
                            break;

                        case BerkeleyDbType.DB_UNKNOWN:
                            _unknown = dbcMethods;
                            break;

                        case BerkeleyDbType.DB_HEAP:
                            _heap = dbcMethods;
                            break;
                        }
                    }
                }
            }
            return(dbcMethods);
        }
        public static BDbOffsetOf SetInstance(BDbOffsetOf offsetOf)
        {
            if (_instance != null)
            {
                throw new InvalidOperationException("OffsetOf already created");
            }

            lock (typeof(BDbOffsetOf))
            {
                if (_instance != null)
                {
                    throw new InvalidOperationException("OffsetOf already created");
                }

                _instance = offsetOf;
            }

            return(_instance);
        }
Exemple #7
0
        public static BerkeleyDbError Create(BDbOffsetOf offsetOf, IntPtr penv, BerkeleyDbType dbType, BerkeleyDbFlags flags, out IntPtr pdb)
        {
            var error = (BerkeleyDbError)db_create(out pdb, penv, 0);

            if (error != 0)
            {
                return(error);
            }

            BDbMethods methods = CreateMethods(dbType, pdb, offsetOf);

            error = (BerkeleyDbError)methods.SetFlags(pdb, flags);
            if (error != 0 && pdb != IntPtr.Zero)
            {
                methods.Close(pdb, 0);
                pdb = IntPtr.Zero;
            }
            return(error);
        }
Exemple #8
0
        private BDbMethods(IntPtr pdb, BDbOffsetOf offsetOf, BerkeleyDbType dbType)
        {
            _dbType   = dbType;
            _offsetOf = offsetOf;

            foreach (BDbOffsetOfItem offsetOfItem in offsetOf.Db)
            {
                IntPtr funcptr = Marshal.ReadIntPtr(pdb + offsetOfItem.Offset);
                switch (offsetOfItem.Name)
                {
                case "close":
                    _close = (close)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(close));
                    break;

                case "cursor":
                    _cursor = (cursor)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(cursor));
                    break;

                case "del":
                    _del = (del)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(del));
                    break;

                case "get_pagesize":
                    _get_pagesize = (get_pagesize)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(get_pagesize));
                    break;

                case "open":
                    _open = (open)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(open));
                    break;

                case "put":
                    _put = (put)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(put));
                    break;

                case "set_flags":
                    _set_flags = (set_flags)Marshal.GetDelegateForFunctionPointer(funcptr, typeof(set_flags));
                    break;
                }
            }
        }