Index: trunk/Ohana/src/opihi/pantasks/controller.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/controller.c	(revision 4450)
+++ trunk/Ohana/src/opihi/pantasks/controller.c	(revision 4539)
@@ -1,48 +1,41 @@
 # include "scheduler.h"
+
+static Command controller_cmds[] = {
+  {"host",   controller_host,   "define host for controller"},
+  {"status", controller_status, "check controller status"},
+  {"check",  controller_check,  "check controller host/job"},
+};
 
 int controller (int argc, char **argv) {
 
   int status;
-  char command[1024];
-  IOBuffer buffer;
+  Function *func;
 
-  if (argc != 3) {
-    fprintf (stderr, "USAGE: controller host (hostname)\n");
+  if (argc < 2) {
+    fprintf (stderr, "USAGE: controller (command) ... \n");
     return (FALSE);
   }
 
-  if (strcmp (argv[1], "host")) {
+  func = FindControllerCommand (argv[1]);
+  if (func == NULL) {
     fprintf (stderr, "invalid controller command\n");
     return (FALSE);
   }
 
-  /* start controller connection (if needed) */
-  StartController ();
+  status = (*func)(argc - 1, argv + 1);
+  return (status);
+}
 
-  sprintf (command, "host %s", argv[2]);
-  InitIOBuffer (&buffer, 0x100);
-  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
-  FreeIOBuffer (&buffer);
+Function *FindControllerCommand (char *cmd) {
 
-  /* check on success of controller command */
-  switch (status) {
-    case CONTROLLER_DOWN:
-      fprintf (stderr, "controller is down\n");
-      return (FALSE);
+  int i, N;
 
-    case CONTROLLER_HUNG:
-      fprintf (stderr, "controller is not responding\n");
-      return (FALSE);
+  N = sizeof (controller_cmds) / sizeof (Command);
 
-    case CONTROLLER_GOOD:
-      fprintf (stderr, "controller command sent\n");  
-      return (TRUE);
-
-    default:
-      fprintf (stderr, "unknown status for controller command: programming error\n");  
-      exit (1);
+  for (i = 0; i < N; i++) {
+    if (!strcmp (controller_cmds[i].name, argv[1])) {
+      return (controller_cmds[i].func);
+    }
   }
-
-  fprintf (stderr, "programming error: should not reach here\n");  
-  exit (1);
+  return (NULL);
 }
