Functions
kephren_plugin/main.cpp File Reference
#include <signal.h>
#include <GeopsyCore.h>
#include <QGpCoreTools.h>
#include "TitanProcess.h"
#include "ConformProcess.h"
#include "FFTW.h"
#include "kephren_pluginVersion.h"
#include "kephren_pluginInstallPath.h"

Functions

void crashed (int)
ApplicationHelphelp ()
void interrupted (int)
int main (int argc, char **argv)
 PACKAGE_INFO (kephren_plugin, KEPHREN_PLUGIN)

Function Documentation

void crashed ( int  )

References QGpCoreTools::endl(), and QGpCoreTools::tr().

Referenced by main().

{
  App::stream() << tr("received SEGV or ABRT signal") << endl;
  Leds::timer(0, 100, 100);
  exit(2);
}
void interrupted ( int  )

References QGpCoreTools::endl(), and QGpCoreTools::tr().

Referenced by main().

{
  App::stream() << tr("received TERM or INTERRUPT signal") << endl;
  QCoreApplication::instance()->quit();
}
int main ( int  argc,
char **  argv 
)

References crashed(), QGpCoreTools::endl(), help(), interrupted(), ConformProcess::setStationName(), QGpCoreTools::CoreApplicationPrivate::setStreamPrefix(), ConformProcess::setTimeReference(), ConformProcess::start(), str, and QGpCoreTools::tr().

{
  CoreApplication a(argc, argv, help, false);
  a.setStreamPrefix("%t: ");
  GeopsyCoreEngine gp;
  new FFTW;


  // Use external leds to show status (if available)
  Leds leds;

  // Options
  QString titanPath, stationName, timeReference;
  double signalDuration=300.0;
  int watchInterval=60;
  QString server;
  quint16 port=18000;
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-s") {
        CoreApplication::checkOptionArg(i, argc, argv);
        titanPath=argv[i];
      } else if(arg=="-n") {
        CoreApplication::checkOptionArg(i, argc, argv);
        stationName=argv[i];
      } else if(arg=="-server") {
        CoreApplication::checkOptionArg(i, argc, argv);
        server=argv[i];
      } else if(arg=="-port") {
        CoreApplication::checkOptionArg(i, argc, argv);
        port=atoi(argv[i]);
      } else if(arg=="-d") {
        CoreApplication::checkOptionArg(i, argc, argv);
        signalDuration=atof(argv[i]);
      } else if(arg=="-tref") {
        CoreApplication::checkOptionArg(i, argc, argv);
        timeReference=argv[i];
      } else if(arg=="-m") {
        CoreApplication::checkOptionArg(i, argc, argv);
        watchInterval=atoi(argv[i]);
      } else if(arg=="--") { // force end of arguments
        for(i++; i<argc; i++) {
          argv[j++]=argv[i];
        }
        break;
      } else {
        App::stream() << tr("error: bad option %s, see -help").arg(argv[i]) << endl;
        Leds::timer(0, 100, 100);
        return 2;
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }
  if(argc==2) {
    QString str="%t - ";
    str+=argv[1];
    str+=": ";
    a.setStreamPrefix(str);
  } else if(argc>2) {
    App::stream() << tr("error: multiple plugin names specified for kephren_plugin") << endl;
    for(i=1; i<argc; i++) {
      App::stream() << QString("     ")+argv[i] << endl;
    }
    Leds::timer(0, 100, 100);
    return 2;
  } else {
    App::stream() << tr("error: no plugin name specified for kephren_plugin") << endl;
    Leds::timer(0, 100, 100);
    return 2;
  }

  signal(SIGTERM, interrupted);
  signal(SIGINT, interrupted);
  signal(SIGSEGV, crashed);
  signal(SIGABRT, crashed);

  /*if(titanPath.isEmpty()) {
    App::stream() << tr("error: source path no specified or empty (option '-s')") << endl;
    Leds::timer(0, 100, 100);
    return 2;
  }*/
  if(server.isEmpty()) {
    App::stream() << tr("error: server address no specified or empty (option '-server')") << endl;
    Leds::timer(0, 100, 100);
    return 2;
  }
  if(stationName.isEmpty()) {
    App::stream() << tr("error: station name no specified or empty (option '-n')") << endl;
    Leds::timer(0, 100, 100);
    return 2;
  }
  /*TitanProcess proc;
  proc.setInitialWatchDelay(watchInterval);
  proc.setSignalDuration(signalDuration);
  proc.setStationName(stationName);
  if(!timeReference.isEmpty()) {
    QDateTime t=QDateTime::fromString(timeReference, "yyyy-MM-dd");
    if(t.isValid()) {
      proc.setTimeReference(t);
    } else {
      App::stream() << tr("error: invalid time reference (option '-tref')\n") << endl;
      Leds::timer(0, 100, 100);
      return 2;
    }
  }
  if(!proc.setSourcePath(titanPath)) {
    Leds::timer(0, 100, 100);
    return 2;
  }*/

  ConformProcess proc;
  proc.setStationName(stationName);
  if(!timeReference.isEmpty()) {
    QDateTime t=QDateTime::fromString(timeReference, "yyyy-MM-dd");
    if(t.isValid()) {
      proc.setTimeReference(t);
    } else {
      App::stream() << tr("error: invalid time reference (option '-tref')\n") << endl;
      Leds::timer(0, 100, 100);
      return 2;
    }
  }
  proc.start(server, port);

  int appReturn=a.exec();
  return appReturn;
}
PACKAGE_INFO ( kephren_plugin  ,
KEPHREN_PLUGIN   
)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines