/* **********************************************************************
 * *	                                                                *
 * *      IRIS Structures and Definitions Related to Product Output     *
 * *                                                                    *
 * **********************************************************************
 * File: include/output.h
 *
 *  COPYRIGHT (c) 1992, 1993, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
 *                           2003, 2004  BY
 *         SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 *
 * Include Requirements : sigtypes.h
 *                        headers.h
 */
#ifndef SIGMET_OUTPUT_H
#define SIGMET_OUTPUT_H 1

#ifdef __cplusplus
extern "C" {
#endif

struct archive_info
{
  UINT2 itape_cmd;                      /* Tape Process command */

/* The mode will be set to "none" when it is finished with the operation */
  UINT2 itape_mode;                     /* Archive command being executed */
#define TPC_DONE        (0)             /*No command, or "done" */
#define TPC_MOUNT       (1)             /*Mount and identify new tape */
#define TPC_UNMOUNT     (2)             /*Unmount and release tape */
#define TPC_INVENTORY   (3)             /*Make new inventory file*/
#define TPC_RECORD      (4)             /*Write data as it becomes available*/
#define TPC_RETRIEVE    (5)             /*Read taged products from tape*/
#define TPC_STOP        (6)             /*Stop tape operation*/

  UINT2 ltape_full;                     /* Tape is full */

  UINT2 ltape_wenab;                    /* Tape is write enabled */

  UINT2 ltape_bot;                      /* Beginning/End of Tape */
  UINT2 ltape_eot;

  SINT4 itfile;                         /*Present file position of tape*/
      
  UINT2 itape_action;                   /*What archive device is doing*/
#define TPD_IDLE       (0)
#define TPD_REWIND     (1)
#define TPD_READ       (2)
#define TPD_WRITE      (3)
#define TPD_SEARCH    (4)
#define TPD_UNAVAIL    (5)          /*Could not assign to drive*/
#define TPD_OFFLINE    (6)          /*Assign OK, but switched offline*/
#define TPD_NONIRIS    (7)          /*Not IRIS format*/
#define TPD_RELEASED   (8)          /*Released*/
#define TPD_BUSY       (9)          /*Device is busy, could not be mounted*/
  char ipad18x2[2];

};

/* ----------------- Archive Inventory and Header Structures --------------------
 * The following record appears at the beginning of all IRIS tapes, and serves
 * to identify those tapes when loaded onto a drive.  The record is always
 * followed by an EOF.
 */
#define TAPE_HEADER_RECORD_SIZE (320)
#define SVER_TAPE_HEADER     (2)     /* Tape_header_record */
struct tape_header_record
{
  struct structure_header hdr;       /* Generic Header */
  char stape_id[16];                 /* Tape identification, space padded */
  char sitename[16];                 /* Name of site that created tape, space padded */
  struct ymds_time init_time;        /* Time that tape was created */
  SINT2 idrive;                      /* Drive # that created tape */
  char ipad58x2[2];
  char sversion[8];                  /* IRIS version, null terminated */
  char ipad_end[252];
};

/* Disk resident inventories of tapes are made by writing the /TAPE_INVENTORY/
 * structure to a file having the same name as the Tape ID.  The number of
 * one_tape_product records that are written is variable, depending on the
 * actual contents of the tape so far.  The file is variable-length unformatted
 * record organization.
 */
#define ONE_TAPE_PRODUCT_SIZE (84 + PSI_SIZE)
struct one_tape_product
{
  SINT4 ibytes;                         /*Size in bytes*/
  UINT1 isite_num;                      /*Site number*/
  UINT1 idata_out;                      /*Data Type Code*/
  SINT2 iYSize;
  char spname[12];                      /*Task and Product config names*/
  struct ymds_time ing_time;            /*Data time */
  char stname[12];                      /* Space padded */
  UINT2 iptype;                         /*Product type code*/

  UINT2 iflags;                         /*File Status*/
#define OTP_ON_DISK    (0x0002)       /* On Disk (and tape) */
#define OTP_ON_DISK_P  (0x0002)       /* On Disk (and tape) */
#define OTP_RETRIEVE   (0x0004)       /* To be recovered from tape */
#define OTP_RETRIEVE_P (0x0004)       /* To be recovered from tape */
#define OTP_ERROR      (0x0008)       /* Tape error(s) in this product */
#define OTP_ERROR_P    (0x0008)       /* Tape error(s) in this product */
  SINT4 ixscale, iyscale;               /*Scale factors */
  SINT2 iXSize, iZSize;                 /*Dimensions*/
  PSI psi;                              /*Info for each product type*/
  char sfile_name[24];                  /*File name on MO, zero terminated */
};

/* Header structure used for communication with the iris client interface.
 * One sent first before the tape inventory.
 */ 
struct server_tapelist_header
{
  SINT4 ilist_max;         /* Maximum number of products allowed in the inventory */
  SINT4 isend_max;         /* Maximum number of products that will be sent */
  SINT4 ilist_num;         /* Total number of products in the inventory */
  SINT4 isend_num;         /*       number of products which are being sent */
  SINT4 ilist_kbytes;      /* Total size of products in the inventory */
  SINT4 isend_kbytes;      /*       size of products which are being sent */

  UINT4 itape_cmd;         /* Tape Process command */

  /* The mode will be set to "none" when it is finished with the operation */
  UINT4 itape_mode;        /* Tape command being executed (defs above) */
  UINT4 itape_action;      /* What tape drive is doing (defs above)*/

  UINT4 ltape_mounted;     /* Tape is mounted, variables below are defined */
  UINT4 lpartial;          /* Inventory is incomplete */
  char stape_name[20];     /* Name of tape, null terminated */
  UINT4 ltape_full;        /* Tape is full */
  UINT4 ltape_wenab;       /* Tape is write enabled */
  UINT4 ltape_bot;         /* Beginning/End of Tape */
  UINT4 ltape_eot;
  SINT4 itfile;            /* Present file position of tape */
  SINT4 iDvdBufferKBytes;  /* If DVD then display DVD Buffer K Bytes */
  SINT4 iArchiveSubType;   /* Archive sub type could be DVD, TAPE, LDA.. */
};
typedef struct server_tapelist_header STAP_HDR;

struct server_tape_product
{
  SINT4 index;            /*Index of product on the tape, origin 1*/
  SINT4 ibytes;           /*Number of bytes*/
  char  spname[16];       /*Product name*/
  char  stname[16];       /*Task name*/
  UINT4 iptype;           /*Product type*/
  char  spsi_text[28];    /*Product specific text, null terminated*/
  UINT4 idata_out;        /*Data type*/
  struct serv_ymds_time ing_time; /*Time*/
  UINT4 iflags;           /*Flags*/
  UINT4 isite_num;        /*Site number*/
};
typedef struct server_tape_product STP_SUM;


/* Structure returned by server in reply to update command, size varies
 */
struct server_tape_update
{
  struct server_tapelist_header hdr;
  struct server_tape_product list[100];
};
typedef struct server_tape_update STAP_UPD;


#define ARCHIVE_INVENTORY_HDR_SIZE (360)
#define SVER_ARCHIVE_INVEN      (4)     /* archive_inventory version */
struct archive_inventory_header
{
  struct structure_header hdr;      /* Generic Header */
  UINT4 lvalid;                     /* Non-zero if information is valid */
  UINT4 lpartial;                   /* Non-zero if Inventory is not complete */
  char stape_id[16];                /* Tape identification */
  char sitename[16];                /* Name of site that created tape */
  struct ymds_time init_time;       /* Time that archive was initialized */
  SINT4 idrive;                     /* Drive # that created tape */
  SINT4 itape_version;              /* Version number of tape's header */

  struct linear_list_header lhead;  /* List header */
  struct kilo_count num_bytes;      /* # bytes for all products */

  UINT4 lmodified;                  /* Non-zero if inven != disk copy */
  UINT4 iarchive_type;              /* Type of archive media */
  struct kilo_count DvdBufferBytes; /* # bytes currently in a temporary buffer for DVD */

  char ipad_end[256];

};

/* The archive inventory actually consists of an array of linear list numbers
 * followed by an array of the one_tape_product structures.  The dimensions
 * are determined from setup questions.
 */
struct archive_inventory
{
  UINT4  isize;           /* Full size of the inventory structure for one device */
  UINT4  ioffset_to_OTP;  /* Offset within the device to the array of OTP structures */
  struct archive_info control;
  struct archive_inventory_header Head;
  SINT4  iLList[1];
  /* struct one_tape_product file[1]; */
};

#ifdef __cplusplus
}
#endif
#endif /* #ifndef SIGMET_OUTPUT_H */
