-- Copyright (C) 1983  by Xerox Corporation. All rights reserved. 
-- TimeServersLogNoDisk.mesa, HGM, 25-Jun-85  2:49:52

DIRECTORY
  Ascii USING [CR],
  Format USING [NetworkAddress],
  Put USING [Text],
  String USING [AppendChar, AppendLongDecimal, AppendString],
  System USING [broadcastHostNumber, GreenwichMeanTime, NetworkAddress, nullNetworkNumber],
  Time USING [Append, AppendCurrent, Unpack],
  
  NSConstants USING [timeServerSocket],
  TimeServerLog USING [];

TimeServersLogNoDisk: PROGRAM
  IMPORTS Format, Put, String, Time
  EXPORTS TimeServerLog =
  BEGIN

  StartLogging: PUBLIC PROCEDURE = BEGIN END;

  StopLogging: PUBLIC PROCEDURE = BEGIN END;
  
  LogInconsistancy: PUBLIC PROCEDURE [
    whoWith: System.NetworkAddress,
    myTime: System.GreenwichMeanTime, myError: LONG CARDINAL,
    theirTime: System.GreenwichMeanTime, theirError: LONG CARDINAL] =
    BEGIN
    text: STRING = [200];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: Inconsistancy noted with "L];
    AppendNetworkAddress[text, whoWith];
    String.AppendChar[text, '.];
    String.AppendChar[text, Ascii.CR];
    String.AppendString[text, "Local: "L];
    Time.Append[text, Time.Unpack[myTime], TRUE];
    String.AppendString[text, " +/- "L];
    String.AppendLongDecimal[text, myError];
    String.AppendString[text, ", remote: "L];
    Time.Append[text, Time.Unpack[theirTime], TRUE];
    String.AppendString[text, " +/- "L];
    String.AppendLongDecimal[text, theirError];
    LogString[text];
    END;
    
  LogClockChange: PUBLIC PROCEDURE [
    time: System.GreenwichMeanTime,
    delta: LONG INTEGER,
    whoFrom: System.NetworkAddress,
    errorAccurate: BOOLEAN,
    oldError: LONG CARDINAL,
    newError: LONG CARDINAL,
    flightTime: LONG CARDINAL,
    newVersion: LONG CARDINAL] =
    BEGIN
    text: STRING = [300];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: Time reset from "L];
    AppendNetworkAddress[text, whoFrom];
    String.AppendString[text, ", adjustment was "L];
    String.AppendLongDecimal[text, delta];
    IF newError # LAST[LONG CARDINAL] THEN
      BEGIN
      String.AppendChar[text, '.];
      String.AppendChar[text, Ascii.CR];
      String.AppendString[text, "The Clock error was "L];
      String.AppendLongDecimal[text, oldError];
      String.AppendString[text, " ms"L];
      END;
    IF newError # LAST[LONG CARDINAL] THEN
      BEGIN
      String.AppendChar[text, '.];
      String.AppendChar[text, Ascii.CR];
      String.AppendString[text, "The Clock error is "L];
      String.AppendLongDecimal[text, newError];
      String.AppendString[text, " ms"L];
      String.AppendString[text, ".  The flight time was "L];
      String.AppendLongDecimal[text, flightTime];
      String.AppendString[text, " ms"L];
      IF newVersion # 0 THEN
        BEGIN
        String.AppendString[text, ".  The new version is "L];
        String.AppendLongDecimal[text, newVersion];
        END;
      END;
    LogString[text];
    END;
    
  LogReset: PUBLIC PROCEDURE [whoSays, from: System.NetworkAddress] =
    BEGIN
    anywhere: System.NetworkAddress = [
      net: System.nullNetworkNumber,
      host: System.broadcastHostNumber,
      socket: NSConstants.timeServerSocket];
    text: STRING = [200];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: "L];
    AppendNetworkAddress[text, whoSays];
    String.AppendString[text, " told us to reset from "L];
    IF from = anywhere THEN String.AppendString[text, "the local net(s)"L]
    ELSE AppendNetworkAddress[text, from];
    LogString[text];
    END;

  LogStart: PUBLIC PROCEDURE [whoSays: System.NetworkAddress] =
    BEGIN
    text: STRING = [200];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: Started by "L];
    AppendNetworkAddress[text, whoSays];
    LogString[text];
    END;
  
  LogStop: PUBLIC PROCEDURE [whoSays: System.NetworkAddress] =
    BEGIN
    text: STRING = [200];
    Time.AppendCurrent[text];
    String.AppendString[text, "  TimeServer: Stopped by "L];
    AppendNetworkAddress[text, whoSays];
    LogString[text];
    END;
  
  LogString: PROCEDURE [text: LONG STRING] =
    BEGIN
    String.AppendChar[text, '.];
    String.AppendChar[text, Ascii.CR];
    Put.Text[NIL, text];
    END;

  AppendNetworkAddress: PROCEDURE [string: LONG STRING, address: System.NetworkAddress] =
    BEGIN
    Append: PROCEDURE [s: LONG STRING, clientData: LONG POINTER] =
      BEGIN String.AppendString[string, s]; END;
    Format.NetworkAddress[Append, address, productSoftware];
    END;
    
  END.