
*copyc OSD$DEFAULT_PRAGMATS
?? NEWTITLE := '170 NOS/VE REMOTE HOST' ??
MODULE rhmqft;

?? NEWTITLE := 'GLOBAL TYPE DECLARATIONS' ??
?? SET (LIST := OFF) ??
?? EJECT ??
*copyc RHT$FUNCTION_STATUS
*copyc RHC$CONSTANTS

?? TITLE := 'EXTERNAL PROCEDURES REFERENCED BY THIS MODULE' ??
?? SET (LIST := OFF) ??
?? EJECT ??
*copyc RHP$ACQUIRE_QUEUE_FILE
*copyc RHV$SIGNAL
*copyc RHP$LOG_STATUS
*copyc RHP$OPEN_FILE
*copyc RHP$RECEIVE_MESSAGE_OS
*copyc RHP$SEND_MESSAGE_OS
*copyc RHP$CLOSE_FILE
*copyc RHP$RETURN_FILE
*copyc RHP$ROUTE_FILE
*copyc RHP$WAIT
*copyc BIZCLOS
*copyc BIZOPEN
*copyc BIZPUT

  PROCEDURE [XREF] qfsend (lfn: integer;
        an170: integer;
        an180: integer;
    VAR detailed_status: integer;
    VAR qfsend_status: integer);

?? SET (LIST := ON) ??
?? TITLE := 'RHP$QUEUE_FILE_TRANSMIT_EXEC' ??
?? EJECT ??

{ RHP$QUEUE_FILE_TRANSMIT_EXEC
{
{     This procedure is responsible for the acquisition and subsequent
{ transfer of a queued file to its receiving partner application.  This
{ transfer includes the responsibilities of performing protocol
{ maintenance, file transmission control, and final file disposition.
{
{     RHP$QUEUE_FILE_TRANSMIT_EXEC (APPLICATION_NAMES,EXEC_STATUS)
{
{ APPLICATION_NAMES: (input) This parameter contains the sending and
{     receiving application names required for MLI communication.
{
{ EXEC_STATUS: (output) This parameter indicates to the calling
{     procedure the processing status of the executive.  The following
{     status values may be returned:
{                 beginning
{                 middle
{                 unrecoverable_error
{
{ LID_LIST: (input) This parameter specifies the pointer to the
{      list of lids that a site can route jobs from.
{
  PROCEDURE [XDCL] rhp$queue_file_transmit_exec ALIAS 'rhmqft' (VAR
    application_names: rht$mli_application_names;
    VAR exec_status: rht$exec_status;
    lid_list: ^cell);

    TYPE
      qtran_states = (acquire, get, dispose);

    CONST
      boi = rhc$beginning_of_information,
      moi = rhc$middle_of_information,
      eoi = rhc$end_of_information,
      errmsg_file_name = 'rhermsg',
      errmsg_dc_file_name = 22100522152307(8),
      completed = rhc$completed,
      delete_file = rhc$delete_file;

    VAR
      quanta_work_completed: boolean,
      qtran_state: [STATIC] qtran_states := acquire,
      tran_status: [STATIC] (ok, error) := ok,
      acquire_status: rht$acquire_status,
      status: ost$status,
      route_status: rht$function_status,
      local_file_info: [STATIC] rht$local_file_info,
      queue_file_info: [XDCL] rht$queue_file_info, { kludge for conv. serv.
      {architecture 4/16/80 RMD }
      abnormal_mli_stat_message: string(33),
      string_length: 1 .. 33,
      sender_name: mlt$application_name,
      message_info: [STATIC] rht$mli_message_info := [ * , 0, * , * ],
      errmsg_local_file_info: [STATIC] rht$local_file_info,
      errmsg_queue_file_info: [STATIC] rht$queue_file_info,
      errmsg: [STATIC] packed ARRAY [0..39] of
              0 .. 03fffffff(16) :=
              [ 0061000000(8), 0000000000(8),  {1}
                0060000000(8), 0000000000(8),  {0}
                0040005500(8), 5501050122(8),  { --ER}
                0122011701(8), 2200550055(8),  {ROR--}
                0040004001(8), 1601170123(8),  {  NOS}
                0057012601(8), 0500400112(8),  {/VE J}
                0117010200(8), 4001040111(8),  {OB DI}
                0104004001(8), 1601170124(8),  {D NOT}
                0040010701(8), 0501240040(8),  { GET }
                0122011701(8), 2501240105(8),  {ROUTE}
                0104004001(8), 0401250105(8),  {D DUE}
                0040012401(8), 1700400114(8),  { TO L}
                0117010701(8), 1101160040(8),  {OGIN }
                0103011701(8), 1501150101(8),  {COMMA}
                0116010400(8), 4001150111(8),  {ND MI}
                0123012301(8), 1101160107(8),  {SSING}
                0040011701(8), 2200400111(8),  { OR I}
                0116010301(8), 1701220122(8),  {NCORR}
                0105010301(8), 2400560000(8),  {ECT.}
                0062000000(8), 0000000000(8) ],  {2}
      errmsg_file: file,
      detailed_status,
      qfsend_status: integer;

{ * * * * * * *   T R A N S M I T   A    Q U E U E   F I L E   * * * * * * *

    quanta_work_completed := FALSE;

  /control_loop/
    WHILE NOT quanta_work_completed DO
      CASE qtran_state OF

{ Acquire the queue file that is to be transmitted.

      = acquire =
        rhp$acquire_queue_file (local_file_info, queue_file_info,
          lid_list, acquire_status);
        IF acquire_status = acquired THEN
          rhp$open_file (local_file_info);
          message_info.message_area := ^queue_file_info.equalizer;
          message_info.message_length := #SIZE (queue_file_info.equalizer);
          message_info.arbitrary_info := boi;
          qtran_state := get;

          /send_info/
          REPEAT
            rhp$send_message_os (application_names.application.application_name,
              message_info.arbitrary_info, rhv$signal, message_info.message_area,
              message_info.message_length, application_names.destination.application_name,status);
            IF status.normal THEN
              log_status (dayfile_log_and_display, 'BEGIN XFER NOSVE INPUT JOB');
            ELSE
              CASE status.condition OF
              = mlc$busy_interlock, mlc$pool_buffer_not_avail,
                mlc$prior_msg_not_received =
                wait(1000);
                CYCLE /send_info/;
              ELSE
                abnormal_mli_stat_message (1,26) := 'send msg mli abnorm cond =';
                STRINGREP (abnormal_mli_stat_message (27,3), string_length, status.condition);
                log_status (dayfile_log, abnormal_mli_stat_message (1, 26+string_length));
                tran_status := error;
                exec_status := beginning;
                qtran_state := dispose;
                CYCLE /control_loop/;
              CASEND;
            IFEND;
          UNTIL status.normal;  { send_info }
        ELSE
          exec_status := beginning;
          quanta_work_completed := TRUE;
        IFEND;

{ Get data from local queue file to transmit.

      = get =
        qfsend (local_file_info.fet.filename, application_names.application.
              application_name, application_names.destination.application_name,
              detailed_status, qfsend_status);
        CASE qfsend_status OF
        = moi =
          qtran_state := get;
          exec_status := middle;
          quanta_work_completed := TRUE;
        = eoi =
          qtran_state := dispose;
          tran_status := ok;
          exec_status := middle;
        ELSE
          tran_status := error;
          qtran_state := dispose;
          exec_status := middle;
        CASEND;

{ Return local file if data transmitted okay, or route file back to the queue.

      = dispose =

        IF tran_status = ok THEN
          /receive_loop/
          REPEAT
            rhp$receive_message_os (application_names.application.application_name,
              message_info.arbitrary_info, rhv$signal, message_info.message_area,
              message_info.message_length, message_info.message_area_length,
              0{ for receive any pending message }, sender_name, status);
            IF (status.normal) OR (status.condition = mlc$signal_failed_ignored) THEN
              CASE message_info.arbitrary_info OF
              = completed =
                tran_status := ok;
              = delete_file =
                BI#OPEN (errmsg_file, errmsg_file_name, new#, output#, first#);
                BI#PUT (errmsg_file, #LOC (errmsg), #SIZE (errmsg));
                BI#CLOSE (errmsg_file, first#);
                errmsg_local_file_info.fet.filename := errmsg_dc_file_name;
                errmsg_queue_file_info.a170.form_code := '  ';
                errmsg_queue_file_info.a170.repeat_count := 1;
                errmsg_queue_file_info.a170.family_name_of_creator.a170_creator_family_name :=
                      queue_file_info.a170.family_name_of_creator.a170_creator_family_name;
                errmsg_queue_file_info.a170.user_number_of_owner.a170_owner_user_num :=
                      queue_file_info.a170.user_number_of_owner.a170_owner_user_num;
                errmsg_queue_file_info.a170.user_project_number :=
                      queue_file_info.a170.user_project_number;
                errmsg_queue_file_info.a170.user_charge_number :=
                      queue_file_info.a170.user_charge_number;
                errmsg_queue_file_info.a170.logical_identifier.a170_logical_identifier :=
                      queue_file_info.a170.logical_identifier.a170_logical_identifier;
                errmsg_queue_file_info.a170.implicit_text_size := queue_file_info.a170.implicit_text_size;
                errmsg_queue_file_info.a170.implicit_routing_text :=
                    queue_file_info.a170.implicit_routing_text;
                route_file (receive_exec, errmsg_local_file_info, errmsg_queue_file_info, route_status);
                tran_status := ok;
              ELSE
                tran_status := error;
              CASEND;
            ELSE
              CASE status.condition OF
              = mlc$busy_interlock, mlc$receive_list_index_invalid =
                wait (1000);
                CYCLE /receive_loop/;
              = mlc$nosve_not_up =
                log_status (dayfile_log, '$loss of dual state environment');
                tran_status := error;
                EXIT /receive_loop/;
              ELSE
                tran_status := error;
                abnormal_mli_stat_message (1,29) := 'receive msg mli abnorm cond =';
                STRINGREP (abnormal_mli_stat_message(30,3), string_length, status.condition);
                log_status (dayfile_log, abnormal_mli_stat_message (1,29+string_length));
                EXIT /receive_loop/;
              CASEND;
            IFEND;
        UNTIL status.normal; { receive_loop }
        IFEND;
        rhp$close_file (local_file_info);
        IF tran_status = ok THEN
          return_file (local_file_info);
          log_status (dayfile_log_and_display, 'END XFER NOSVE INPUT JOB');
        ELSE
          route_file (transmit_exec, local_file_info, queue_file_info,
            route_status);
          tran_status := ok;
          log_status (dayfile_log_and_display, 'ERROR END XFER NOSVE INPUT JOB');
        IFEND;
        qtran_state := acquire;
        quanta_work_completed := TRUE;
      CASEND;
    WHILEND /control_loop/;

  PROCEND rhp$queue_file_transmit_exec;

MODEND rhmqft;
