-- Registration Server - Defs for using heap as a registry.

-- [Juniper]<Grapevine>MS>RegistryDefs.mesa

-- J. Dion, September 10, 1979. 
-- Andrew Birrell  27-Oct-82 15:42:16

DIRECTORY
  BodyDefs USING [RName, Timestamp],
  HeapDefs USING [ReaderHandle, WriterHandle],
  ProtocolDefs USING [Connect, RNameType, Password];

RegistryDefs: DEFINITIONS =

  BEGIN

  Copy: PROC [reader: HeapDefs.ReaderHandle, writer: HeapDefs.WriterHandle];
  -- copies one component of an entry --

  Skip: PROC [reader: HeapDefs.ReaderHandle];
  -- skips one component of an entry --

  SkipIfEmpty: PROC [reader: HeapDefs.ReaderHandle] RETURNS [empty: BOOLEAN];
  -- skips one component if the component is empty, else no-op --

  WriteList: PROC [
    writer: HeapDefs.WriterHandle, name: BodyDefs.RName,
    stamp: BodyDefs.Timestamp];
  -- writes four components to the writer: an RList of one item, name,
  -- (or empty if name is NIL), a StampList of one item, stamp,
  -- (or empty if name is NIL), an empty RList, and an empty StampList.

  StartSublist: PROC RETURNS [HeapDefs.WriterHandle];

  AddNameToSublist: PROC [writer: HeapDefs.WriterHandle, name: BodyDefs.RName];

  EndSublist: PROC [writer: HeapDefs.WriterHandle, count: CARDINAL]
    RETURNS [reader: HeapDefs.ReaderHandle];
  -- writes component length and following stamp list and deleted list --

  EnumerateRList: PROC [
    reader: HeapDefs.ReaderHandle,
    work: PROC [BodyDefs.RName] RETURNS [done: BOOLEAN]];
  -- enumerates the R-Names in the current component --


  UpdateInfo: TYPE = {done, noChange, outOfDate};

  AddName: PROC [
    reader: HeapDefs.ReaderHandle, name: BodyDefs.RName,
    stamp: POINTER TO BodyDefs.Timestamp, writer: HeapDefs.WriterHandle]
    RETURNS [UpdateInfo];
  -- adds name to current list,copying list into writer. Returns "noChange"
  -- if name is already on list, "outOfDate" if name is already deleted
  -- with superior timestamp --

  RemoveName: PROC [
    reader: HeapDefs.ReaderHandle, name: BodyDefs.RName,
    stamp: POINTER TO BodyDefs.Timestamp, writer: HeapDefs.WriterHandle]
    RETURNS [UpdateInfo];
  -- removes name from current list, copying list into writer. Returns
  -- "noChange" if name is not on list, "outOfDate" if name is on list
  -- with superior timestamp --

  MergeLists: PROC [
    reader1, reader2: HeapDefs.ReaderHandle, writer: HeapDefs.WriterHandle]
    RETURNS [newer1, newer2: BOOLEAN];
  -- readers 1 and 2 must be positioned at the start of lists to be merged.
  -- Where the added and deleted sublists are considered as sets
  -- A1 A2 D1 D2 , the result contains the sublists A1 + A2 - (D1 + D2)
  -- and D1 + D2 - (A1 + A2),' with appropriate timestamps.
  -- The returned values specify whether information from each reader was
  -- copied to the merge lists.


  ReadPrefix: PROC [reader: HeapDefs.ReaderHandle, name: BodyDefs.RName]
    RETURNS [type: ProtocolDefs.RNameType, stamp: BodyDefs.Timestamp];
  -- reads the prefix of an entry --

  WritePrefix: PROC [
    writer: HeapDefs.WriterHandle, type: ProtocolDefs.RNameType,
    stamp: POINTER TO BodyDefs.Timestamp, name: BodyDefs.RName];
  -- writes a prefix for an entry --

  ReadPassword: PROC [reader: HeapDefs.ReaderHandle]
    RETURNS [pw: ProtocolDefs.Password, stamp: BodyDefs.Timestamp];
  -- reads the password of an individual.

  WritePassword: PROC [
    writer: HeapDefs.WriterHandle, pw: ProtocolDefs.Password,
    stamp: BodyDefs.Timestamp];
  -- writes the password at the current location in the heap object.

  ReadConnect: PROC [reader: HeapDefs.ReaderHandle, connect: ProtocolDefs.Connect]
    RETURNS [stamp: BodyDefs.Timestamp];
  -- Returns the connect-site of an individual.

  WriteConnect: PROC [
    writer: HeapDefs.WriterHandle, connect: ProtocolDefs.Connect,
    stamp: BodyDefs.Timestamp];
  -- writes the connect-site at the current location in the heap object.

  Comparison: TYPE = {less, equal, greater};

  CompareRNames: PROC [n1, n2: BodyDefs.RName] RETURNS [RegistryDefs.Comparison];

  CompareTimestamps: PROC [t1, t2: BodyDefs.Timestamp] RETURNS [Comparison];
  -- compares two timestamps in terms of temporal ordering.

  MakeTimestamp: PROCEDURE RETURNS [stamp: BodyDefs.Timestamp];
  -- produces a new unique timestamp, waiting if necessary.

  CheckStampList: PROC [reader: HeapDefs.ReaderHandle, limit: BodyDefs.Timestamp]
    RETURNS [old: BOOLEAN];
  -- checks whether any of the stamps are older than given value.
  -- If so, leaves reader at undefined point.

  FilterStampList: PROC [
    reader: HeapDefs.ReaderHandle, limit: BodyDefs.Timestamp,
    writer: HeapDefs.WriterHandle];
  -- Reader should be positioned at namelist component.
  -- Copies to writer the names and stamps newer than the limit.

  END.