Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

main.cc

Go to the documentation of this file.
00001 // New File - Main.CPP
00002 //
00003 
00004 
00005 
00006 // Includes
00007 //
00008 
00009 #include "rcs.hh"               //WPS 14-Nov-1996
00010 #include "demon.h"
00011 #include "ch1.h"
00012 #include "ch2.h"
00013 
00014 #include <signal.h>             // signal(), SIGINT -- WPS 12-Dec-1996
00015 #include <stdlib.h>             // exit()
00016 #include <string.h>             // strcmp()
00017 #if defined(MSDOS) && !defined(_Windows)
00018 #include <conio.h>              // kbhit()
00019 #endif
00020 
00021 // Definitions and Macros
00022 //
00023 // Public Global Variables
00024 //
00025 #ifndef NO_TIMER
00026 static RCS_TIMER *timer = 0;
00027 #endif
00028 
00029 int want_to_quit = 0;
00030 
00031 void
00032 quit (int sig)
00033 {
00034   want_to_quit = 1;
00035 }
00036 
00037 /*QQ*********************************************************************
00038 RTNS:  None.
00039 PRPSE: This is the main routine.  Handles the multitasking, initialization
00040                  of the system, and system restoration upon completion.
00041 ATHR:  Nat Frampton
00042 CRTD:  05/03/96
00043 MDFD:  None.
00044 NOTES: None.
00045 PRBLM: None.
00046 OTHER: None.
00047 ************************************************************************/
00048 void
00049 main (int argc, char **argv)
00050 {
00051   set_rcs_print_destination (RCS_PRINT_TO_STDOUT);
00052 
00053   // Create Each Module
00054   //
00055   CH1_MODULE *ch1 = new CH1_MODULE ();
00056   CH2_MODULE *ch2 = new CH2_MODULE ();
00057 
00058 
00059   // Start the timer
00060 #ifndef NO_TIMER
00061   timer = new RCS_TIMER (1.0);
00062   if (NULL == timer)
00063     {
00064       rcs_print_error ("Can't create timer.\n");
00065       exit (-1);
00066     }
00067 #endif
00068 
00069   // set the SIGINT handler
00070   rcs_print ("Set up SIGINT handler.\n");
00071   signal (SIGINT, quit);
00072 
00073   rcs_print ("Running Modules.\n");
00074   double start_time = etime ();
00075   int cycles = 0;
00076 
00077 
00078   while (!want_to_quit)
00079     {
00080       ch1->controller ();
00081       ch2->controller ();
00082 #ifndef NO_TIMER
00083       // Wait for the timer;
00084       timer->wait ();
00085 #endif
00086       cycles++;
00087 #if defined(MSDOS) && !defined(_Windows)
00088       if (_kbhit ())
00089         {
00090           want_to_quit = 1;
00091           break;
00092         }
00093 #endif
00094 
00095 
00096     }
00097   double finish_time = etime ();
00098   rcs_print ("Exiting Loop.\n");
00099 
00100   if (NULL != ch1)
00101     {
00102       rcs_print ("Deleting ch1.\n");
00103       delete ch1;
00104       ch1 = NULL;
00105     }
00106 
00107   if (NULL != ch2)
00108     {
00109       rcs_print ("Deleting ch2.\n");
00110       delete ch2;
00111       ch2 = NULL;
00112     }
00113 
00114   rcs_print ("Totals: cycles = %d, time = %f\n", cycles,
00115              finish_time - start_time);
00116   rcs_print ("Average Cycle Time = %f\n",
00117              (finish_time - start_time) / cycles);
00118 
00119 
00120 #ifndef NO_TIMER
00121   rcs_print ("Deleting Timer.\n");
00122   delete timer;
00123 #endif
00124 }

Generated on Sun Dec 2 15:56:50 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001