?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Operator Facility : System Header Display' ??
MODULE ofm$system_header_display;

{ This module contains the code that updates the system header line of the system console.
{ It also deals with updating time every day to assure its accuracy.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc dpc$console_row_size
*copyc ose$default_process_exceptions
*copyc oss$task_private
?? POP ??
*copyc dpp$set_title
*copyc dsp$log_dft_top_of_hour
*copyc ofp$report_status_error
*copyc osp$change_date_time
*copyc osp$change_hardware_date_time
*copyc osp$clear_defaults_changed_flag
*copyc osp$initialize_date_time
*copyc osp$update_wait_frc
*copyc pmp$get_date
*copyc pmp$get_os_version
*copyc pmp$get_time
*copyc pmp$log_ascii
?? EJECT ??
*copyc dpv$critical_display_id
*copyc dsv$mainframe_type
*copyc osv$170_os_type
*copyc osv$date_time_update
*copyc osv$os_defaults
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??
  VAR
    v$last_hour: [oss$task_private] string (2) := '00',
    v$title: [oss$task_private] string (dpc$console_row_size) := ' ';
?? OLDTITLE ??
?? NEWTITLE := 'ofp$system_header_display', EJECT ??

  PROCEDURE [XDCL] ofp$system_header_display;

    VAR
      current_time: ost$free_running_clock,
      date: ost$date,
      date_entry: string (78),
      date_entry_length: integer,
      hour: string (2),
      local_status: ost$status,
      time: ost$time,
      unused_os_defaults: ost$operating_system_default,
      version : pmt$os_name;

    { If, in dual state, the NOS operator has changed the date/time, OR if running on a Cyber 2000 mainframe
    { and the service processor has changed the date/time, update the NOS/VE date/time.  The hardware clock
    { has been updated by the NOS or by the service processor.

    IF osv$date_time_update AND ((osv$170_os_type <> osc$ot7_none) OR
          (dsv$mainframe_type = dsc$mt_2000_mainframe)) THEN
      osp$initialize_date_time (local_status);
      IF NOT local_status.normal THEN
        ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - initializing time and date');
      ELSE
        IF dsv$mainframe_type = dsc$mt_2000_mainframe THEN
          pmp$log_ascii ('System date/time changed by the service processor.',
                $pmt$ascii_logset [pmc$system_log, pmc$job_log], pmc$msg_origin_system, local_status);
        ELSE
          pmp$log_ascii ('System date/time changed by the NOS operator.',
                $pmt$ascii_logset [pmc$system_log, pmc$job_log], pmc$msg_origin_system, local_status);
        IFEND;
      IFEND;
    IFEND;

    { Update the hardware date/time at top of minute, if necessary.  If the current time is greater then
    { the maximum wait time then adjust the maximum wait time by multiples of one minute to be greater then
    { current time.  If the current time is between the minimum wait time and the maximum wait time then
    { change the hardware date/time.

    IF osv$os_defaults.time_data.wait_to_change THEN
      current_time := #FREE_RUNNING_CLOCK (0);
      IF current_time >= osv$os_defaults.time_data.wait_frc.max THEN
        osp$update_wait_frc (current_time);
      IFEND;
      IF (current_time >= osv$os_defaults.time_data.wait_frc.min) AND
            (current_time <= osv$os_defaults.time_data.wait_frc.max) THEN
        osp$change_hardware_date_time (local_status);
        IF NOT local_status.normal THEN
          ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - changing hardware date/time');
        IFEND;
      IFEND;
    IFEND;

    pmp$get_time (osc$hms_time, time, local_status);
    IF NOT local_status.normal THEN
      ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - getting time');
      hour := '00';
    ELSE
      v$title (44, 8) := time.hms;
      hour := time.hms (1, 2);
    IFEND;

    IF osv$os_defaults.defaults_changed THEN
      pmp$get_date (osc$mdy_date, date, local_status);
      IF NOT local_status.normal THEN
        ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - getting date');
      ELSE
        v$title (53, 10) := date.mdy;
      IFEND;
      pmp$get_os_version (version, local_status);
      IF NOT local_status.normal THEN
        ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - getting version');
      ELSE
        v$title (1, STRLENGTH(version)) := version;
      IFEND;
    IFEND;

    dpp$set_title (dpv$critical_display_id, v$title, local_status);
    IF NOT local_status.normal THEN
      ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - setting title');
    IFEND;

    IF osv$os_defaults.defaults_changed THEN
      osp$clear_defaults_changed_flag;
    IFEND;

    { Emit TOP-OF-HOUR statistics if the 'hour' part of the current time has changed and update the date/time
    { in the MRT if hour indicates midnight has occurred.

    IF hour <> v$last_hour THEN
      dsp$log_dft_top_of_hour;
      v$last_hour := hour;
      IF hour = '00' THEN
        osp$change_date_time (FALSE, unused_os_defaults, local_status);
        IF NOT local_status.normal AND (local_status.condition <> ose$not_allowed_in_dual_state) THEN
          ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - updating time at midnight');
        IFEND;
        pmp$get_date (osc$month_date, date, local_status);
        IF NOT local_status.normal THEN
          ofp$report_status_error (local_status, 'OFM$SYSTEM_HEADER_DISPLAY - getting date');
        IFEND;
        STRINGREP (date_entry, date_entry_length, '*********   CURRENT DATE IS NOW ', date.month);
        pmp$log_ascii (date_entry (1, date_entry_length), $pmt$ascii_logset [pmc$system_log, pmc$job_log],
              pmc$msg_origin_system, local_status);
      IFEND;
    IFEND;

  PROCEND ofp$system_header_display;
?? OLDTITLE ??
MODEND ofm$system_header_display;
