IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 12, 2005, 9:34:34 AM (21 years ago)
Author:
eugene
Message:

pcontrol dev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/JobOps.c

    r3189 r3203  
    11# include "pcontrol.h"
    22
    3 Queue *JobPool_Pending;
    4 Queue *JobPool_Busy;
    5 Queue *JobPool_Exit;
    6 Queue *JobPool_Crash;
     3Stack *JobPool_Pending;
     4Stack *JobPool_Busy;
     5Stack *JobPool_Exit;
     6Stack *JobPool_Crash;
    77
    8 Queue *GetJobQueue (int QueueID) {
    9   switch (QueueID) {
     8void InitJobStacks () {
     9  JobPool_Pending = InitStack ();
     10  JobPool_Busy = InitStack ();
     11  JobPool_Exit = InitStack ();
     12  JobPool_Crash = InitStack ();
     13}
     14
     15Stack *GetJobStack (int StackID) {
     16  switch (StackID) {
    1017    case PCONTROL_JOB_PENDING:
    1118      return (JobPool_Pending);
     
    1421    case PCONTROL_JOB_EXIT:
    1522      return (JobPool_Exit);
    16     case PCONTROL_JOB_Crash:
     23    case PCONTROL_JOB_CRASH:
    1724      return (JobPool_Crash);
    1825    default:
    19       fprintf (stderr, "error: unknown job queue\n");
     26      fprintf (stderr, "error: unknown job stack\n");
    2027      return (NULL);
    2128  }
     
    2330}
    2431
    25 int PutJob (Job *job, int QueueID, int where) {
     32int PutJob (Job *job, int StackID, int where) {
    2633
    2734  int status;
    28   Queue *queue;
     35  Stack *stack;
    2936
    30   queue = GetJobQueue (QueueID);
    31   if (queue == NULL) return (FALSE);
     37  stack = GetJobStack (StackID);
     38  if (stack == NULL) return (FALSE);
    3239
    33   job[0].status = QueueID;
    34   status = PutObject (queue, where, job);
     40  /* be default, these are both the same - to override, set state after PutJob */
     41  job[0].state = StackID;
     42  job[0].stack = StackID;
     43  status = PutStack (stack, where, job);
    3544  return (status);
    3645}
    3746 
    38 Job *GetJob (int QueueID, int where) {
     47Job *GetJob (int StackID, int where) {
    3948
    4049  Job *job;
    41   Queue *queue;
     50  Stack *stack;
    4251
    43   queue = GetJobQueue (QueueID);
    44   if (queue == NULL) return (NULL);
     52  stack = GetJobStack (StackID);
     53  if (stack == NULL) return (NULL);
    4554
    46   job = GetObject (queue, where);
     55  job = GetStack (stack, where);
    4756  return (job);
    4857}
    4958 
    50 int FindJob (IDtype JobID, int QueueID) {
     59int FindJob (IDtype JobID, int StackID) {
    5160
     61  int i;
    5262  Job *job;
    53   Queue *queue;
     63  Stack *stack;
    5464
    55   queue = GetJobQueue (QueueID);
    56   if (queue == NULL) return (-2);
     65  stack = GetJobStack (StackID);
     66  if (stack == NULL) return (-2);
    5767
    58   for (i = 0; i < queue[0].Nobject; i++) {
    59     job = (Job *) queue[0].object;
     68  for (i = 0; i < stack[0].Nobject; i++) {
     69    job = (Job *) stack[0].object;
    6070    if (job[0].JobID == JobID) {
    6171      return (i);
     
    6575}
    6676
    67 AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) {
     77IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) {
    6878
    6979  Job *job;
     
    7686  job[0].mode     = mode;
    7787  job[0].host     = NULL;
    78   job[0].ID       = NextJobID();
     88  job[0].JobID    = NextJobID();
     89  job[0].Reset    = FALSE;
    7990
    80   InitIOBuffer (&job[0].stdin,  0x1000);
     91  /* do this step on start? */
    8192  InitIOBuffer (&job[0].stdout, 0x1000);
    8293  InitIOBuffer (&job[0].stderr, 0x1000);
    8394
    84   PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM);
     95  PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
     96  return (job[0].JobID);
    8597}
    8698
    87 DelJob (Job *job) {
     99void DelJob (Job *job) {
     100
     101  int i;
    88102
    89103  FREE (job[0].hostname);
     
    93107  FREE (job[0].argv);
    94108
    95   FreeIOBuffer (&job[0].stdin);
    96109  FreeIOBuffer (&job[0].stdout);
    97110  FreeIOBuffer (&job[0].stderr);
     
    100113}
    101114
    102 KillJob (Job *job) {
     115# if (0)
     116void KillJob (Job *job) {
    103117
     118  int status;
    104119  char line[64];
     120  Host *host;
    105121
    106122  sprintf (line, "reset\n");
     
    110126  if ((status == -1) && (errno == EPIPE)) {
    111127    fprintf (stderr, "host %s is down\n", host[0].hostname);
    112     PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);
    113     PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM);
     128    PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
     129    PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
    114130    return (FALSE);
    115131  }
    116132  /* check for a response */
    117133
     134  /** this needs to be cleaned up to handle the slow response case **/
    118135}
     136# endif
     137
     138Host *UnlinkJobAndHost (Job *job) {
     139
     140  int N;
     141  Host *host;
     142
     143  host = job[0].host;
     144
     145  /* unlink host & job */
     146  job[0].host = NULL;
     147  host[0].job = NULL;
     148 
     149  /*** need to pop host off of correct stack XXX ***/
     150  N = FindHost (host[0].HostID, host[0].stack);
     151  if (N < 0) {
     152    fprintf (stderr, "programming error: host is not found in current stack\n");
     153    exit (2);
     154  }
     155  host = GetHost (host[0].stack, N);
     156  return (host);
     157}
     158
     159void LinkJobAndHost (Job *job, Host *host) {
     160  job[0].host = host;
     161  host[0].job = job;
     162}
Note: See TracChangeset for help on using the changeset viewer.