# include "pantasks.h"

int controller_host (int argc, char **argv) {

  int status;
  char command[1024];
  IOBuffer buffer;

  if (argc != 3) {
    gprint (GP_ERR, "USAGE: controller host (command) (hostname)\n");
    return (FALSE);
  }

  /* start controller connection (if needed) */
  if (!StartController ()) {
    gprint (GP_ERR, "failure to start pcontrol\n");
    return (FALSE);
  }

  sprintf (command, "host %s %s", argv[1], argv[2]);
  InitIOBuffer (&buffer, 0x100);

  SerialThreadLock ();
  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
  SerialThreadUnlock ();

  if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);

  FreeIOBuffer (&buffer);
  return (TRUE);
}

/* should I keep an internal host table so I can reload the 
   hosts if the controller exits?

   alternatively, that could be a user-level choice
*/
