Public Types | Public Member Functions | Private Member Functions

MarStartup Class Reference

#include <marstartup.h>

Inheritance diagram for MarStartup:
Inheritance graph
[legend]

List of all members.

Public Types

typedef MarHW inherited

Public Member Functions

 MarStartup (QObject *parent=0)
int marStartup ()

Private Member Functions

int trnlog (char *table, char *logical_name, char *name)

Detailed Description

Definition at line 6 of file marstartup.h.


Member Typedef Documentation

Reimplemented from MarHW.

Reimplemented in Command, QScan345Controller, and Scan345.

Definition at line 12 of file marstartup.h.


Constructor & Destructor Documentation

MarStartup::MarStartup ( QObject *  parent = 0)

Definition at line 91 of file marstartup.cpp.

  : inherited(parent)
{
}

Member Function Documentation

int MarStartup::marStartup ( )

Definition at line 100 of file marstartup.cpp.

References cfg, config_file, cur_mode, GetConfig(), CONFIG::host, i, input_priority, input_scale, mar_host, mar_port, MAR_VERSION, QScan345Settings::marscannermode(), QScan345Settings::marscannernumber(), martable_dir, QScan345Settings::martabledir(), nbcode_file, MarNet::net_open(), netcontrol, now, CONFIG::port, MarXF::print_message(), PutConfig(), scanner_no, CONFIG::spiral_scale, str, CONFIG::use_msg, and working_dir.

Referenced by QScan345Controller::restart_scanner(), and Scan345::scan345_main().

{
  int                   i=0;
  int                   fdtest;
  time_t                now;
  extern int    input_priority;
  extern float  input_scale;
  FILE          *fp;

#ifdef __linux__
  if ( input_priority == -1 ) 
    input_priority = -20;
  /* Set priority to ... */
  i=setpriority(PRIO_PROCESS, (int)getpid(), input_priority);
  if ( i == -1 )
    input_priority = -1;
#elif __sgi
  if ( input_priority == -1 ) 
    input_priority = NDPHIMAX;
        
  while ( (i = schedctl( NDPRI, 0, input_priority ) ) == -1 ) {
    input_priority++;
    if ( input_priority > NDPNORMMIN ) break;
  }
  if ( i == -1 )
    input_priority = -1;
#endif

#ifndef __osf__
  if ( i < 0 ) {
    emit print_message(QString().sprintf("scan345: Cannot increase PRIORITY of process %d\n",getpid()));
  }
#endif

  /*
   * Get environment variables MARTABLEDIR and MAR_SCANNER_NO
   */

  QScan345Settings s;

  strcpy( martable_dir, qPrintable(s.martabledir()));
  sprintf(scanner_no, "%03d", s.marscannernumber());
#if ( __osf__ )
  strcpy( working_dir , (char *)getcwd( NULL, 256, 1 ) ) ;
#else
  strcpy( working_dir , (char *)getcwd( NULL, 256 ) ) ;
#endif

  sprintf(  config_file,"%s/config.%s",  martable_dir, scanner_no );

  /* Open neighbour code file... */     
  sprintf(  nbcode_file,"%s/mar2300.%s", martable_dir, scanner_no);
  if( -1 == (fdtest =  open( nbcode_file, 0 ))) {
    emit print_message(QString().sprintf("scan345: Cannot open %s as neighbour code file\n", nbcode_file));
    return (0);
//     exit( -1 );
  }
  close( fdtest );

  sprintf(  nbcode_file,"%s/mar3450.%s", martable_dir, scanner_no);
  if( -1 == (fdtest=  open( nbcode_file, 0))) {
    emit print_message(QString().sprintf("scan345: Cannot open %s as neighbour code file\n", nbcode_file));
    return (0);
//     exit( -1 );
  }
  close( fdtest );

  /***************************************************************** 
   * Get configuration parameters
   *****************************************************************/

  /* Open configuration file ... */
  if(NULL == (fp = fopen( config_file, "r"))) {
    emit print_message(QString().sprintf( "scan345: Cannot open file %s\n",config_file));
  }                                                     
  else {                                                
    cfg = GetConfig( fp );
    fclose( fp );
  }                                       

  /***************************************************************** 
   * Open network connection
   *****************************************************************/

  if ( strlen( mar_host ) < 1 )
    strcpy( mar_host, cfg.host );
  else
    strcpy( cfg.host, mar_host );
                
  if ( !mar_port )
    mar_port = cfg.port;
  else
    cfg.port = mar_port;

  if ( input_scale > -1.0 )
    cfg.spiral_scale = input_scale;

  PutConfig( cfg );                        

  for ( i=0; i<4; i++ ) {
    if ( cfg.use_msg == 0 && i == 3 ) break;
    netcontrol += net_open(i);
  }
  if ( cfg.use_msg == 0 ) i--;

  if(netcontrol < 1 ) {
    emit print_message(QString().sprintf("scan345: Cannot connect to '%s' at port %d\n",mar_host,mar_port));
    emit print_message(QString().sprintf("scan345: No SCANNER control \n"));
  }

  /* Display messages in marstart */
  if ( !netcontrol ) {
    exit(0); 
  }

  /***************************************************************** 
   * Initialize variables 
   *****************************************************************/

  cur_mode = s.marscannermode();

  /* Log the time to the errorlog for startup */
  time(&now);
        
  sprintf( str ,"\n=============================================================\n");
  emit print_message( str );
  sprintf( str ,"            Program     :  scan345\n");
  emit print_message( str );
  sprintf( str ,"            Version     :  %s  (%s)\n",MAR_VERSION,__DATE__);
  emit print_message( str );
  sprintf( str ,"            Scanner no. :  %s\n",scanner_no);
  emit print_message( str );
  sprintf( str ,"            Started on  :  %s",(char *) ctime(&now));
  emit print_message( str );
  sprintf( str ,"=============================================================\n\n");
  emit print_message( str );

  emit print_message("scan345: Running tasks can only be aborted with ^\\ (SIGQUIT)\n\n");

  return( netcontrol );
}
int MarStartup::trnlog ( char *  table,
char *  logical_name,
char *  name 
) [private]

Definition at line 246 of file marstartup.cpp.

{
  char  *tr;
        
  if(NULL == (tr = (char *) getenv(logical_name))) {
    name[0] = '\0';
    return 0;
  }
  else {
    strcpy(name,tr);
    return 1;
  }
}

The documentation for this class was generated from the following files: