/* **********************************************************************
 * *                                                                    *
 * *     Common variables and functions for archivein                   *
 * *                                                                    *
 * **********************************************************************
 * File: ts/exec/TsArchExec.h
 *
 *                     COPYRIGHT (c) 2003  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.
 */

#ifndef SIGMET_TSARCHEXEC_H
#define SIGMET_TSARCHEXEC_H

#ifdef TSARCHEXEC_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

/****************************************
** Global USER Created Classes 
******************************************/
/////////////////////////////////
// archFunc.C
/////////////////////////////////

#ifdef SIGMET_RVP8_H
class TsRec 
{
 private:
  FILE   *pRecordStream;
  UINT4  iRecordSize;     /* Total number of bytes written to the file */
  char   sRecordPath[PATHNAME_SIZE];
  UINT1  lRecordDataGap;  /* Indicates that there was a gap in the data */
  UINT2  iAqModeLast;     /* Valid modes are 0-255, so greater initial value will mismatch */
  UINT4  iSeqNum;         /* Next sequence number we want to record */
  UINT4  iTotalNPulses;
  void    writeToFile(Rvp8TS *pRvp8Ts_a);
  MESSAGE WritePulsesToFile(Rvp8TS *pRvp8Ts_a, UINT4 *pDirLen_a );
  void    closeFile(UINT4 idir_len_a);
  void    displayAttachedWriters(Rvp8TS *pRvp8Ts_a);
 public:
  void    record(Rvp8TS *pRvp8Ts_a);
};
EXTERN TsRec tsRec;

class TsPlay
{
 private:
 char *pInput;
  UINT2 lFileIsOpened;
  SINT4 iInSize, iInChannel;
  void    playbackFromFile(Rvp8TS *pRvp8Ts_a, UINT1 *plWriter_a );
  MESSAGE ReadPulsesFromFile( Rvp8TS *pRvp8Ts_a, char *spath_a);
  MESSAGE openFile(char *spath_a);
  void    closeFile(void);
 public:
  void    playback(Rvp8TS *pRvp8Ts_a, UINT1* plLastWriter_a );
};
EXTERN TsPlay tsPlay;
#endif  /* #ifdef SIGMET_RVP8_H */

class TsFunc 
{
  private:
    char *sFileNameCpy
      ( char *sDest_a, 
	const char *sSource_a,
	UINT4 iSize_a );   /* Size of dest.  Will be all zeroed, and null terminated */

  public:
    void printPulseInfo
      (volatile const struct rvp8PulseInfo *pInfo_a);
    void getDateTimeFromPulseHdr
      ( volatile const struct rvp8PulseHdr *pHdr_a,
	char sdate_time_a[FILENAME_SIZE]);
    void createArchiveFilename
      (volatile const struct rvp8PulseInfo *pInfo_a,
       volatile const struct rvp8PulseHdr *pHdr_a, 
       char sFilename_a[FILENAME_SIZE]);
    UINT4 fwriteAsciiPulseInfo
      (volatile const struct rvp8PulseInfo *pInfo_a,
       FILE *stream_a);
    UINT4 fwriteAsciiPulseHdr
      (volatile const struct rvp8PulseHdr *pHdr_a,
       FILE *stream_a);
    void EntryFromFileName
      ( struct one_ts_file *pFile_a,
	const char *sFile_a );
};
EXTERN TsFunc tsFunc;

EXTERN TsArchExec TsArch_c;

/* Mount a new directory */
void MountHandler
( const char *sMountDirectory_a );

/* Initialize a directory */
void InitHandler
( const char *sInitDirectory_a,  /* Directory to init.  Must match the current directory */
  const char *sInitTitle_a );    /* Title to give the directory */

#undef EXTERN

#endif   /* #ifndef SIGMET_TSARCHEXEC_H */

