?? RIGHT := 110 ??
?? NEWTITLE := ' NOS/VE File Server: Client/Server', EJECT ??
MODULE dfm$reset_mainframe_tables;

{ PURPOSE:
{   This module contains the code to reset tables associated
{   with a partner (server or client) mainframe when the partner is
{   re-activated.
{
{ NOTE:
{   It is assumed that the state of the partner is terminated and that there
{   is nothing which cannot be reset.

?? NEWTITLE := '    Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc dfc$poll_constants
*copyc dfd$driver_queue_types
*copyc dfe$error_condition_codes
*copyc dfi$display
*copyc dft$client_mainframe_file
*copyc dft$cpu_queue
*copyc dfv$false_queue_entry_flags
*copyc dfv$file_server_debug_enabled
*copyc dfv$null_global_task_id
*copyc dfv$p_queue_interface_directory
*copyc dfv$server_wired_heap
?? POP ??
*copyc dfp$build_client_mf_file_name
*copyc dfp$change_family_server_state
*copyc dfp$find_mainframe_id
*copyc osp$clear_locked_variable
*copyc osp$set_status_abnormal
*copyc osp$system_error
*copyc oss$job_paged_literal
*copyc pfp$purge
*copyc pfp$purge_catalog
*copyc pmp$get_compact_date_time
*copyc pmp$zero_out_table


?? TITLE := '    [XDCL] dfp$reset_mainframe_tables', EJECT ??

  PROCEDURE [XDCL] dfp$reset_mainframe_tables
    (    mainframe_name: pmt$mainframe_id;
         host_is_server_to_client: boolean;
     VAR status: ost$status);

    VAR
      active_queue_entry: boolean,
      character_index: 1 .. dfc$queue_assignment_strng_size,
      client_mainframe: pmt$mainframe_id,
      client_mainframe_name: ost$name,
      cycle_selector: pft$cycle_selector,
      display_size: integer,
      display_string: string (80),
      ignore_status: ost$status,
      mainframe_found: boolean,
      p_catalog_path: ^pft$path,
      p_cpu_queue: ^dft$cpu_queue,
      p_cpu_queue_entry: ^dft$cpu_queue_entry,
      p_cpu_queue_header: ^dft$cpu_queue_header,
      p_driver_queue: ^dft$driver_queue,
      p_mainframe_file_path: ^pft$path,
      p_queue_interface_table: dft$p_queue_interface_table,
      p_q_interface_directory_entry: ^dft$q_interface_directory_entry,
      q_d_index: dft$queue_directory_index,
      queue_index: dft$queue_index,
      queue_entry_index: dft$queue_entry_index,
      total_queue_entries: dft$queue_entry_index;

    status.normal := TRUE;
    dfp$find_mainframe_id (mainframe_name, host_is_server_to_client, mainframe_found,
          p_queue_interface_table, p_cpu_queue, queue_index, p_q_interface_directory_entry);
    IF NOT mainframe_found THEN
      osp$system_error (' UNKNOWN MAINFRAME - DFP$RESET_MAINFRAME_TABLES.', NIL);
    IFEND;
    IF dfv$file_server_debug_enabled THEN
      STRINGREP (display_string, display_size, 'dfp$reset_mainframe_tables ',
          mainframe_name, ' S->C ', host_is_server_to_client, ' Q', queue_index);
       display (display_string (1, display_size));
     IFEND;

    p_driver_queue := p_queue_interface_table^.queue_directory.driver_queue_pva_directory [queue_index].
          p_driver_queue;

    total_queue_entries := p_driver_queue^.queue_header.number_of_queue_entries;

    p_cpu_queue_header := ^p_cpu_queue^.queue_header;
    p_cpu_queue_header^.monitor_io [dfc$monitor_io].number_of_requests := 0;
    p_cpu_queue_header^.monitor_io [dfc$monitor_io].total_request_time := 0;
    p_cpu_queue_header^.monitor_io [dfc$monitor_io].max_request_time := 0;
    p_cpu_queue_header^.monitor_io [dfc$monitor_allocate].number_of_requests := 0;
    p_cpu_queue_header^.monitor_io [dfc$monitor_allocate].total_request_time := 0;
    p_cpu_queue_header^.monitor_io [dfc$monitor_allocate].max_request_time := 0;
    pmp$get_compact_date_time (p_cpu_queue_header^.transaction_data.
         transaction_start_time, ignore_status);
    osp$clear_locked_variable (p_cpu_queue_header^.transaction_data.total_transaction_count,
          { Best Guess = } 0);
    osp$clear_locked_variable (p_cpu_queue_header^.transaction_data.total_buffer_length_sent,
          { Best Guess = } 0);
    osp$clear_locked_variable (p_cpu_queue_header^.transaction_data.total_data_pages_sent,
          { Best Guess = } 0);
    osp$clear_locked_variable (p_cpu_queue_header^.transaction_data.total_buffer_length_received,
          { Best Guess = } 0);
    osp$clear_locked_variable (p_cpu_queue_header^.transaction_data.total_data_pages_received,
          { Best Guess = } 0);

    FOR character_index := 1 TO #SIZE (p_cpu_queue_header
          ^.queue_entry_assignment_table) DO
      IF character_index <= total_queue_entries THEN
        IF character_index = dfc$poll_queue_index THEN
          p_cpu_queue_header^.queue_entry_assignment_table (character_index) :=
                dfc$assigned_entry_char;
        ELSE
          p_cpu_queue_header^.queue_entry_assignment_table (character_index) :=
                dfc$free_entry_char;
        IFEND;
      ELSE
        p_cpu_queue_header^.queue_entry_assignment_table (character_index) :=
              dfc$pad_entry_char;
      IFEND;
    FOREND;

    FOR queue_entry_index := 1 to total_queue_entries DO
      p_cpu_queue_entry := ^p_cpu_queue^.queue_entries [queue_entry_index];
      p_cpu_queue_entry^.transaction_count := 0;
      p_cpu_queue_entry^.request_start_time := 0;
      p_cpu_queue_entry^.retransmission_count := 0;
      IF host_is_server_to_client THEN
        p_cpu_queue_entry^.transaction_state := dfc$server_waiting_request;
      ELSE
        p_cpu_queue_entry^.transaction_state := dfc$queue_entry_available;
      IFEND;
      p_cpu_queue_entry^.request_timeout_count := 0;
      p_cpu_queue_entry^.global_task_id := dfv$null_global_task_id;
      p_cpu_queue_entry^.data_pages_locked := FALSE;
      IF p_cpu_queue_entry^.processor_type = dfc$monitor THEN
        IF host_is_server_to_client THEN
          p_cpu_queue_entry^.p_server_iocb^.server_state := mmc$ss_waiting;
        ELSE
          p_cpu_queue_entry^.p_server_iocb := NIL;
        IFEND;
      IFEND;
      RESET p_cpu_queue_entry^.p_send_buffer;
      pmp$zero_out_table ( p_cpu_queue_entry^.p_send_buffer, #SIZE (
           p_cpu_queue_entry^.p_send_buffer^));
      RESET p_cpu_queue_entry^.p_receive_buffer;
      pmp$zero_out_table ( p_cpu_queue_entry^.p_receive_buffer, #SIZE (
           p_cpu_queue_entry^.p_receive_buffer^));

      p_driver_queue^.queue_entries [queue_entry_index].flags := dfv$false_queue_entry_flags;
      IF queue_entry_index = dfc$poll_queue_index THEN
        p_driver_queue^.queue_entries [queue_entry_index].flags.active_entry := TRUE;
      IFEND;
      p_driver_queue^.queue_entries [queue_entry_index].error_condition := 0;
      p_driver_queue^.queue_entries [queue_entry_index].held_over_cm_word_count := 0;
      p_driver_queue^.queue_entries [queue_entry_index].held_over_esm_division_number := 0;
      p_driver_queue^.queue_entries [queue_entry_index].data_descriptor.actual_length := 0;
      p_driver_queue^.queue_header.flags.idle := TRUE;
    FOREND;

    p_cpu_queue_entry := ^p_cpu_queue^.queue_entries [dfc$poll_queue_index];
    IF host_is_server_to_client THEN
{     Incase the Client Side has already sent the "verify_queue" POLL message
{     and 1. it is missed by the Server Side because activation of the PP driver
{     will clear the message in STORNET, or 2. in loopback, the PP driver dumped
{     the message because the Server Side queue entry was not active, set the
{     Server Side POLL queue entry's transaction_state to dfc$media_error.
{     If an "Inquiry_message" is received on the Server Side an "Inquiry_Response"
{     with a transaction_state of dfc$media_error will be returned to the Client.
{     When the Client Side recognizes the transaction_state of dfc$media_error
{     from the Server it will immediately retransmit the "verify_queue" POLL
{     message.
{     If/when the "verify_queue" POLL message is received on the Server Side,
{     the transaction_state will be changed to the appropriate state.
      p_cpu_queue_entry^.transaction_state := dfc$media_error;
    ELSE
{     This serves no purpose other than to accurately reflect the
{     transaction_state of the Client Side POLL queue entry.
      p_cpu_queue_entry^.transaction_state := dfc$queue_entry_assigned;
    IFEND;

  PROCEND dfp$reset_mainframe_tables;

MODEND dfm$reset_mainframe_tables;
