/*==========================================================================*\
 |  This file is part of setiherder (http://www.sackheads.org/setiherder/)  |
 |  which was written by Brian L. Naylor <brian+seti@sackheads.org> and is  |
 |  under the GNU General Public License.  You should have recieved a copy  |
 |  of the GPL with this source code.  If not, we'd like to know about it.  |
\*--------------------------------------------------------------------------*/

#ifndef SH_TYPES
#define SH_TYPES

#include <sys/types.h>
#include <gtk/gtk.h>

typedef unsigned int sh_rc;

typedef struct sh_expanded_widgets {
  GtkWidget *toplevel;
  GtkWidget *hostname;
  GtkWidget *task;
  GtkWidget *version;
  GtkWidget *platform;
  GtkWidget *coords;
  GtkWidget *recdate;
  GtkWidget *source;
  GtkWidget *basefreq;
  GtkWidget *progress;
  GtkWidget *dop_shift_rt;
  GtkWidget *last_shift;
  GtkWidget *fft_len;
} sh_expanded_widgets_t;

typedef struct sh_client {
  int   index;         /* index of node (convenience)                        */
  char *hostname;      /* hostname of seti client                            */
  char *seticmd;       /* full command used to spawn seti software on client */
  char *account;       /* email address used for stats                       */
  char *version;       /* seti@home software version                         */
  char *platform;      /* client platform type; listed by seti@home program  */
  char *coords;        /* cky coordinates a unit of data was recorded from   */
  char *recdate;       /* date a work unit was recorded                      */
  char *source;        /* Earth location where signal was recorded           */
  char *basefreq;      /* Base frequency of recording                        */
  int   autores;       /* auto-restart client if it dies?                    */
  int   delay;         /* how long to wait before restarting?                */
  int   stop_next;     /* kill client after next work unit is complete?      */
  int   died;          /* time() at which client died                        */
  int   user_stopped;  /* did the user manually stop the process?            */
  int   state;         /* current client task                                */
  float completed;     /* how much of current client task is complete?       */
  float dop_shift_rt;  /* doppler shift rate                                 */
  float last_shift;    /* amount of last data shift                          */
  int   fft_len;       /* FFT length                                         */
  int   units_done;    /* units completed by this session                    */
  float cpu_time;      /* how much cpu time used by this session             */
  pid_t pid;           /* process ID of child (if it exists)                 */
  int   socket;        /* for use in networking mode                         */
  FILE *ttyfp, *ptyfp; /* stream ptrs for pseudo-terminal of child           */
  gint  iotag;         /* place to save gdk_input tag for removal            */
  sh_expanded_widgets_t *expanded; /* pointer to expanded window bits        */
  char *task;          /* exactly what it's doing now (for details view)     */
  int   spawn_method;  /* network or local command?                          */
  int   detach;        /* leave client running after setiherder exit?        */
  int   port;          /* port to use with setid                             */
  char *passwd;        /* password for connecting to setid daemon            */
} sh_client_t;

#define CHUNKSIZE              360  /* size of seti@home work units          */

#define SH_SUCCESS              0
#define SH_ERR_GENERIC          1
#define SH_ERR_MEM              2
#define SH_ERR_PERM             3
#define SH_ERR_CHILD            4
#define SH_ERR_NOCMD           20
#define SH_ERR_RC              30
#define SH_ERR_NOT_EXPANDED    50
#define SH_ERR_NOTWERK        100

#define SH_DEFAULT_HOSTNAME     "hostname"
#define SH_DEFAULT_SETICMD      "ssh -t hostname setistart /usr/local/seti"
#define SH_DEFAULT_ACCOUNT      "seti@sackheads.org"
#define SH_DEFAULT_AUTORES      1
#define SH_DEFAULT_DELAY        600
#define SH_DEFAULT_STATE        SH_STATE_STOPPED
#define SH_DEFAULT_COMPLETED    0.0
#define SH_DEFAULT_DOP_SHIFT_RT 0.0
#define SH_DEFAULT_LAST_SHIFT   0.0
#define SH_DEFAULT_FFT_LEN      0
#define SH_DEFAULT_UNITS_DONE   0
#define SH_DEFAULT_CPU_TIME     0.0
#define SH_DEFAULT_PID          0
#define SH_DEFAULT_DEAD_PID    -1
#define SH_DEFAULT_INDEX       -1

#define SH_MAX_CLIENTS           256   /* arbitrary */
#define SH_MAX_BUF              1024
#define SH_MAX_LINE              160

#define SH_SPAWN_CMD            1
#define SH_SPAWN_NET            2

#define SH_STATE_STOPPED        0  /* not started yet, or stopped by user */
#define SH_STATE_WORKING        1  /* computation in progress             */
#define SH_STATE_TRANSFERRING   2  /* sending or receiving data           */
#define SH_STATE_CRASHED        3  /* died unexpectedly                   */
#define SH_STATE_HUNG           4  /* child process isn't responding      */
#define SH_STATE_WAITING        5  /* seti@home process initiated wait    */

extern int total_complete;   /* total units completed by account                    */
extern float total_cpu;      /* total cpu time used by account                      */
extern sh_client_t sh_client_list[SH_MAX_CLIENTS];
extern char *sh_state_list[];

#endif
