/*===========================================================================

 SIGBRU.H    Global variables and functions for SIGBRU 

=============================================================================*/

#ifdef SIGBRU_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

//#define DEBUG_PRINTF
#define SIG_BACKUP             1  //iCurMode
#define SIG_RESTORE            2  
#define SIG_LIST               3  
#define SIG_SKIP               4  
#define SIG_REWIND             5  

#define SIG_START               1   //iCurAction
#define SIG_CANCEL              2

#define SIG_NONE                0
#define SIG_AVAIL               1
#define SIG_INCLUDE             2
#define SIG_EXCLUDE             3

#define SIG_INC_IDX              1
#define SIG_DEC_IDX              2

#define SIG_SKIP_FWD             1
#define SIG_SKIP_REV             2

#define SIG_DEV_TYPE_UNKNOWN     0 
#define SIG_DEV_TYPE_HDD         1
#define SIG_DEV_TYPE_TAPE_LINUX  2
#define SIG_DEV_TYPE_TAPE_HPUX   3
#define SIG_DEV_TYPE_TAPE_IRIX   4
#define SIG_DEV_TYPE_DVD         5 

#define DVD_MOUNT_POINT          "/mnt/dvd"
#define DVD_DEVICE_TYPE          "/dev/dvd"
#define DVD_MAX_SIZE             (4000)   //4000 MB = 4 GB


#define MAX_ARGS      1000 
#define MAX_LIST_SIZE 10000
#define MAX_STR_LEN 300
struct IncExcStr
{
   char file[MAX_STR_LEN];
};


class Sigbru
{
 private:
    Cursor hourglassCursor;
 public:
    UINT2 lDebug;
    UINT2 lCheckSrcSize;
    UINT2 lHasAutoArchive;
    UINT2 lHasAutoArchiveEnabled;
    char  sIncludePath[100];
    char  sExcludePath[100];
    UINT2 lHasCompress;
    UINT2 lHasDeleteAfterArchive;
    char  sArchiveHost[50];
    FLT4  fQuota;
    FLT4  fCurSize;
    FLT4  fOldSize;
    char  sDevice[50];
    void  init(void);
    void  updateAvailFiles(void);
    void  getFilesSelected(UINT4 list_type_a, 
             XmStringTable *xsitems_a, UINT4 *num_xsitems_a);
    void  keepListSelected(UINT4 list_type_a);
    void  changeStartPB(UINT4 cur_action_a);
    void  setSenAll(UINT2 set_sen_a);
    void  modifyFilename(void);
    void  setAutoArchiveOM(UINT2 lset_a);
    void  setSenStartPB(UINT2 set_sen_a);
    UINT4 getCurMode(void);
    UINT4 getCurDeviceType(void);
    char  *getDeviceFileTxtF(void);
    void  setDeviceTxtF(UINT4 idev_type_a); 
    void  setSensitiveFilename(UINT4 idev_type_a, UINT4 icur_mode_a); 
    void  createHourglassCursor(void);
    void  setHourglassCursor(void);
    void  setPointerCursor(void);
    void  setCurPosition(UINT4 iskip_direction_a); 
    void  checkSkip(); 
    void  getSrcSize(); 
    void  checkSrcSize(); 
    void  checkRewind(); 
    void  popupDvdInfo(const char *smessage_a);
    void  popupDvdError(const char *smessage_a);
    void  popupDvdBusyError(const char *smessage_a);
};
EXTERN Sigbru sigbru;

class SigbruStat
{
  private:
  public:
     void create(swidget parent);
     void popup(void);
     void popdown(void);
     void write(const char *info);
     void writeStartMessage(void);
     void writeFinishMessage(void);
     void writeTerminateMessage(void);
     void writeCancelMessage(void);
     void writeCmdLineOpt(char *copy_to_dir, char *args_ptr_a[]);
};
EXTERN SigbruStat sigbruStat;

class SigbruErr
{
  private:
  public:
     void create(swidget parent);
     void popup(void);
     void popdown(void);
     void write(const char *err_type_a, const char *info_a);
};
EXTERN SigbruErr sigbruErr;

class SigbruFunc
{
 private:
    char   curDir[MAX_STR_LEN];
    char   sigbrushPath[160];
    UINT2  lCheckMatch(const char *str_a, char *new_str_a);
    void   pipeExec(char *args_ptr[]);
    pid_t  iSigbrushPID;
    UINT2  lTerminating;
 public:
    SigbruFunc(void);
    UINT2 lDvdIsMounted;
    UINT4  iSkipDirection;
    void  cleanupPipes(void);
    void  mountDvdAfterWrite(void);
    void  killAllProcesses(void);
    pid_t getSigbrushPID(void);
    UINT2 processesAreTerminating(void);
    UINT2 lFoundErrorData(const char *buf_a);
    UINT2 lCheckEnvirVariables(void);
    char  *getCurDir(void);
    void  getCurDirFiles(struct IncExcStr *current_a, UINT4 *num_current_a);
    void  getTaredFiles(struct IncExcStr *tared_a, UINT4 *num_tared_a);
    void  changeDir(const char *dir_a);

          // Backup
    void  sigbruBackup(UINT2 ltest_cmd_line_opt_a,
             char *hostname_a, char *device_file_a,
             char *tmp_file_a, UINT2 lcompress_a, 
             struct IncExcStr *include_a, UINT4 num_include_a,
             struct IncExcStr *exclude_a, UINT4 num_exclude_a);
          //Restore 
    void  sigbruRestore(UINT2 ltest_cmd_line_opt_a,
             char *hostname_a, char *device_file_a, char *restore_path_a,
             struct IncExcStr *restore_a, UINT4 num_restore_a);
          //List
    void  sigbruList(UINT2 ltest_cmd_line_opt_a,
             char *hostname_a, char *device_file_a);

          //Tape Skip
    void  sigbruSkip(UINT2 ltest_cmd_line_opt_a,
            char *hostname_a, char *device_file_a, UINT4 skip_direction);

          //Tape Rewind 
    void  sigbruRewind(UINT2 ltest_cmd_line_opt_a,
            char *hostname_a, char *device_file_a);

          //DVD Mount 
    UINT2 lCheckSigbruDvd(UINT2 ltest_cmd_line_opt_a, const char *device_file_a);

          //DVD Mount 
    void  mountDvd(UINT2 ltest_cmd_line_opt_a, const char *device_file_a);

          //DVD Unmount 
    void  unmountDvd(UINT2 ltest_cmd_line_opt_a, const char *mount_point_a);

          //DVD Unmount 
    void  unmountForceDvd(UINT2 ltest_cmd_line_opt_a, const char *device_file_a);

};
EXTERN SigbruFunc sigbruFunc;


#undef EXTERN
