?? RIGHT := 110 ??
MODULE osm$wait_on_condition;
?? RIGHT := 110 ??

{ PURPOSE:
{   This module contains the procedures that wait on a condition and display
{   the appropriate message for the job status display.
{   File server job recovery is initiated from this routine.

?? PUSH (LISTEXT := ON) ??
*copyc osd$virtual_address
*copyc dfe$error_condition_codes
*copyc ioe$st_errors
*copyc mme$condition_codes
*copyc dmt$error_condition_codes
*copyc ost$caller_identifier
*copyc ost$status
*copyc ost$status_condition_code
?? POP ??
*copyc dfp$check_job_recovery
*copyc ofp$display_status_message
*copyc ofp$get_display_status_message
*copyc pmp$cause_task_condition
*copyc pmp$delay
*copyc pmp$get_job_names
*copyc pmp$long_term_wait
?? TITLE := '[XDCL, #GATE] osp$clear_wait_message', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$clear_wait_message
    (    original_display_message: oft$display_message;
     VAR wait_message_displayed: {i/o} boolean);

    CONST
      continuing_message = 'Continuing: ',
      continuing_message_size = 12;

    VAR
      ignored_status: ost$status,
      message_length: integer,
      message_string: string (ofc$max_display_message);

    IF wait_message_displayed THEN
      IF original_display_message.text (1, continuing_message_size) = continuing_message THEN
        message_length := original_display_message.size;
        message_string := original_display_message.text (1, message_length);
      ELSE
        message_string := continuing_message;
        IF (continuing_message_size + original_display_message.size) > ofc$max_display_message THEN
          message_length := ofc$max_display_message;
        ELSE
          message_length := continuing_message_size + original_display_message.size;
        IFEND;
        message_string (continuing_message_size + 1, * ) :=
              original_display_message.text (1, original_display_message.size);
      IFEND;
      ofp$display_status_message (message_string (1, message_length), ignored_status);
      wait_message_displayed := FALSE;
      #SPOIL (wait_message_displayed);
    IFEND;

  PROCEND osp$clear_wait_message;

?? TITLE := '[XDCL, #GATE] osp$get_current_display_message', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$get_current_display_message
    (VAR current_display_message: oft$display_message);

    VAR
      local_display_message: oft$display_message,
      local_status: ost$status,
      system_supplied_name: jmt$system_supplied_name,
      user_name: jmt$user_supplied_name;

    pmp$get_job_names (user_name, system_supplied_name, {ignore} local_status);

    ofp$get_display_status_message (system_supplied_name, local_display_message, local_status);
    IF NOT local_status.normal THEN
      local_display_message.size := 7;
      local_display_message.text := 'UNKNOWN';
    IFEND;
    current_display_message := local_display_message;
  PROCEND osp$get_current_display_message;

?? TITLE := '[XDCL, #GATE] osp$wait_on_condition', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$wait_on_condition
    (    condition: ost$status_condition_code);

    CONST
      delay = 30000;

    VAR
      caller_id: ost$caller_identifier,
      original_display_message: oft$display_message,
      recovery_occurred: boolean,
      status: ost$status,
      strl: integer,
      str: string (80),
      wait_message_displayed: boolean;

    #CALLER_ID (caller_id);

    osp$get_current_display_message (original_display_message);

    IF condition = dme$unable_to_alloc_all_space THEN
      pmp$cause_task_condition ('OSC$SPACE_UNAVAILABLE          ', NIL, TRUE, FALSE, TRUE, FALSE, status);
      ofp$display_status_message (' Waiting for space.', status);
    ELSE
      pmp$cause_task_condition ('OSC$VOLUME_UNAVAILABLE         ', NIL, TRUE, FALSE, TRUE, FALSE, status);
      IF condition = ioe$unit_disabled THEN
        ofp$display_status_message (' Waiting for disabled unit.', status);
      ELSEIF condition = dfe$server_not_active THEN
        ofp$display_status_message (' Waiting for unavailable server', status);
      ELSEIF condition = dfe$server_has_terminated THEN
        { We should not be waiting on this condition.
        ofp$display_status_message (' Waiting for terminated server', status);
      ELSE
        ofp$display_status_message (' Waiting for unavailable volume.', status);
      IFEND;
    IFEND;
    wait_message_displayed := TRUE;
    {
    { Note. Currently we must do this on all conditions, because the monitor
    {  path always uses the condition of unavailable volume.
    {
    dfp$check_job_recovery (recovery_occurred);

    IF NOT recovery_occurred THEN
      IF caller_id.ring <= osc$tsrv_ring THEN
        {Cannot allow interruption of OS code
        pmp$delay (delay, status);
      ELSE
        {The following extra wait is required to "eat" xcb.wait_inhibited
        pmp$long_term_wait (1, 1);
        pmp$long_term_wait (30000, 30000);
      IFEND;
    IFEND;

    osp$clear_wait_message (original_display_message, wait_message_displayed);

  PROCEND osp$wait_on_condition;
MODEND osm$wait_on_condition;

