Index: trunk/Ohana/src/opihi/pantasks/InputQueue.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/InputQueue.c	(revision 7952)
+++ trunk/Ohana/src/opihi/pantasks/InputQueue.c	(revision 7952)
@@ -0,0 +1,80 @@
+# include "pantasks.h"
+# define DEBUG 1
+
+static int Ninputs = 0;
+static int NINPUTS = 0;
+static char **inputs;
+
+void InitInputs () {
+
+  Ninputs = 0;
+  NINPUTS = 10;
+  ALLOCATE (inputs, char *, NINPUTS);
+}
+
+/* add this input to the inputs table */
+void AddNewInput (char *input) {
+
+  SerialThreadLock ();
+  if (DEBUG) gprint (GP_LOG, "adding a new input (%s)\n", input);
+  inputs[Ninputs] = input;
+  Ninputs ++;
+  if (Ninputs >= NINPUTS - 1) {
+    NINPUTS += 10;
+    REALLOCATE (inputs, char *, NINPUTS);
+  }
+  if (DEBUG) gprint (GP_LOG, "done new input (%s)\n", input);
+  SerialThreadUnlock ();
+}
+
+/* remove this input from the inputs table */
+int DeleteInput (char *input) {
+
+  int i, j;
+
+  if (DEBUG) gprint (GP_LOG, "deleting an input (%s)\n", input);
+  for (i = 0; i < Ninputs; i++) {
+    if (inputs[i] == input) {
+      free (inputs[i]);
+      for (j = i; j < Ninputs - 1; j++) {
+	inputs[j] = inputs[j+1];
+      }
+      Ninputs --;
+      if ((Ninputs > 10) && (Ninputs / 2 < NINPUTS)) {
+	NINPUTS = Ninputs + 10;
+	REALLOCATE (inputs, char *, NINPUTS);
+      }
+      if (DEBUG) gprint (GP_LOG, "deleted an input\n");
+      return TRUE;
+    }
+  }
+  // did not find the input
+  return FALSE;
+}
+
+/* if any inputs are pending, run one */
+void CheckInputs () {
+
+  int Nbytes, status;
+  char *input, *line, *outline, tmp;
+
+  if (Ninputs < 1) return;
+
+  input = inputs[0];
+  if (DEBUG) gprint (GP_LOG, "got an input (%s)\n", input);
+  
+  Nbytes = snprintf (&tmp, 0, "input %s", input);
+  fprintf (stderr, "string len %d\n", Nbytes);
+
+  ALLOCATE (line, char, Nbytes + 1);
+  fprintf (stderr, "allocated line\n");
+
+  snprintf (line, Nbytes + 1, "input %s", input);
+  
+  fprintf (stderr, "running command %s\n", line);
+
+  status = command (line, &outline, TRUE);
+  free (outline);
+  
+  DeleteInput (input);
+}
Index: trunk/Ohana/src/opihi/pantasks/Makefile
===================================================================
--- trunk/Ohana/src/opihi/pantasks/Makefile	(revision 7940)
+++ trunk/Ohana/src/opihi/pantasks/Makefile	(revision 7952)
@@ -74,4 +74,8 @@
 server = \
 $(SDIR)/pantasks_server.$(ARCH).o \
+$(SDIR)/server_threads.$(ARCH).o \
+$(SDIR)/server_run.$(ARCH).o \
+$(SDIR)/server_load.$(ARCH).o \
+$(SDIR)/InputQueue.$(ARCH).o \
 $(SDIR)/ListenClients.$(ARCH).o \
 $(SDIR)/CheckPassword.$(ARCH).o
Index: trunk/Ohana/src/opihi/pantasks/pantasks_server.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 7940)
+++ trunk/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 7952)
@@ -16,5 +16,9 @@
 int main (int argc, char **argv) {
   
-  pthread_t thread;
+  pthread_t clientsThread;
+  pthread_t tasksThread;
+  pthread_t jobsThread;
+  pthread_t inputsThread;
+  pthread_t controllerThread;
   int InitSocket, BindSocket;
   SockAddress Address;
@@ -32,4 +36,5 @@
   
   gprintInit ();  // each thread needs to init the printing system
+  InitInputs ();
 
   signal (SIGPIPE, gotsignal);
@@ -38,14 +43,12 @@
   signal (SIGINT, SIG_DFL);
 
-  // startup (&argc, argv);
-
-  /* set up mechanisms for sharing data between the threads */
-  // init_data_handling ();
+  startup (&argc, argv);
 
   /* start up the background threads here */
-  pthread_create (&thread, NULL, &ListenClients, NULL);
-
-  // pthread_create (&thread, NULL, &RunScheduler, NULL);
-  // pthread_create (&thread, NULL, &RunController, NULL);
+  pthread_create (&clientsThread,    NULL, &ListenClients,    	   NULL);
+  pthread_create (&tasksThread,      NULL, &CheckTasksThread, 	   NULL);
+  pthread_create (&jobsThread,       NULL, &CheckJobsThread,  	   NULL);
+  pthread_create (&controllerThread, NULL, &CheckControllerThread, NULL);
+  pthread_create (&inputsThread,     NULL, &CheckInputsThread,     NULL);
 
   /* in this loop, we listen for incoming connections, validate, and
Index: trunk/Ohana/src/opihi/pantasks/server.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/server.c	(revision 7940)
+++ trunk/Ohana/src/opihi/pantasks/server.c	(revision 7952)
@@ -4,4 +4,7 @@
 int quit            PROTO((int, char **));
 int input      	    PROTO((int, char **));
+int server_load	    PROTO((int, char **));
+int server_run	    PROTO((int, char **));
+int server_stop	    PROTO((int, char **));
 int cd              PROTO((int, char **));
 int pwd        	    PROTO((int, char **));
@@ -14,4 +17,7 @@
   {"quit",   quit,   "shutdown server"},
   {"input",  input,  "load input file on server"},
+  {"load",   server_load, "load input file on server"},
+  {"run",    server_run,  "run scheduler"},
+  {"stop",   server_stop, "stop scheduler"},
   {"cd",     cd,     "set local directory"},
   {"pwd",    pwd,    "check local directory"},
Index: trunk/Ohana/src/opihi/pantasks/server_load.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/server_load.c	(revision 7952)
+++ trunk/Ohana/src/opihi/pantasks/server_load.c	(revision 7952)
@@ -0,0 +1,18 @@
+# include "pantasks.h"
+
+int server_load (int argc, char **argv) {
+
+  char *input;
+
+  if (argc != 2) {
+    gprint (GP_ERR, "USAGE: server load (file)\n");
+    return (FALSE);
+  }
+
+  // the allocated input string is eventually freed 
+  // by the InputQueue system
+  input = strcreate (argv[1]);
+  AddNewInput (input);
+
+  return (TRUE);
+}
Index: trunk/Ohana/src/opihi/pantasks/server_run.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/server_run.c	(revision 7952)
+++ trunk/Ohana/src/opihi/pantasks/server_run.c	(revision 7952)
@@ -0,0 +1,23 @@
+# include "pantasks.h"
+
+int server_run (int argc, char **argv) {
+
+  if (argc != 1) {
+    gprint (GP_ERR, "USAGE: server run\n");
+    return (FALSE);
+  }
+
+  CheckTasksSetState (TRUE);
+  return (TRUE);
+}
+
+int server_stop (int argc, char **argv) {
+
+  if (argc != 1) {
+    gprint (GP_ERR, "USAGE: server stop\n");
+    return (FALSE);
+  }
+
+  CheckTasksSetState (FALSE);
+  return (TRUE);
+}
Index: trunk/Ohana/src/opihi/pantasks/server_threads.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/server_threads.c	(revision 7952)
+++ trunk/Ohana/src/opihi/pantasks/server_threads.c	(revision 7952)
@@ -0,0 +1,138 @@
+# include "pantasks.h"
+
+/* this mutex is used by the serialized threads */
+
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void SerialThreadLock () {
+    pthread_mutex_lock (&mutex);
+}
+
+void SerialThreadUnlock () {
+    pthread_mutex_unlock (&mutex);
+}
+
+/** things related to CheckTasks **/
+
+static int CheckTasksRun = FALSE;
+
+void CheckTasksSetState (int state) {
+  CheckTasksRun = state;
+}
+int CheckTasksGetState () {
+  return (CheckTasksRun);
+}
+
+void CheckTasksThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckTasksRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckTasks ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "T");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckJobs **/
+
+static int CheckJobsRun = FALSE;
+
+void CheckJobsSetState (int state) {
+  CheckJobsRun = state;
+}
+int CheckJobsGetState () {
+  return (CheckJobsRun);
+}
+
+void CheckJobsThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckJobsRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckJobs ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "J");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckController **/
+
+static int CheckControllerRun = FALSE;
+
+void CheckControllerSetState (int state) {
+  CheckControllerRun = state;
+}
+int CheckControllerGetState () {
+  return (CheckControllerRun);
+}
+
+void CheckControllerThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckControllerRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckController ();
+    CheckControllerOutput ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "C");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckInputs **/
+
+static int CheckInputsRun = TRUE;
+
+void CheckInputsSetState (int state) {
+  CheckInputsRun = state;
+}
+int CheckInputsGetState () {
+  return (CheckInputsRun);
+}
+
+void CheckInputsThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckInputsRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckInputs ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "I");
+    usleep (250000);
+  }
+}
Index: trunk/Ohana/src/opihi/pantasks/status.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/status.c	(revision 7940)
+++ trunk/Ohana/src/opihi/pantasks/status.c	(revision 7952)
@@ -9,5 +9,15 @@
     gprint (GP_LOG, " Scheduler is running\n");
   }
-  if (CheckControllerStatus ()) {
+  if (CheckControllerStatus()) {
+    gprint (GP_LOG, " Controller is running\n");
+  } else {
+    gprint (GP_LOG, " Controller is stopped\n");
+  }
+  if (CheckTasksGetState()) {
+    gprint (GP_LOG, " Scheduler is running\n");
+  } else {
+    gprint (GP_LOG, " Scheduler is stopped\n");
+  }
+  if (CheckControllerGetState()) {
     gprint (GP_LOG, " Controller is running\n");
   } else {
