IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4539


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

adding user-level controller commands

Location:
trunk/Ohana/src/opihi/pantasks
Files:
6 added
2 edited

Legend:

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

    r4450 r4539  
    11# include "scheduler.h"
     2
     3static Command controller_cmds[] = {
     4  {"host",   controller_host,   "define host for controller"},
     5  {"status", controller_status, "check controller status"},
     6  {"check",  controller_check,  "check controller host/job"},
     7};
    28
    39int controller (int argc, char **argv) {
    410
    511  int status;
    6   char command[1024];
    7   IOBuffer buffer;
     12  Function *func;
    813
    9   if (argc != 3) {
    10     fprintf (stderr, "USAGE: controller host (hostname)\n");
     14  if (argc < 2) {
     15    fprintf (stderr, "USAGE: controller (command) ... \n");
    1116    return (FALSE);
    1217  }
    1318
    14   if (strcmp (argv[1], "host")) {
     19  func = FindControllerCommand (argv[1]);
     20  if (func == NULL) {
    1521    fprintf (stderr, "invalid controller command\n");
    1622    return (FALSE);
    1723  }
    1824
    19   /* start controller connection (if needed) */
    20   StartController ();
     25  status = (*func)(argc - 1, argv + 1);
     26  return (status);
     27}
    2128
    22   sprintf (command, "host %s", argv[2]);
    23   InitIOBuffer (&buffer, 0x100);
    24   status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
    25   FreeIOBuffer (&buffer);
     29Function *FindControllerCommand (char *cmd) {
    2630
    27   /* check on success of controller command */
    28   switch (status) {
    29     case CONTROLLER_DOWN:
    30       fprintf (stderr, "controller is down\n");
    31       return (FALSE);
     31  int i, N;
    3232
    33     case CONTROLLER_HUNG:
    34       fprintf (stderr, "controller is not responding\n");
    35       return (FALSE);
     33  N = sizeof (controller_cmds) / sizeof (Command);
    3634
    37     case CONTROLLER_GOOD:
    38       fprintf (stderr, "controller command sent\n"); 
    39       return (TRUE);
    40 
    41     default:
    42       fprintf (stderr, "unknown status for controller command: programming error\n"); 
    43       exit (1);
     35  for (i = 0; i < N; i++) {
     36    if (!strcmp (controller_cmds[i].name, argv[1])) {
     37      return (controller_cmds[i].func);
     38    }
    4439  }
    45 
    46   fprintf (stderr, "programming error: should not reach here\n"); 
    47   exit (1);
     40  return (NULL);
    4841}
  • trunk/Ohana/src/opihi/pantasks/init.c

    r4450 r4539  
    2121  {"run",        run,          "run the scheduler"},
    2222  {"stop",       stop,         "stop the scheduler"},
     23
     24  {"kill",       kill_sh,      "kill job"},
     25  {"delete",     delete,       "delete job"},
     26  {"job",        job,          "add job"},
     27  {"host",       host,         "add / delete / modify host"},
     28  {"check",      check,        "get job or host status"},
     29  {"status",     status,       "get system status"},
     30  {"stdout",     stdout_pc,    "get stdout buffer for job"},
     31  {"stderr",     stderr_pc,    "get stderr buffer for job"},
    2332};
    2433
Note: See TracChangeset for help on using the changeset viewer.