?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE - Job Management: History Log Interfaces' ??
MODULE jmm$job_history_log_interfaces;

{ PURPOSE:
{   This module accesses the global log $HISTORY_LOG and positions the log at the
{   requested starting position. It retrieves an event and passes this information
{   back to the processor of job_history.
{
{ DESIGN:
{   This module has ring brackets of (2,3,D) such that it can access the global logs.
{   As little processing as possible is in this module so as to let users interrupt
{   the display command as they return from ring 3.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc jme$job_history_conditions
*copyc jml$user_id
*copyc jmt$beginning_log_position
*copyc jmt$system_supplied_name
*copyc jmt$user_supplied_name
*copyc ost$user_identification
*copyc sfd$type_declarations
*copyc sft$statistic_buffer
*copyc sft$global_log_statistic_header
?? POP ??
*copyc amp$get_next
*copyc fsp$open_file
*copyc osp$set_status_abnormal
*copyc osp$verify_system_privilege
*copyc pmp$get_compact_date_time
*copyc pmp$get_job_names
?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] jmp$ready_log_file', EJECT ??

{ PURPOSE:
{   The purpose of this procedure is to open and position the $HISTORY_LOG
{   at the requested position to start collection of job events.

  PROCEDURE [XDCL, #GATE] jmp$ready_log_file
    (    start_log_search: jmt$beginning_log_position;
         current_login_user: ost$user_identification;
         file: ^fst$file_reference;
     VAR buffer: sft$statistic_buffer;
     VAR file_position: amt$file_position;
     VAR p_header: ^sft$global_log_statistic_header;
     VAR p_descriptor: ^sft$descriptive_data;
     VAR input_file: amt$file_identifier;
     VAR status: ost$status);

    VAR
      attachment_options_p: ^fst$attachment_options,
      date_time: ost$date_time,
      ssn: jmt$system_supplied_name,
      temp_ssn: jmt$system_supplied_name,
      ujn: jmt$user_supplied_name;

    osp$verify_system_privilege;
    status.normal := TRUE;

    PUSH attachment_options_p: [1 .. 2];
    attachment_options_p^ [1].selector := fsc$access_and_share_modes;
    attachment_options_p^ [1].access_modes.selector := fsc$specific_access_modes;
    attachment_options_p^ [1].access_modes.value := $fst$file_access_options [fsc$read];
    attachment_options_p^ [1].share_modes.selector := fsc$determine_from_access_modes;
    attachment_options_p^ [2].selector := fsc$open_position;
    attachment_options_p^ [2].open_position := amc$open_at_boi;

    IF (file <> NIL) THEN

      fsp$open_file (file^, amc$record, attachment_options_p, NIL, NIL, NIL, NIL, input_file, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    ELSE
      fsp$open_file ('$HISTORY_LOG                   ', amc$record, attachment_options_p, NIL, NIL, NIL, NIL,
            input_file, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

    CASE start_log_search OF
    = jmc$today =
      pmp$get_compact_date_time (date_time, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
      jmp$get_log_entry (input_file, buffer, file_position, p_header, p_descriptor, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

    /search_log/
      WHILE file_position <> amc$eoi DO

        IF p_header^.date_time.year >= date_time.year THEN
          IF p_header^.date_time.month >= date_time.month THEN
            IF p_header^.date_time.day = date_time.day THEN
              EXIT /search_log/;
            IFEND;
          IFEND;
        IFEND;
        jmp$get_log_entry (input_file, buffer, file_position, p_header, p_descriptor, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      WHILEND /search_log/;

      IF file_position = amc$eoi THEN
        osp$set_status_abnormal ('JM', jme$end_of_log_reached, '', status);
        RETURN;
      IFEND;

    = jmc$session =
      pmp$get_job_names (ujn, ssn, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      jmp$get_log_entry (input_file, buffer, file_position, p_header, p_descriptor, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

    /find_starting_event/
      WHILE file_position <> amc$eoi DO

        IF p_header^.statistic_code = jml$job_queuing_started THEN
          temp_ssn := p_descriptor^ (1, jmc$system_supplied_name_size);
          IF temp_ssn = ssn THEN
            EXIT /find_starting_event/;
          IFEND;
        IFEND;
        jmp$get_log_entry (input_file, buffer, file_position, p_header, p_descriptor, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      WHILEND /find_starting_event/;

      IF file_position = amc$eoi THEN
        osp$set_status_abnormal ('JM', jme$end_of_log_reached, '', status);
        RETURN;
      IFEND;

    = jmc$boi =
      jmp$get_log_entry (input_file, buffer, file_position, p_header, p_descriptor, status);
    ELSE
    CASEND;

  PROCEND jmp$ready_log_file;
?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] jmp$get_log_entry', EJECT ??

{ PURPOSE:
{   The purpose of this request is to retrieve on job event and pass this on
{   for further processing.
{
{ NOTE:
{   If there are counters associated with a statistic they are ignored.  Job
{   history statistics should not contain counters.  This will be captured
{   in the processing module by the statistic_identifier in the statistic
{   header.

  PROCEDURE [XDCL, #GATE] jmp$get_log_entry
    (    file: amt$file_identifier;
     VAR buffer: sft$statistic_buffer;
     VAR file_position: amt$file_position;
     VAR p_header: ^sft$global_log_statistic_header;
     VAR p_descriptor: ^sft$descriptive_data;
     VAR status: ost$status);


    VAR
      byte_address: amt$file_byte_address,
      p_buffer: ^sft$statistic_buffer,
      p_counters: sft$counters,
      transfer_count: amt$transfer_count;

    osp$verify_system_privilege;
    amp$get_next (file, #LOC (buffer), #SIZE (buffer), transfer_count, byte_address, file_position, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    IF file_position <> amc$eoi THEN
      p_buffer := ^buffer;
      RESET p_buffer;
      NEXT p_header IN p_buffer;
      IF p_header^.number_of_counters <> 0 THEN
        NEXT p_counters: [1 .. p_header^.number_of_counters] IN p_buffer;
      IFEND;
      IF p_header^.descriptive_data_size > 0 THEN
        NEXT p_descriptor: [p_header^.descriptive_data_size] IN p_buffer;
      ELSE
        p_descriptor := NIL;
      IFEND;
    IFEND;
  PROCEND jmp$get_log_entry;
?? OLDTITLE ??
MODEND jmm$job_history_log_interfaces;
