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

perfsvr.cc

Go to the documentation of this file.
00001 /* Program Name to print at startup. */
00002 static char program_id[] = "perfsvr version 1.7 compiled on " __DATE__;
00003 
00004 #include "rcs_defs.hh"
00005 
00006 #ifdef EXTERN_C_STD_HEADERS
00007 extern "C" {
00008 #endif
00009    
00010 #include <stdio.h>              /* printf() */
00011 #include <stdlib.h>             /* exit() */
00012 #include <string.h>             /* strcmp() */
00013 
00014 #ifdef EXTERN_C_STD_HEADERS
00015 }
00016 #endif
00017 
00018 #include "cms_cfg.hh"           /* CMS_CONFIG_LINELEN */
00019 #include "nml.hh"               /* NML, NMLTYPE */
00020 #include "nml_srv.hh"           /* run_nml_servers() */
00021 #include "nmlmsg.hh"            /* NMLmsg */
00022 #include "cms.hh"               /* CMS  */
00023 #include "rcs_prnt.hh"          /* rcs_print_error() */
00024 #include "timer.hh"             /* etime() */
00025 #include "perftype.hh"          /* perf_types_format() */
00026 
00027 #ifdef VXWORKS
00028 #include "vxWorks.h"
00029 #include "taskLib.h"
00030 #endif
00031 
00032 #define MAX_NML_CHANNELS 100
00033 char *default_perfsvr_config_file="test.nml";
00034 char *default_perfsvr_host_name="localhost";
00035 
00036 
00037 
00038 #ifdef VXWORKS
00039 extern "C" int killperfsvr();
00040 int perfsvr_tid =0;
00041 
00042 
00043 int killperfsvr()
00044 {
00045   if(perfsvr_tid > 0)
00046     {
00047       kill(perfsvr_tid,2);
00048     }
00049 }
00050 #endif
00051 
00052 
00053 extern "C" int run_perfsvr(char *config_file, char *host_name);
00054 
00055 #ifdef VXWORKS
00056 extern "C" void perfsvr(char *config_file, char *host_name, int print_everything);
00057 
00058 void perfsvr(char *config_file, char *host_name, int print_everything)
00059 #else
00060 int main(int argc, char **argv)
00061 #endif
00062 {
00063 
00064 
00065   //set_rcs_print_destination(RCS_PRINT_TO_STDOUT);
00066   //set_rcs_print_flag(PRINT_EVERYTHING);
00067 
00068   /* Print File name, version, and compile date. */
00069   rcs_puts(program_id);
00070   rcs_errors_printed = 0;
00071   if(max_rcs_errors_to_print < 40)
00072     {
00073       max_rcs_errors_to_print = 40;
00074     }
00075 
00076 
00077 #ifndef VXWORKS
00078   char config_file[80];
00079   char host_name[80];
00080   printf("PERFSVR:\n");
00081   if(argc > 2)
00082   {
00083     /* Get host_name and config_file from command line */
00084     strcpy(config_file, argv[1]);
00085     strcpy(host_name, argv[2]);
00086    }
00087   else
00088   {
00089     /* Prompt user for config_file and host name */
00090     printf("Configuration File? [%s]", default_perfsvr_config_file);
00091     fgets(config_file,80,stdin);
00092     if(config_file[0] == 0 || config_file[0] == '\r' || config_file[0] == '\n')
00093       {
00094         strncpy(config_file, default_perfsvr_config_file, 80);
00095       }
00096 
00097     printf("Host Name? [%s]", default_perfsvr_host_name);
00098     fgets(host_name,80,stdin);
00099      if(host_name[0] == 0 || host_name[0] == '\r' || host_name[0] == '\n')
00100       {
00101         strncpy(host_name, default_perfsvr_host_name, 80);
00102       }
00103 }
00104 
00105 
00106   printf("print everything ? (y/n) ");
00107   char print_everything[16];
00108   fgets(print_everything, 16, stdin);
00109   if(print_everything[0] == 'y' || print_everything[0] == 'Y')
00110   {
00111     set_rcs_print_flag(PRINT_EVERYTHING);
00112   }
00113   run_perfsvr(config_file,host_name);
00114 #else
00115 
00116   if(config_file == NULL)
00117     {
00118       config_file = default_perfsvr_config_file;
00119     }
00120   if(host_name == NULL)
00121     {
00122       host_name = default_perfsvr_host_name;
00123     }
00124 
00125   if(print_everything == 1)
00126    {
00127     set_rcs_print_flag(PRINT_EVERYTHING);
00128   }
00129   perfsvr_tid = taskSpawn("tperfsvr",100,VX_FP_TASK,0x4000, (FUNCPTR) run_perfsvr,
00130             config_file, host_name,0,0,0,
00131             0,0,0,0,0);
00132 #endif
00133 }
00134 
00135 int run_perfsvr(char *config_file, char *host_name)
00136 {
00137   FILE *fp;
00138   char line[CMS_CONFIG_LINELEN];
00139   int line_len, line_number = 0;
00140   char buffer_name[CMS_CONFIG_LINELEN];
00141   char buffer_host[CMS_CONFIG_LINELEN];
00142   NML *nml_channel[MAX_NML_CHANNELS];
00143   int num_nml_channels;
00144 
00145   /* Open the configuration file. */
00146   if ((fp = fopen(config_file, "r")) == NULL)
00147   {
00148     rcs_print_error("nmlperf: Can't open '%s'\n", config_file);
00149     exit(-1);
00150   }
00151 
00152   /* Read the configuration file line by line to find buffers. */
00153   num_nml_channels = 0;
00154   while (!feof(fp) && num_nml_channels < MAX_NML_CHANNELS)
00155   {
00156     if ((fgets(line, CMS_CONFIG_LINELEN, fp)) == NULL)
00157     {
00158       break;
00159     }
00160 
00161     line_number++;
00162     line_len = strlen(line);
00163     if(line_len > CMS_CONFIG_LINELEN)
00164     {
00165       rcs_print_error("cms_cfg: Line length of line number %d in %s exceeds max length of %d", line_number, config_file, CMS_CONFIG_LINELEN);
00166     }
00167 
00168     if(line_len > 1)
00169     {
00170       if(line[line_len-2] == '\\' )
00171       {
00172         if ((fgets(line+line_len-2, CMS_CONFIG_LINELEN-line_len, fp)) == NULL)
00173         {
00174           break;
00175         }
00176         line_number++;
00177       }
00178     }
00179 
00180     if(line[0] != 'B')
00181     {
00182       continue;
00183     }
00184 
00185     sscanf(line+1, "%s %*s %s", buffer_name, buffer_host);
00186 
00187     /* Try to connect locally if the buffer host matches this one. */
00188 
00189     if(!strcmp(buffer_host, host_name))
00190     {
00191       printf("\nAttempting to connect to %s locally . . .\n",buffer_name);
00192       nml_channel[num_nml_channels] = new NML(perf_types_format,buffer_name,"perfsvr", config_file);
00193       num_nml_channels++;
00194     }
00195   }
00196 
00197   if(NULL != fp)
00198     {
00199       fclose(fp);
00200       fp = NULL;
00201     }
00202 
00203   printf("Press Control-C to stop server(s).\n");
00204   run_nml_servers();
00205   return 0;
00206 }

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