-- File: NameServerDefs.mesa - last edit:
-- AOF                  3-Feb-88 14:21:18
-- HGM                 30-Jun-84 10:48:54
-- Copyright (C) 1984, 1988 by Xerox Corporation. All rights reserved. 

DIRECTORY
  MFile USING [Handle],
  Stream USING [Handle],
  Window USING [Handle],

  Stats USING [StatCounterIndex],
  NSBuffer USING [Buffer],
  PupDefs USING [PupBuffer],
  PupTypes USING [PupType, PupAddress],
  Socket USING [ChannelHandle],
  PupWireFormat USING [BcplLongNumber],
  MiscServerDefs USING [
    lockDirRequest, lockDirReply, unlockDirRequest, unlockDirReply,
    nameStatsRequest, nameStatsReply,
    nameToCacheRequest, addressToCacheRequest, hereIsCacheEntry];

NameServerDefs: DEFINITIONS =
  BEGIN

  PupBuffer: TYPE = PupDefs.PupBuffer;
  PupAddress: TYPE = PupTypes.PupAddress;

  PupDirServerOn: PROCEDURE;
  PupDirServerOff: PROCEDURE;
  KickProber: PROCEDURE;
  PupDirServer: PROCEDURE [PupBuffer];
  PupNameServerOn: PROCEDURE;
  PupNameServerOff: PROCEDURE;
  PupNameServer: PROCEDURE [PupBuffer];
  NSNameServer: PROCEDURE [Socket.ChannelHandle, NSBuffer.Buffer];
  StartProbingForDirectory: PROCEDURE;
  GetOldDirectoryVersion: PROCEDURE RETURNS [version: CARDINAL, inTransit: BOOLEAN];
  GetNewDirectoryVersion: PROCEDURE RETURNS [version: CARDINAL, inTransit: BOOLEAN];
  EnumerateCache: PROCEDURE [PROCEDURE [CacheEntry]];
  UpdatePicture: PROCEDURE;

  lockDirRequest: PupTypes.PupType = MiscServerDefs.lockDirRequest;
  lockDirReply: PupTypes.PupType = MiscServerDefs.lockDirReply;
  unlockDirRequest: PupTypes.PupType = MiscServerDefs.unlockDirRequest;
  unlockDirReply: PupTypes.PupType = MiscServerDefs.unlockDirReply;

  nameStatsRequest: PupTypes.PupType = MiscServerDefs.nameStatsRequest;
  nameStatsReply: PupTypes.PupType = MiscServerDefs.nameStatsReply;
  
  nameToCacheRequest: PupTypes.PupType = MiscServerDefs.nameToCacheRequest;
  addressToCacheRequest: PupTypes.PupType = MiscServerDefs.addressToCacheRequest;
  hereIsCacheEntry: PupTypes.PupType = MiscServerDefs.hereIsCacheEntry;

  CacheEntry: TYPE = LONG POINTER TO CacheEntryObject;
  CacheEntryObject: TYPE = RECORD [
    next: CacheEntry,
    size: CARDINAL,
    count: LONG CARDINAL,
    sequence: CARDINAL,
    names: LONG DESCRIPTOR FOR ARRAY OF LONG STRING,
    addrs: LONG DESCRIPTOR FOR ARRAY OF PupAddress];


  -- Statistics
  statName, statAddress, statXlation, statConst, statBusy:
    Stats.StatCounterIndex;
  statSend, statVers: Stats.StatCounterIndex;
  statHits, statMisses, statNone, statFile: Stats.StatCounterIndex;
  statMsScanningFile: Stats.StatCounterIndex;

  NameStatsEntry: TYPE = RECORD [
    version: WORD,
    nameRequests: PupWireFormat.BcplLongNumber,
    directoriesSend: PupWireFormat.BcplLongNumber,
    cacheHits: PupWireFormat.BcplLongNumber,
    cacheMisses: PupWireFormat.BcplLongNumber];
  nameVersion: WORD = 1;

  SetCacheSize: PROCEDURE [CARDINAL];
  BumpCacheSize: PROCEDURE [INTEGER];


  -- internal things

  -- PupDirServer to PupNetDirFile and PupNetDirCache
  OpenDirectoryFiles: PROCEDURE;
  CloseDirectoryFiles: PROCEDURE;
  FlushWholeCache: PROCEDURE;
  GetStreamForOldDirectoryFile: PROCEDURE RETURNS [Stream.Handle];
  GetStreamForNewDirectoryFile: PROCEDURE RETURNS [Stream.Handle];
  CreateTempFile: PROCEDURE RETURNS [MFile.Handle, Stream.Handle];
  MakeTempFileIntoOldDirectoryFile: PROCEDURE [MFile.Handle] RETURNS [BOOLEAN];
  MakeTempFileIntoNewDirectoryFile: PROCEDURE [MFile.Handle] RETURNS [BOOLEAN];
  DeleteTempFile: PROCEDURE [MFile.Handle];

  -- PupNameServer to NetDirCache
  SearchCacheForName: PROCEDURE [LONG STRING, PROCEDURE [CacheEntry]] RETURNS [BOOLEAN];
  SearchCacheForAddress: PROCEDURE [PupAddress, PROCEDURE [CacheEntry]] RETURNS [BOOLEAN];
  ForceNameIntoCache: PROCEDURE [LONG STRING, PROCEDURE [CacheEntry]] RETURNS [BOOLEAN];
  ForceAddressIntoCache: PROCEDURE [PupAddress, PROCEDURE [CacheEntry]] RETURNS [BOOLEAN];

  -- NetDirCache to PupNetDirFile
  SearchNetDirForName: PROCEDURE [LONG STRING, CacheEntry] RETURNS [BOOLEAN];
  SearchNetDirForAddress: PROCEDURE [PupAddress, CacheEntry] RETURNS [BOOLEAN];

  PrintNameInfo: PROCEDURE [wh: Window.Handle];
  msg: Window.Handle;
  busy, nameRunning, dirRunning, probing, sending: BOOLEAN;


  END.