home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / rserv.h < prev    next >
C/C++ Source or Header  |  1993-11-05  |  3KB  |  137 lines

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: rserv.h,v 1.15 1993/06/23 05:21:22 kevinl Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *
  23.  *  recServer module
  24.  *
  25.  *  Original Author : Darren Platt
  26.  *
  27.  *-------------------------------------------------------------------------
  28.  * Revision History:
  29.  *
  30.  * $Log: rserv.h,v $
  31.  * Revision 1.15  1993/06/23  05:21:22  kevinl
  32.  * Mallocs are now in angular brackets
  33.  *
  34.  * Revision 1.14  1993/05/03  23:34:29  kevinl
  35.  * writeData and readData use theData instead of data
  36.  *
  37.  * Revision 1.13  1993/05/01  14:43:11  kevinl
  38.  * Removed ;'s from inlines
  39.  *
  40.  * Revision 1.12  1993/04/28  11:29:22  kevinl
  41.  * Fixing up some inlines
  42.  *
  43.  * Revision 1.11  1993/04/27  06:59:47  kevinl
  44.  * Comments
  45.  *
  46.  * Revision 1.10  1993/04/04  23:59:57  kevinl
  47.  * Added cache support
  48.  *
  49.  * Revision 1.9  1993/03/28  11:51:24  kevinl
  50.  * Modified for dbErr
  51.  *
  52.  * Revision 1.8  1993/03/28  19:09:22  davison
  53.  * deleted pError member.
  54.  *
  55.  * Revision 1.7  1993/03/26  06:16:38  darrenp
  56.  * standardized error codes.
  57.  *
  58.  * Revision 1.6  1993/03/24  06:21:47  kevinl
  59.  * Added error handling code
  60.  *
  61.  * Revision 1.5  1993/03/11  06:22:33  kevinl
  62.  * Added $ onto $Id and $Log in header
  63.  *
  64.  **************************************************************************/
  65.  
  66. #ifndef RSERV_INC_
  67. #define RSERV_INC_
  68.  
  69. #include <defs.h>
  70. #include <cache.h>
  71. #include <memory.h>
  72.  
  73. // Default number of entries in the cache
  74.  
  75. const DEF_RS_CACHE_SIZE = 10;
  76. struct rsHeader;
  77.  
  78. // the bitPool is a bitmap of used/unused records
  79.  
  80. struct bitPool {
  81.     short    bitsUsed;
  82.     unsigned    char    map[512];
  83.     inline void    zero(void) {
  84.                 // warning - method unfriendly.
  85.                 // memset(&dummy,0,sizeof dummy);
  86.                 // Yet again... tut tut tut
  87.                 memset(map, 0, sizeof map);
  88.                 bitsUsed = 0;
  89.             }
  90.         inline bitPool(void) { zero();}
  91. };
  92.  
  93. struct rsHeader {
  94.     long    recLength;
  95.     long    totalRecs;
  96.     long    recsUsed;
  97. };
  98.  
  99. class recServer : public cache {
  100.     public:
  101. //        dbError status;
  102. //        inline dbError rserror(dbError err) { return (status = err); };
  103.  
  104.         recServer(const char *name,long offset=0, long cSize = DEF_RS_CACHE_SIZE);
  105.         recServer(void);
  106.         ~recServer();
  107.         dbError    createDb(const char *name,long recLen,long offset=0, long cSize = DEF_RS_CACHE_SIZE);
  108.  
  109.         dbError getRec(long idx,void *buffer);
  110.         dbError putRec(long idx,void *buffer);
  111.         dbError newRec(long &newIdx);
  112.         dbError delRec(long idx);
  113.         bool     writeData(long offset,void *theData,long length);
  114.         bool    readData(long offset,void *theData,long length);
  115.         bool    isOpen;
  116.     private:
  117.         int        fd;
  118.         void    commonInit(void);
  119.         bool    getBitPool(long idx,bitPool &bp);
  120.         bool    putBitPool(long idx,bitPool &bp);
  121.         short    bitPoolBits; // how many bits stored in
  122.         long    currentPool;
  123.         short    bitPoolBytes;
  124.         short    bitPoolRecs; // 2^bitPoolRecs
  125.         long    idx2offset(long idx);
  126.         long    bpIdx2Offset(long idx);
  127.         bool    readHeader(rsHeader &);
  128.         bool    writeHeader(rsHeader &);
  129.         long    headerOffset;
  130.         long    dataOffset;
  131.         long    blockLength; // Length of one pool/block of records.
  132.         bitPool    indelPool;
  133.     protected:
  134.         rsHeader header;
  135. };
  136. #endif
  137.