-- DBCommon.mesa
-- Last edited by
--   MBrown on December 14, 1982 2:16 pm
--   Cattell on  November 10, 1983 2:10 am
--   Willie-Sue on: May 3, 1983 10:26 am

  DIRECTORY
    Atom USING [GetPropFromList],
    Commander USING [Handle],
    PrincOps USING [wordsPerPage],
    IO USING [STREAM],
    ProcessProps USING [GetPropList];

DBCommon: DEFINITIONS IMPORTS Atom, ProcessProps = BEGIN
  -- This interface contains things that don't fit anywhere else.

  softwareCompatibilityVersion: INTEGER = 3;
    -- Version of DB software.  Attempt to use wrong version will produce
    --ERROR BadOperation[SoftwareCompatibilityVersionCheck].

  DBPage: TYPE = LONG CARDINAL;
    -- "Virtual address" of a page in a database.  Interpreted by the segment implementation
    --only.  DBSegmentPrivate and DBStorageTID include definitions relevant to more
    --detailed interpretation.
  NullDBPage: DBPage = 0;
    -- A DBPage address that represents "no page" (NIL, used to terminate lists).
  NotOnList: DBPage = LAST[LONG CARDINAL];
    -- A DBPage address that represents "page not part of a list".

  PagesPerDBPage: CARDINAL = 1;
  WordsPerPage: CARDINAL = PagesPerDBPage * PrincOps.wordsPerPage;
    -- the rest are all defined in terms of WordsPerPage
  BytesPerPage: CARDINAL = 2*WordsPerPage;
  LogOfWordsPerPage: CARDINAL = 8;
  LogOfBytesPerPage: CARDINAL = LogOfWordsPerPage+1;
  MaskOfWordsPerPage: CARDINAL = WordsPerPage-1;
  MaskOfBytesPerPage: CARDINAL = BytesPerPage-1;

  PagesForBytes: PROC [nBytes: LONG CARDINAL] RETURNS[CARDINAL] = INLINE {
    RETURN[nBytes/BytesPerPage]};

  VersionOptions: TYPE = {NewFileOnly, OldFileOnly, None};
    -- Versions that may be specified to ObtainFile.

  Trans: TYPE = REF ANY;
    -- Represents transaction throughout the database system.  May Pilot, Juniper, or Alpine
    --transaction.

  Segment: TYPE = ATOM;
    -- The atom's PName is the full path name of file.

  SegmentIndex: TYPE = INT [0..512);
    -- Number assigned to a segment.

  SegmentID: TYPE = DBPage; -- with lots of low-order zeroes.

  OpenFileHandle: TYPE = REF ANY;
    -- Open file.  May Pilot, Juniper, or Alpine file.

  FileSystem: TYPE = { pilot, juniper, alpine };


-- Common IO stream procs

  GetDebugStream: PROC RETURNS [IO.STREAM] = INLINE
    -- Gives a place to print debugging info; creates Viewer typescript on screen.
    { ch: Commander.Handle←
       	NARROW[Atom.GetPropFromList[ProcessProps.GetPropList[], $CommanderHandle]];
      RETURN [ch.out]};


END.--DBCommon


--  Module History

Created by MBrown on December 5, 1979  9:50 AM

Changed by MBrown on December 5, 1979  11:57 AM
  -- Moved SIGNALs to DBSignalDefs.

Changed by Suzuki on December 6, 1979 12:39 PM
  -- Changed the definition of TransactionId.

Changed by Suzuki on December 7, 1979  8:42 AM
  -- Changed the definition of LongJFHandle.

Changed by MBrown on December 9, 1979  9:02 PM
  -- Defined BrokenLockNotification.

Changed by Suzuki on December 14, 1979  2:18 PM
  -- Deleted TransactionId and BrokenLockNotification.

Changed by MBrown on January 4, 1980  2:34 PM
  -- Changes for new file and cache interfaces: DBPage moves here, and WordsPerPage
  --and BytesPerPage are defined; VersionOptions is no longer in the cache interface,
  --so it moves to DBStorageDefs.

Changed by Suzuki on January 14, 1980  11:32 AM
  -- LogOf and MaskOf for WordsPerPage and BytesPerPage are added.

Changed by MBrown on February 21, 1980  10:34 AM
-- Added NullDBPage.  Moved VersionOptions back here (!) because it is now needed in the segment
--interface.

Changed by MBrown on July 24, 1980  9:23 PM
-- Added NotOnList.

Changed by MBrown on December 7, 1980  8:48 PM
-- Added softwareCompatibililtyVersion.

Changed by MBrown on December 8, 1980  3:21 PM
-- Added PagesForBytes.

Changed by MBrown on February 27, 1981  1:27 PM
-- Added Transaction.  InlineDefs -> Inline.

Changed by Rick on  6-Jun-81 13:14:49
-- New software version since some tuple level constants stored in database changed.

Changed by Willie-Sue on June 30, 1982 4:14 pm
--  Added GetDebugStream proc, so as not to use PrivateIO

Changed by Rick on July 9, 1982 4:55 pm
--  Changed definition of Transaction to be FileIO.Trans.  This is cleaner than LOOPHOLEing into a POINTER TO [CARDINAL] as we were before!

Changed by MBrown on November 24, 1982 5:36 pm
--  Changed definition of Transaction to be REF ANY.  Added FileSystem.alpine.  Rolled
--softwareCompatibilityVersion for segment changes.

Changed by Cattell on December 20, 1982 4:53 pm
-- Moved DBLogStream stuff here.

Changed by Cattell on January 17, 1983 5:49 pm
-- Removed FlushLogStream, GetLogStream; the latter was only used by DBModelGlobalImpl.  Made GetDebugStream INLINE.  Now no longer need DBCommonImpl.

Changed by Cattell on November 10, 1983 2:11 am
-- Changed Inline.LongDIV to an ordinary long cardinal division.