00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "marstartup.h"
00013 #include "qscan345settings.h"
00014
00015 #include <stdio.h>
00016 #include <string.h>
00017 #include <ctype.h>
00018 #include <time.h>
00019 #include <errno.h>
00020 #include <stdlib.h>
00021 #include <fcntl.h>
00022 #include <unistd.h>
00023
00024 #include "esd.h"
00025 #include "marglobals.h"
00026 #include "version.h"
00027 #define CONFIGGLOBAL
00028 #include "config.h"
00029
00030
00031
00032
00033 #ifdef __sgi
00034 #include <sys/stat.h>
00035
00036 #ifndef DEGRADING_PRIORITIES
00037 #include <limits.h>
00038 #include <sys/types.h>
00039 #include <sys/prctl.h>
00040 #include <sys/schedctl.h>
00041 #endif
00042
00043 #endif
00044
00045
00046
00047
00048 #ifdef __osf__
00049 #include <sys/types.h>
00050 #include <sys/stat.h>
00051 #endif
00052
00053
00054
00055
00056 #ifdef __linux__
00057 #include <sys/stat.h>
00058 #include <unistd.h>
00059 #include <sys/time.h>
00060 #include <sys/resource.h>
00061 #include <errno.h>
00062 #endif
00063
00064
00065
00066
00067 char martable_dir [128];
00068 char nbcode_file [128];
00069
00070
00071
00072
00073 extern int lines;
00074 extern int status_interval;
00075
00076
00077
00078
00079 extern int net_open(int);
00080
00081
00082
00083
00084 int marStartup();
00085
00086 extern "C" {
00087 extern CONFIG GetConfig(FILE*);
00088 extern void PutConfig(CONFIG);
00089 }
00090
00091 MarStartup::MarStartup(QObject *parent)
00092 : inherited(parent)
00093 {
00094 }
00095
00096
00097
00098
00099 int
00100 MarStartup::marStartup()
00101 {
00102 int i=0;
00103 int fdtest;
00104 time_t now;
00105 extern int input_priority;
00106 extern float input_scale;
00107 FILE *fp;
00108
00109 #ifdef __linux__
00110 if ( input_priority == -1 )
00111 input_priority = -20;
00112
00113 i=setpriority(PRIO_PROCESS, (int)getpid(), input_priority);
00114 if ( i == -1 )
00115 input_priority = -1;
00116 #elif __sgi
00117 if ( input_priority == -1 )
00118 input_priority = NDPHIMAX;
00119
00120 while ( (i = schedctl( NDPRI, 0, input_priority ) ) == -1 ) {
00121 input_priority++;
00122 if ( input_priority > NDPNORMMIN ) break;
00123 }
00124 if ( i == -1 )
00125 input_priority = -1;
00126 #endif
00127
00128 #ifndef __osf__
00129 if ( i < 0 ) {
00130 emit print_message(QString().sprintf("scan345: Cannot increase PRIORITY of process %d\n",getpid()));
00131 }
00132 #endif
00133
00134
00135
00136
00137
00138 QScan345Settings s;
00139
00140 strcpy( martable_dir, qPrintable(s.martabledir()));
00141 sprintf(scanner_no, "%03d", s.marscannernumber());
00142 #if ( __osf__ )
00143 strcpy( working_dir , (char *)getcwd( NULL, 256, 1 ) ) ;
00144 #else
00145 strcpy( working_dir , (char *)getcwd( NULL, 256 ) ) ;
00146 #endif
00147
00148 sprintf( config_file,"%s/config.%s", martable_dir, scanner_no );
00149
00150
00151 sprintf( nbcode_file,"%s/mar2300.%s", martable_dir, scanner_no);
00152 if( -1 == (fdtest = open( nbcode_file, 0 ))) {
00153 emit print_message(QString().sprintf("scan345: Cannot open %s as neighbour code file\n", nbcode_file));
00154 return (0);
00155
00156 }
00157 close( fdtest );
00158
00159 sprintf( nbcode_file,"%s/mar3450.%s", martable_dir, scanner_no);
00160 if( -1 == (fdtest= open( nbcode_file, 0))) {
00161 emit print_message(QString().sprintf("scan345: Cannot open %s as neighbour code file\n", nbcode_file));
00162 return (0);
00163
00164 }
00165 close( fdtest );
00166
00167
00168
00169
00170
00171
00172 if(NULL == (fp = fopen( config_file, "r"))) {
00173 emit print_message(QString().sprintf( "scan345: Cannot open file %s\n",config_file));
00174 }
00175 else {
00176 cfg = GetConfig( fp );
00177 fclose( fp );
00178 }
00179
00180
00181
00182
00183
00184 if ( strlen( mar_host ) < 1 )
00185 strcpy( mar_host, cfg.host );
00186 else
00187 strcpy( cfg.host, mar_host );
00188
00189 if ( !mar_port )
00190 mar_port = cfg.port;
00191 else
00192 cfg.port = mar_port;
00193
00194 if ( input_scale > -1.0 )
00195 cfg.spiral_scale = input_scale;
00196
00197 PutConfig( cfg );
00198
00199 for ( i=0; i<4; i++ ) {
00200 if ( cfg.use_msg == 0 && i == 3 ) break;
00201 netcontrol += net_open(i);
00202 }
00203 if ( cfg.use_msg == 0 ) i--;
00204
00205 if(netcontrol < 1 ) {
00206 emit print_message(QString().sprintf("scan345: Cannot connect to '%s' at port %d\n",mar_host,mar_port));
00207 emit print_message(QString().sprintf("scan345: No SCANNER control \n"));
00208 }
00209
00210
00211 if ( !netcontrol ) {
00212 exit(0);
00213 }
00214
00215
00216
00217
00218
00219 cur_mode = s.marscannermode();
00220
00221
00222 time(&now);
00223
00224 sprintf( str ,"\n=============================================================\n");
00225 emit print_message( str );
00226 sprintf( str ," Program : scan345\n");
00227 emit print_message( str );
00228 sprintf( str ," Version : %s (%s)\n",MAR_VERSION,__DATE__);
00229 emit print_message( str );
00230 sprintf( str ," Scanner no. : %s\n",scanner_no);
00231 emit print_message( str );
00232 sprintf( str ," Started on : %s",(char *) ctime(&now));
00233 emit print_message( str );
00234 sprintf( str ,"=============================================================\n\n");
00235 emit print_message( str );
00236
00237 emit print_message("scan345: Running tasks can only be aborted with ^\\ (SIGQUIT)\n\n");
00238
00239 return( netcontrol );
00240 }
00241
00242
00243
00244
00245 int
00246 MarStartup::trnlog(char *table, char *logical_name, char *name)
00247 {
00248 char *tr;
00249
00250 if(NULL == (tr = (char *) getenv(logical_name))) {
00251 name[0] = '\0';
00252 return 0;
00253 }
00254 else {
00255 strcpy(name,tr);
00256 return 1;
00257 }
00258 }
00259