/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : _schedulerTest.cc                                             */
/* Author   : Rob McEwen and Hans Thomas                                    */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 08/017/2000                                                   */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*-----------------------------------------------------------------------*
  $Id: _schedulerTest.cc,v 1.2 2000/09/13 21:09:40 rob Exp $
 *-----------------------------------------------------------------------*/

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <signal.h>
#include <process.h>
#include <time.h>

#include "LblIF.h"
#include "TimeIF.h"
#include "LblServer.h"
#include "Syslog.h"
#include "System.h"
#include "SerialParameters.h"

int main( int argc, char **argv ) 
{
  LblIF *lbl;
  TimeIF::TimeSpec sampleTime;
  double depth, temp, pressure;
  pid_t lblServer;
  Boolean debug = True;

  dprintf(" Start schedulerTest.\n");

  try { 
    SerialParameters serialParams(&argc, argv);
    char argString[100];
    dprintf(" schedulerTest: Serial Port String = %s\n", serialParams.string());
    sprintf(argString, "-serial %s", serialParams.string());
    if ((lblServer = System::spawn("lblServer", argString)) == -1)
      {
	Syslog::write("System::spawn(lblServer) failed\n");
      }
  }
  catch ( ... )
    {
      Syslog::write("schedulerTest -- "
		    "caught exception on spawning of Lbl Server\n");
    }

  dprintf(" schedulerTest: SerialParams.\n");
  //
  // Start worksite server (needed by ps8000 to read the .cfg files).
  //
  pid_t workSiteServer;

  if ((workSiteServer = System::spawn("workSite",  "")) == -1) 
    throw Exception("System::spawn(workSite Server) failed");

  dprintf(" schedulerTest: Started WorkSite Server.\n");


  try 
  {
       lbl = new LblIF( "Lbl", 1000 );
  }
  catch (...)
  {
       Syslog::write("schedulerTest -- Caught exception on IF creation\n");
       exit( -1 );
  }

  dprintf(" schedulerTest: Opened lblIF.\n");

  LblIF ::RTimes     times[1];
  double decimalTime;
  TimeIF::TimeSpec   ping_time[1];
  char buf[256];

  pid_t schedulerServer;

  if ((schedulerServer = System::spawn("scheduler",  "True")) == -1) 
    throw Exception("System::spawn(scheduler Server) failed");

  dprintf(" schedulerTest: Started WorkSite Server.\n");


  printf(" Begin pinging...\n");


  while (1) 
  {
    sleep(1);
  }

  fprintf(stderr, " Exiting schedulerTest\n");
  delete lbl;
  kill(0, SIGTERM);
  kill(workSiteServer, SIGTERM);
  kill(lblServer, SIGTERM);
  return 0;
}
