Functions
waranscreend/main.cpp File Reference
#include <GpCoreTools.h>
#include "CrystalfontzDevice.h"
#include "CrystalfontzServer.h"
#include "waranscreendVersion.h"
#include "waranscreendInstallPath.h"

Functions

ApplicationHelphelp ()
int main (int argc, char **argv)
 PACKAGE_INFO (waranscreend, WARANSCREEND)

Function Documentation

int main ( int  argc,
char **  argv 
)

References GpCoreTools::EventLoop::addStream(), GpCoreTools::CoreApplication::applicationName(), GpCoreTools::DaemonApplication::close(), CrystalfontzDevice::configureBoot(), GpCoreTools::Serial::connect(), GpCoreTools::EventLoop::exec(), CrystalfontzDevice::firstPage(), GpCoreTools::DaemonApplication::fork(), help(), GpCoreTools::TcpServerStream::listen(), and GpCoreTools::DaemonApplication::start().

{
  DaemonApplication a(argc, argv, help);

  // Options
  std::string devicePath, bootVersion;
  uint16_t port=2977;
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    const char * arg=argv[i];
    if(arg[0]=='-') {
      if(strcmp(arg, "-p")==0) {
        CoreApplication::checkOptionArg(i, argc, argv, true);
        port=atoi(argv[i]);
      } else if(strcmp(arg, "-d")==0) {
        CoreApplication::checkOptionArg(i, argc, argv, true);
        devicePath=argv[i];
      } else if(strcmp(arg, "-boot-screen")==0) {
        CoreApplication::checkOptionArg(i, argc, argv, true);
        bootVersion=argv[i];
      } else {
        fprintf(stderr, "%s: bad option %s, see -help\n", a.applicationName(), argv[i]);
        CoreApplication::exit(2);
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }
  if(argc>1) {
    fprintf(stderr, "%s: bad option %s, see -help\n", a.applicationName(), argv[1]);
    CoreApplication::exit(2);
  }
  if(devicePath.size()==0) {
    fprintf(stderr, "%s: missing device path, see -help\n", a.applicationName());
    CoreApplication::exit(2);
  }
  std::vector<std::string> * devicePaths=File::complete(devicePath);
  switch(devicePaths->size()) {
  case 0:
    fprintf(stderr, "%s: no device named %s\n", a.applicationName(), devicePath.data());
    delete devicePaths;
    CoreApplication::exit(2);
  case 1:
    devicePath=devicePaths->front();
    delete devicePaths;
    break;
  default:
    fprintf(stderr, "%s: more than one device named %s\n", a.applicationName(), devicePath.data());
    delete devicePaths;
    CoreApplication::exit(2);
  }
  if(bootVersion.size()>0) {
    CrystalfontzDevice d(devicePath);
    d.connect();
    d.configureBoot(bootVersion);
    return 0;
  }

  a.fork();
  a.start();

  EventLoop loop;

  CrystalfontzDevice * device=new CrystalfontzDevice(devicePath);
  device->connect();
  if(!EventLoop::instance()->isTerminated()) {
    device->firstPage();
    loop.addStream(device);

    CrystalfontzServer * server=new CrystalfontzServer(device);
    while(!server->listen(port, 50)) {
      Log::write(1, "cannot listen to port %hu, retry in 10 seconds\n", port);
      sleep(10);
    }
    loop.addStream(server);

    loop.exec();
  }
  a.close();
  return 0;
}
PACKAGE_INFO ( waranscreend  ,
WARANSCREEND   
)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines