IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 5, 2005, 7:12:22 AM (21 years ago)
Author:
eugene
Message:

tested / bugfixed sched/pcontrol I/F

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r4451 r4452  
    55int status = FALSE;
    66int stdin_cntl, stdout_cntl, stderr_cntl;
    7 
    8 /* we read Nbytes from the host, then watch for the prompt */
    9 int GetJobOutput (char *cmd, int pid, IOBuffer *buffer, int Nbytes) {
    10  
    11   int i, status, Nstart;
    12   char *line;
    13 
    14   /* flush any earlier messages */
    15   ReadtoIOBuffer (buffer, stdout_cntl);
    16   FlushIOBuffer (buffer);
    17   Nstart = buffer[0].Nbuffer;
    18 
    19   /* send command to get appropriate channel */
    20   ALLOCATE (line, char, MAX (1, strlen(cmd) + 15));
    21   sprintf (line, "%s %d\n", cmd, pid);
    22   status = write (stdin_cntl, line, strlen(line));
    23   free (line);
    24 
    25   /* is pipe still open? */
    26   if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN);
    27 
    28   /* read at least Nbytes, then watch for CONTROLLER_PROMPT */
    29   line = NULL;
    30   status = -1;
    31   for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) {
    32     status = ReadtoIOBuffer (buffer, stdout_cntl);
    33     if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {
    34       line = memstr (buffer[0].buffer, CONTROLLER_PROMPT, buffer[0].Nbuffer);
    35     }
    36     if (status == -1) usleep (10000);
    37   }
    38   if (status ==  0) return (CONTROLLER_DOWN);
    39   if (status == -1) return (CONTROLLER_HUNG);
    40 
    41   fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 
    42   /* drop extra bytes from pcontrol (not pclient:job) */
    43   buffer[0].Nbuffer = Nstart + Nbytes;
    44   if (buffer[0].Nalloc > buffer[0].Nbuffer) {
    45     bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);
    46   }
    47   return (CONTROLLER_GOOD);
    48 }
    497
    508int CheckControllerJob (Job *job) {
     
    12381}
    12482
     83/* we read Nbytes from the host, then watch for the prompt */
     84int GetJobOutput (char *cmd, int pid, IOBuffer *buffer, int Nbytes) {
     85 
     86  int i, status, Nstart;
     87  char *line;
     88
     89  /* flush any earlier messages */
     90  ReadtoIOBuffer (buffer, stdout_cntl);
     91  FlushIOBuffer (buffer);
     92  Nstart = buffer[0].Nbuffer;
     93
     94  /* send command to get appropriate channel */
     95  ALLOCATE (line, char, MAX (1, strlen(cmd) + 15));
     96  sprintf (line, "%s %d\n", cmd, pid);
     97  status = write (stdin_cntl, line, strlen(line));
     98  free (line);
     99
     100  /* is pipe still open? */
     101  if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN);
     102
     103  /* read at least Nbytes, then watch for CONTROLLER_PROMPT */
     104  line = NULL;
     105  status = -1;
     106  for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     107    status = ReadtoIOBuffer (buffer, stdout_cntl);
     108    if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {
     109      line = memstr (buffer[0].buffer, CONTROLLER_PROMPT, buffer[0].Nbuffer);
     110    }
     111    if (status == -1) usleep (10000);
     112  }
     113  if (status ==  0) return (CONTROLLER_DOWN);
     114  if (status == -1) return (CONTROLLER_HUNG);
     115
     116  fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 
     117  /* drop extra bytes from pcontrol (not pclient:job) */
     118  buffer[0].Nbuffer = Nstart + Nbytes;
     119  if (buffer[0].Nalloc > buffer[0].Nbuffer) {
     120    bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);
     121  }
     122  return (CONTROLLER_GOOD);
     123}
     124
    125125/* submitting a job to the controller automatically starts controller */
    126126int SubmitControllerJob (Job *job) {
     
    165165  }
    166166
     167  fprintf (stderr, "sending command to controller: %s\n", cmd);
    167168  InitIOBuffer (&buffer, 0x100);
    168169  ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer);
    169170  free (cmd);
    170171
     172  fprintf (stderr, "response from controller: %s\n", buffer.buffer);
     173
    171174  /* extract the job PID from the controller response */
    172   p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer);
     175  p = memstr (buffer.buffer, "JobID", buffer.Nbuffer);
    173176  if (p == NULL) {
    174177    fprintf (stderr, "missing PID in pcontrol message : programming error\n");
     
    298301  FlushIOBuffer (buffer);
    299302
     303  fprintf (stderr, "send: %s\n", cmd);
     304
    300305  /* send command to client (adding on \n) */
    301   /* fprintf (stderr, "send: %s (%d)\n", command, buffer[0].Nbuffer); */
    302306  ALLOCATE (line, char, MAX (1, strlen(cmd)));
    303307  sprintf (line, "%s\n", cmd);
Note: See TracChangeset for help on using the changeset viewer.