/*
 *  Structures for what files are sent/received.
 */

/* Get OS stuff! */
#ifndef _WORK_DETAIL_

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_LISTS_H
#include <exec/nodes.h>
#endif
#ifndef EXEC_LISTS_H
#include <exec/lists.h>
#endif

#ifndef EXEC_SEMAPHORE_H
#include <exec/semaphores.h>
#endif

#ifndef _SITE_H_
#include "site.h"
#endif

/* Note: following structure is backward compatible. Thus the strange ordering */

typedef struct work_detail_node {
  struct Node dt_node;
  LONG dt_length;      /* length of Detail structure! */
  unsigned char  dt_flags;
  unsigned char  dt_status;
  unsigned short dt_time;
  signed char  dt_minPri;    /* No longer used!!!! */
  signed char  dt_maxPri;    /* Priority to send file */
#define dt_minCost  dt_minPri
#define dt_maxCost  dt_maxPri
#define dt_cost     dt_minPri
#define dt_priority dt_maxPri
  char *dt_filename;
  char *dt_asname;
  LONG dt_filelength;   /* In case anyone cares. Not filled in */
  LONG dt_future2;
  char dt_filenamebuf[1];
} work_detail_node;

/* priority --- Higher the priority, the more chances we have to send it */
/* range from -128 to +127 as with a node structure */
/* Note: This is not the cost. Cost determines when we will CONNECT to send */
/*  it, priority determines if we will send it once we are connected. */

#define DTPRI_MIN     (-128)
#define DTPRI_HOLD     (-50)  /* Reccomendation only */
#define DTPRI_NORM     0      /* Reccomendation only */
#define DTPRI_CRASH    50     /* Reccomendation only */
#define DTPRI_NETMAIL  75     /* Reccomendation only */
#define DTPRI_MAX      127

/* New DT_FLAGS --- bit! */
#define DTB_IFSENT      7     /* Let X= 'sent', else 'end of session' */
#define DTB_DELETE      6     /* delete if X      */
#define DTB_TRUNCATE    5     /* truncate if X    */
#define DTB_REQUEUE     4     /* requeue if not X */
#define DTF_IFSENT    (1<<DTB_IFSENT)
#define DTF_DELETE    (1<<DTB_DELETE)
#define DTF_TRUNCATE  (1<<DTB_TRUNCATE)
#define DTF_REQUEUE   (1<<DTB_REQUEUE)


#ifndef TRASH_OLD_PROGS
/* Old flags around for compatibility. */
#define OLD_DT_MAILBUNDLE   1     /* Default for mail bundles: truncate */
#define OLD_DT_FILEATTACH   2     /* Default for file attaches: nothing */
#define OLD_DT_DELETE       3     /* Delete after transfered. */
#define OLD_DT_TRUNCATE     4     /* Truncate after transfer. */
#define OLD_DT_SHOW_DELETE  5     /* "show" delete after. (?) */
#define OLD_DT_NOTHING      6     /* Don't do anything afterward */
#define OLD_DT_EXTRA_DELETE 7
#define OLD_DT_REQUEST      8     /* Delete if sent, don't recreate */
#endif

#define DT_TRUNCATE     DTF_IFSENT|DTF_TRUNCATE|DTF_REQUEUE
#define DT_FILEATTACH   DTF_IFSENT|DTF_REQUEUE
#define DT_DELETE       DTF_IFSENT|DTF_DELETE|DTF_REQUEUE
#define DT_SHOW_DELETE  DT_DELETE
#define DT_NOTHING      DT_FILEATTACH
#define DT_EXTRA_DELETE DT_DELETE
#define DT_REQUEST      DTF_REQUEUE|DTF_DELETE
#define DT_MAILBUNDLE   DT_TRUNCATE

/* Status flags */
#define DT_INTRANSIT 99
#define DT_SENT       0
#define DT_NOTSENT    1
#define DT_HUNGUP     2
#define DT_RETRIES    3
#define DT_ABORT      4
#define DT_REFUSED    5
#define DT_PRIREJ     6
#define DT_NOTFOUND  10     /* Any error greater than NOTFOUND will */
                            /*  prevent the file from being queued again */

typedef struct work_detail_struct {
  struct Node            wd_masterNode;
  struct Node            wd_specificNode;  /* Why this exists, I really don't remember */
  struct List            wd_unsentWork;    /* I'm going to leave it there just in case */
  struct List            wd_sentWork;      /* I ever do remember what it was for :-)  */
  struct SignalSemaphore wd_lock;
  site                   wd_toWhom;
  int                    wd_slowusecount;
  WORD                   wd_flags;
  short                  wd_maxPri;  
#define wd_minPri wd_maxPri     /* renamed. Will go away soon. */
#define wd_minCost wd_maxPri
  short                  wd_dialcount;     /* available for the scheduler */
  void                  *wd_TagList;       /* A tag list of additional things will be      */
                                           /* will be put here when Tag lists are grokked. */
} work_detail;

#define MASKBITS(bit)  (1<<(bit))

/* Bits for wd_flags */
#define WDB_FLOW  0
#define WDB_FLO   1
#define WDB_HLO   2
#define WDB_CLO   3
#define WDB_DLO   4
#define WDB_REQ   5

#define WD_OUTBOUND(d,type) ((d)->wd_flags|=MASKBITS(type))
#define WD_NOOUT(d,type)    ((d)->wd_flags&=~(MASKBITS(type)))
#define WD_OUTP(d,type)     ((d)->wd_flags&MASKBITS(type))
#define WD_ANYOUTBOUND(d)   ((d)->wd_flags& \
      (MASKBITS(WDB_FLOW) | MASKBITS(WDB_FLO) | MASKBITS(WDB_HLO) | \
       MASKBITS(WDB_CLO)  | MASKBITS(WDB_DLO)))

/* Indicates that the work detail has been modified. */
#define WDB_DIRTY  15
#define WDF_DIRTY (1<<WDB_DIRTY)

#define ISDIRTY(d) ((d)->wd_flags&WDF_DIRTY)
#define WD_DIRTY(d)   ((d)->wd_flags|=WDF_DIRTY)
#define WD_CLEAN(d)   ((d)->wd_flags&=(~WDF_DIRTY))

/* Indicates that the minCost is not the minimum of the sent
 * files -- it has been set by some other means.
 */
#define WDB_PRIORITY 14
#define WDF_PRIORITY MASKBITS(WDB_PRIORITY)
#define WD_PRILOCK(d)  ((d)->wd_flags&WDF_PRIORITY)
#define WD_LOCKPRI(d)  ((d)->wd_flags|=WDF_PRIORITY)
#define WD_UNLOCKPRI(d) ((d)->wd_flags&=(~WDF_PRIORITY))

#ifndef FLO_LIBRARY
#include <exec/libraries.h>
extern struct Library *FlowBase;
#define FloLibrary FlowBase
#endif

#define FLONAME "flow.library"
#define FLOVERSION 4
#define _WORK_DETAIL_
#endif

