LoggerReader_byte::LoggerReader_byte(unsigned int uBufSizei)
                                                                  /*{{{*/
{
#if DEBUG == 1
  printf("LoggerReader_byte::LoggerReader_byte(DaLoConf*, %i)\n", uBufSizei);
#endif
  
  fOK  = true;
  
  {
    readConf();
#if DEBUG == 1
    printf("nach readconf\n");
#endif
    inBufSize = nMaxFrameLen + 1 + 1; // Daten + Format
  }
  
  outBufSize        = uBufSizei;
  outBuf            = (unsigned char*)malloc(outBufSize);
  outBufFrames      = 0;
  outBufWr          = 0;
  outBufRd          = 0;
    
  inBuf             = (unsigned char*)malloc(inBufSize);
  inBufCntAndStatus = -1;      
  fCtrl             = false;
}
void FileParser::processLine(const QString &text)
{
  QStringList keyVal;
  if (intoData) {
    keyVal = readKeyVal(text);
    if (keyVal.size() <= 1)
      return;
    saveWordDic(keyVal);
    return;
  }

  QString section = readSection(text);
  if (!section.isEmpty()) {
    if (section == QString::fromUtf8("数据") || section == "Data") {
      intoData = true;
      intoRule = false;
      return;
    }
    if (section == QString::fromUtf8("组词规则") || section == "Rule") {
      intoRule = true;
    }
  }

  QStringList conf = readConf(text);
  if (!conf.isEmpty()) {
    if (intoRule == true) {
      QStringList tmp = conf.at(1).split('+');
      wordRule.append(qMakePair(conf.at(0), tmp));
    }
    if (conf.at(0) == QString::fromUtf8("键码") || conf.at(0) == "KeyCode") {
      KeyCode = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("码长") || conf.at(0) == "Length") {
      Length = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("拼音") || conf.at(0) == "Pinyin") { 
      Pinyin = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("拼音长度") || conf.at(0) == "PinyinLength") { 
      PinyinLength = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("提示") || conf.at(0) == "Prompt") { 
      Prompt = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("构词") || conf.at(0) == "ConstructPhrase") { 
      ConstructPhrase = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("规避字符") || conf.at(0) == "InvalidChar") { 
      InvalidChar = conf.at(1);
      return;
    }
  }
}
Beispiel #3
0
int main(int argc, char **argv)
{
  uint32_t v4l2_format = V4L2_PIX_FMT_RGB24;
  int bytes, pitch;
  Capturer *capturer;
  Engine *engine;
  uint8_t *frameBuffer;

  const char *config_filename = "ambiled.conf";

  Config config;
  readConf(config_filename, &config);

#ifdef DEBUG
  struct timeval stop, start;
#endif

  if(!setOverCommitMemory("1")) {
    exit(-1);
  }

//  SDL_Window *windowIn = 0;
//  SDL_Window *windowOut = 0;
//  SDL_Renderer *renderIn = 0;
//  SDL_Renderer *renderOut = 0;
//  SDL_Texture *textureIn = 0;
//  SDL_Texture *textureOut = 0;
//  int sdl_format;

  switch (config.videoType) {
    case CAPTURER:
      capturer = new USBGrabber();
      break;
    case PLAYER:
      capturer = new Video();
      break;
    case UNKNOWN:
      error("Unknown video type\n");
      exit(-1);
  }

  if(!capturer->open(config.videoPath, &config.width, &config.height, &v4l2_format)) {
    setOverCommitMemory("0");
    exit(-1);
  }

//  if (!initParams(v4l2_format, width, height, &sdl_format, &pitch, &bytes)) {
  if (!initParams(v4l2_format, config.width, config.height, &pitch, &bytes)) {
    delete capturer;
    error("Unknwn video color format\n");
    setOverCommitMemory("0");
    exit(-1);
  }

//  if (!initSDL(&windowIn, &renderIn, &textureIn, 0, 0, width, height, sdl_format, "Input stream")) {
//    delete capturer;
//    exit(-1);
//  }

//  if (!initSDL(&windowOut, &renderOut, &textureOut, width + 2, 0, width, height, sdl_format, "Leds")) {
//    delete capturer;
//    exit(-1);
//  }

  engine = new Engine(config.ledType, config.ledsUp, config.ledsRight, config.ledsDown, config.ledsLeft, config.width, config.height);
  if (!engine->initLedController(config.ledControllerPath, config.ledControllerType)) {
//  if (!engine->initLedController(piDev, controllerType)) {
    delete capturer;
    setOverCommitMemory("0");
    exit(-1);
  }

  frameBuffer = (uint8_t *) malloc(bytes);

//  SDL_UpdateTexture(textureIn, NULL, buffer, pitch);
//  SDL_UpdateTexture(textureOut, NULL, buffer, pitch);

//  SDL_SetEventFilter(filterSDLQuitEvent, NULL);

  signal(SIGINT, intHandler);

  while (!quit) {

#ifdef DEBUG
  gettimeofday(&start, NULL);
#endif

//    // Process events
//    while (SDL_PollEvent(NULL));

    // Capture and process input
    if (capturer->getFrame(frameBuffer, bytes)) {
//      SDL_UpdateTexture(textureIn, NULL, buffer, pitch);
      engine->processFrame(frameBuffer, bytes);
//      SDL_UpdateTexture(textureOut, NULL, output, pitch);
    }

//    // Update render
//    SDL_RenderClear(renderIn);
//    SDL_RenderCopy(renderIn, textureIn, NULL, NULL);
//    SDL_RenderPresent(renderIn);
//    SDL_RenderClear(renderOut);
//    SDL_RenderCopy(renderOut, textureOut, NULL, NULL);
//    SDL_RenderPresent(renderOut);

//#ifdef DEBUG
//  gettimeofday(&stop, NULL);
//  long time = stop.tv_usec - start.tv_usec;
//  printf("took %lu\n", (stop.tv_usec - start.tv_usec) / 1000);
//
//  long freeTime = (41.6 - (time / 1000)) * 1000 * 1000;
//  if (freeTime > 0) {
//    print("---------- Sleep %lu\n", freeTime / (1000 * 1000));
//    nanosleep((struct timespec[]){{0, freeTime}}, NULL);
//  }
//
//#endif
  }

  delete capturer;
  delete engine;
  free(frameBuffer);
//  SDL_DestroyRenderer(renderIn);
//  SDL_DestroyTexture(textureIn);
//  SDL_DestroyRenderer(renderOut);
//  SDL_DestroyTexture(textureOut);
//  SDL_Quit();
  setOverCommitMemory("0");

  return 0;
}
Beispiel #4
0
int main(int argc, char **argv){
/*
  key_t shmKey;
  int shmid;

  time_t curtime = -1;
  char xtime[40]="\0";
  long int size=4194304; //   = 4 MB // 131072;  //65536;
*/
  long int ii=0;
  long int adc=0;
  pid_t pid;
  int xx=0;


/*
  Set up LabJack U6
*/
  labjackSetup();

/*
  Shared memory creation and attachment
*/

  shmSetup();

/*  
   Get the process number for interupts when the two programs need to interact
*/
  pid = getpid();
  lnptr->pid = pid;
  printf("pid = %li \n",(long int)lnptr->pid);
/*  
   Set up the signal capture routine for when the reading
   program wants something changed
*/

  memset (&act,'\0', sizeof(act));
  act.sa_sigaction = &handlerCommand;
  act.sa_flags = SA_SIGINFO;
  if (sigaction(SIGALRM,&act,NULL) < 0){
    perror("sigaction");
    return 1;
  }

/*  
   Read setup file on disk and load into shared memory
*/
  printf("Read conf file...\n");
  readConf();
  printf(" ... Conf file read \n");
/*
  Go out and read RTDs and get everything needed loaded into shared memory
*/

  updateRTD();
  /*
  for (ii=0; ii<20; ii++){
    if (lnptr->ge[ii].onoff == 1){
      lnptr->ge[ii].rtd = readRTD(lnptr->ge[ii].chanRTD);
      lnptr->ge[ii].oflo = readRTD(lnptr->ge[ii].chanOFLO);
      printf("Active det: %li ->  %lf   %lf\n", ii,lnptr->ge[ii].rtd,lnptr->ge[ii].oflo );
    }
  }
  lnptr->tank.rtd = readRTD(lnptr->tank.chanRTD);
  lnptr->tank.pressure = readRTD(lnptr->tank.chanPRES);

  printf("TANK: %lf\n", lnptr->tank.rtd);
  */
/*  
  Setup time of next fill based on current time and configure file
*/
  curtime = time(NULL);
  time0 = curtime;               // record starting time of program
  time1 = time0 + INTERVAL;      // set up next read of RTD...usually every minute

  for (ii=0; ii<20; ii++){
    if (lnptr->ge[ii].onoff == 1){
      lnptr->ge[ii].next = time0 + lnptr->ge[ii].interval;
    }
    else {
      lnptr->ge[ii].next = 0;
    }
  }

/*  
  Setup monitoring loop to look for changes and requests   
*/
//  setTimer();
  outletStatus();
/*  
  Setup monitoring loop to look for changes/minute and requests   
*/
  nread = INTERVAL;
  lnptr->command = 0;

  while(lnptr->command != -1) {

    //    curtime = time(NULL);                   // check what time it is - confirm still running
    //    lnptr->secRunning = curtime - time0;    // record time running (lets user now it it is still up)
    updateRTD();                            // read and update the RTD information including lnptr->secRunning 
/*
    if (curtime >= time1) {                 // read RTDs every INTERVAL (usually ~60 s)
      //      time1 = time1+INTERVAL;
    /     time1 = time1+nread;              // read RTDs every nread (usually INTERVAL though during a fill it might be more often)
      updateRTD();
    }

   Check if an RTD is too high
*/
    for (ii=0;ii<20;ii++){                               // run thru each detector possibility
      if (lnptr->ge[ii].onoff == 1) {                    // run thru each detector that is ON
	if (lnptr->ge[ii].rtd > lnptr->ge[ii].limit){    // check rtd is within limit
	  printf("SHUT DOWN !\n");
	  strcpy(lnptr->ge[ii].status,"ALARM");
	}
	if (curtime > lnptr->ge[ii].next){               // check if its time to fill a detector
	  printf("start a fill ...set command to 8 = Fill All! \n");
	  lnptr->command = 8;
	} 
      }
    }

    //  AFTER THIS LOOP CHECK FOR COMMANDS COMING IN FROM CONTROL PROGRAM

    if (lnptr->command > 20 &&   lnptr->command <= 40){
      closeDet(lnptr->command-21);                      // way to close individual valves
      lnptr->command=0;
    }
    else if (lnptr->command > 40 &&  lnptr->command <= 60) {
      openDet(lnptr->command-41);                       // way to open individual valves
      lnptr->command=0;
    }
    else {
      switch (lnptr->command) {
      case 0:
/*
      //      signal(SIGTERM,alarm_wakeup);   // set the Alarm signal capture 
      sleep (1);                      // pause for time
      curtime = time(NULL);
      printf ("curtime = %li %li \n", curtime, (time1-curtime));
      if (curtime >= time1) {
	time1 = time1+INTERVAL;
	updateRTD();
      }
*/
	break;
      case 1:
	printf ("1 selected\n");
	updateRTD();
	lnptr->command=0;
	break;
      case 2:
	printf ("2 selected\n");
	lnptr->command=0;
	break;
      case 3:
	printf ("3 selected\n");
	lnptr->command=0;
	break;

      case 7:
	printf ("7 selected\n");   // fill 1 detector
	lnptr->command=0;
	break;
      case 8:
	printf ("8 selected\n");    // fill All
	fillAll();
	lnptr->command=0;
	break;
      case 10:
	printf ("10 selected\n");
	closeAllValves();             // close all valves including tank but open manifold
	lnptr->command=0;
	break;
      case 11:
	printf ("14 selected\n");
	closeTank();                  // open tank
	lnptr->command=0;
	break;
      case 12:
	printf ("14 selected\n");
	closeTank();                  // close Tank
	lnptr->command=0;
	break;
      case 13:
	printf ("11 selected\n");
	closeMani();                  // close Manifold
	lnptr->command=0;
	break;
      case 14:
	printf ("15 selected\n");
	openMani();                  // open Manifold
	lnptr->command=0;
	break;
      case 17:
	printf ("17 selected\n");     // initial cooldown
	outletStatus ();
	lnptr->command=0;
	break;
      case 18:
	printf ("18 selected\n");     // initial cooldown
	break;
      default:
	printf ("default selected\n");
	lnptr->command=0;
	break;
      }
    }        
    sleep (nread);
  }


/*
   Release the shared memory and close the U6

*/
  shmdt(lnptr);                     // detach from shared memory segment
  printf("detached from SHM\n");

  shmctl(shmid, IPC_RMID, NULL);    // remove the shared memory segment hopefully forever
  printf("removed from SHM\n");

  closeUSBConnection(hU6);
  printf("USB closed\n");


  return 0;
}
Beispiel #5
0
int main(int argc, char **argv){
/*
  key_t shmKey;
  int shmid;

  time_t curtime = -1;
  char xtime[40]="\0";
  long int size=4194304; //   = 4 MB // 131072;  //65536;
*/
  long int ii=0;
  long int adc=0;
  pid_t pid;
  int xx=0;

  struct sigaction act;

/*
  Set up LabJack U6
*/
  labjackSetup();

/*
  Shared memory creation and attachment
*/

  shmSetup();

/*  
   Get the process number for interupts when the two programs need to interact
*/
  pid = getpid();
  lnptr->pid = pid;
  printf("pid = %li \n",lnptr->pid);
/*  
   Set up the signal capture routine for when the reading
   program want something changed
*/

  memset (&act,'\0', sizeof(act));
  act.sa_sigaction = &handlerCommand;
  act.sa_flags = SA_SIGINFO;
  if (sigaction(SIGALRM,&act,NULL) < 0){
    perror("sigaction");
    return 1;
  }

/*  
   Read setup file on disk and load into shared memory
*/
  printf("Read conf file...\n");
  readConf();
  printf(" ... Conf file read \n");
/*
  Go out and read RTDs and get everything needed loaded into shared memory
*/

  updateRTD();
  /*
  for (ii=0; ii<20; ii++){
    if (lnptr->ge[ii].onoff == 1){
      lnptr->ge[ii].rtd = readRTD(lnptr->ge[ii].chanRTD);
      lnptr->ge[ii].oflo = readRTD(lnptr->ge[ii].chanOFLO);
      printf("Active det: %li ->  %lf   %lf\n", ii,lnptr->ge[ii].rtd,lnptr->ge[ii].oflo );
    }
  }
  lnptr->tank.rtd = readRTD(lnptr->tank.chanRTD);
  lnptr->tank.pressure = readRTD(lnptr->tank.chanPRES);

  printf("TANK: %lf\n", lnptr->tank.rtd);
  */
/*  
  Setup time of next fill based on current time and configure file
*/
  curtime = time(NULL);
  time0 = curtime;             // record starting time of program
  time1 = time0 + INTERVAL;      // set up next read of RTD...usually every minute

  for (ii=0; ii<20; ii++){
    if (lnptr->ge[ii].onoff == 1){
      lnptr->ge[ii].next = time0 + lnptr->ge[ii].interval;
    }
    else {
      lnptr->ge[ii].next = 0;
    }
  }

/*  
  Setup monitoring loop to look for changes and requests   
*/
  setTimer();
  /*
  tout_val.it_interval.tv_sec = 0;
  tout_val.it_interval.tv_usec = 0;

  tout_val.it_value.tv_sec = INTERVAL; // set timer for "INTERVAL (10) seconds 
  tout_val.it_value.tv_usec = 0;

  setitimer(ITIMER_REAL, &tout_val,0);   // start the timer
  */
/*  
  Setup monitoring loop to look for changes/minute and requests   
*/
  lnptr->command = 0;
  while(lnptr->command != -1) {
    curtime = time(NULL);               // check what time it is 
    if (curtime >= time1) {             // read RTDs every INTERVAL (usually ~60 s)
      time1 = time1+INTERVAL;
      updateRTD();
    }
/*
   Check if an RTD is too high
*/
    for (ii=0;ii<20;ii++){                 // run thru each detector possibility
      if (lnptr->ge[ii].onoff == 1) {      // run thru each detector that is ON


	if (lnptr->ge[ii].rtd > lnptr->ge[ii].limit){    // check rtd is within limit
	  printf("SHUT DOWN !\n");
	  strcpy(lnptr->ge[ii].status,"ALARM");
	}
	if (curtime > lnptr->ge[ii].next){               // check rtd is within limit
	  printf("start a fill !\n");
	} 
      }
    }

    //  AFTER THIS LOOP CHECK FOR COMMANDS COMING IN FROM CONTROL PROGRAM

      /*    
    switch (lnptr->command) {
    case 0:
      //      signal(SIGTERM,alarm_wakeup);   // set the Alarm signal capture 
      sleep (1);                      // pause for time
      curtime = time(NULL);
      printf ("curtime = %li %li \n", curtime, (time1-curtime));
      if (curtime >= time1) {
	time1 = time1+INTERVAL;
	updateRTD();
      }
      break;
    case 1:
      printf ("1 selected\n");
	break;
    case 2:
      printf ("2 selected\n");
	break;
    default:
      printf ("default selected\n");
      lnptr->command=-1;
	break;
    }
      */    
    sleep (59);
  }

/*
  Alarm processing
*/

/*  
   
*/

/*
   Print out some of shared memory to show it has been accessed

  ln.ge[0].rtd = 80.2;

  for (ii=0; ii< 20; ii++){
    ln.ge[ii].rtd = ln.ge[0].rtd + (double) ii;
    lnptr->ge[ii].rtd = ln.ge[ii].rtd;
    printf ("rtd[%li] = %.2lf = %.2lf\n", ii, ln.ge[ii].rtd,lnptr->ge[ii].rtd);

    sleep (1);
  }
*/
  shmdt(lnptr);                     // detach from shared memory segment
  printf("detached from SHM\n");

  shmctl(shmid, IPC_RMID, NULL);    // remove the shared memory segment hopefully forever
  printf("removed from SHM\n");

  closeUSBConnection(hU6);
  printf("USB closed\n");


  return 0;
}
Beispiel #6
0
/*
 * Main function, entry point
 */
int main(int argc, char** argv)
{
    // Open syslog
    lgOpenSyslog();

    // Fork
    createChildExitOnFailure();

    // Install signal handlers and setup exit function
    setupSignalsExit();

    // get path to configuration
    if (argc != 2) {
        syslog(LOG_ERR, "Configuration file not passed. Please use %s <path-configuration-file>.\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // read configuration
    readConf(argv[1]);

    // open log
    lgOpenLog();

    // Syslog not needed anymore, from now on write to log file
    lgCloseSyslog();

    // Close out the standard file descriptors
    if (closeStdFileDescriptors()) {
        die("Cannot close standard file descriptors.\n");
    }

    // Create a new SID for the child process
    if (createSID() < 0) {
        die("Cannot create new sid for the child process.\n");
    }

    // Change the current dir (prevent unmount)
    if (changeRootDir() < 0) {
        die("Cannot change to root dir.\n");
    }

    // Read old PID check if is still running
    FILE *fopid = fopen(pidFile, "r");
    if (fopid != NULL) { // file exists
        char * line = NULL;
        size_t len_allocated = 0;
        ssize_t res = getline(&line, &len_allocated, fopid);
        if (res != -1) {
            // remove newline
            size_t len = strlen(line);
            if(line[len-1] == '\n') {
                line[len-1] = '\0';
            }
            #if defined(DEBUG)
            char ddate[64];
            utilGetDate(ddate);
            fprintf(fpl, "%s - Old PID %s.\n", ddate, line);
            #endif
        }
    }

    return (EXIT_SUCCESS);
}
Beispiel #7
0
    int fastPy::go(int argc, char **argv) {
        int c;
        
        app_name = argv[0];
        
        while ((c = getopt (argc, argv, "dhvc:s:")) != -1) {
            switch (c) {
                case 'd':
                    detach = true;
                    break;                    
                case 'v':
                    if (verbose) debug = true;
                    verbose = true;
                    break;
                case 'c':
                    config_f = optarg;
                    break;
                case 's':
                    sock_f = optarg;
                    break;                    
                case 'h':
                default:
                    usage();
                    return 255;
            }        
        }

        if (config_f == NULL || sock_f == NULL) {
            ts_cout("Config and socket is required");
            usage();
            return 254;
        }
        
        if (readConf(config_f) < 0) {
            return 253;
        }

        if (changeID() < 0) {
            logError("master", LOG_ERROR, "Unable start with user: %s and group: %s", conf.user.c_str(), conf.group.c_str());
            return 252;
        }
                
        if (chdir(wsgi.base_dir.c_str()) < 0) {
            logError("master", LOG_ERROR, "Unable to change working directory to <%s>, check ownership", wsgi.base_dir.c_str());
            return 251;
        }
        
        fcgi = new fastcgi;
        
        // opening socket
        if (fcgi->openSock(sock_f) < 0) {
            logError("master", LOG_ERROR, "Unable to open socket");
            return 250;
        }
                
        if (detach) {
            int d_rc = detachProc();
            if (d_rc > 0) {
                // write pid file here
                return 0;
            } else if (d_rc < 0) {
                return 249;
            }
        } 
        
        for (int i=0; i < conf.workers_cnt; i++) {
            startChild();
        }
        
        if (masterLoop() < 0) {
            return 248;
        }
        
        return 0;
    }
Beispiel #8
0
int main(int argc, char *argv[])
{
  unsigned i, j, k;
  systemConfig *SYS;
  contextConfig *CNT;
  hyperContextConfig *HCNT;
  /*clusterTemplateConfig *CLUT;*/

  systemT *system;
  contextT *context;
  hyperContextT *hypercontext;
  /*clusterT *cluster;*/
  /*unsigned *tempP, clust;*/
  unsigned bundleCount;
  unsigned long long *bundleCountP;

  /*unsigned curClustTemplate, curClustInstance;*/
  /*unsigned sGPROffset, sFPROffset, sVROffset, sPROffset;*/
  /* signal catch (SIGSEGV and SIGUSR1) */
  pid_t pid;
  struct sigaction sigusr1_action;
  sigset_t block_mask;
  unsigned int STACK_SIZE_ARG = 0;

  isLLVM = 0;
  cycleCount = 0;
  char *versionNumber = "Insizzle_Revision";
  similarIRAM = 0;
  suppressOOB = 1;
  STACK_SIZE = 8; /* Default stack size to 8 KiB */
  PRINT_OUT = 0;
  SINGLE_STEP = 0;
  STAGGER = 0;
  printf("Insizzle (%s)\n", versionNumber);

  /* signal catch (SIGSEGV and SIGUSR1) */
  if((pid = getpid()) >= 0) {
    printf("PID: %d\n", pid);
    printf("(send SIGUSR1 signal to produce state dump)\n");
  }
  signal(SIGSEGV, sigsegv_debug);
  sigfillset(&block_mask);
  sigusr1_action.sa_handler = sigusr1_debug;
  sigusr1_action.sa_mask = block_mask;
  sigusr1_action.sa_flags = 0;
  sigaction(SIGUSR1, &sigusr1_action, NULL);

#ifndef INSIZZLEAPI
  if(argc < 2) {
    printf("you need to specify an xml machine model file\n");
    return -1;
  }

  if(readConf(argv[1]) == -1) {
    printf("error reading config\n");
    return -1;
  }
  /* all setup perfomed
     reset rand()
  */
  srand(1);

  printf("Galaxy setup completed.\n");
  /* for each other argv */
  for(i=2;i<(unsigned)argc;i++) {
	  if(!strncmp(argv[i], "-similarIRAM", 12)) {
      similarIRAM = 1;
    }
    else if(!strncmp(argv[i], "-suppressOOB", 12)) {
      suppressOOB = 1;
    }
    else if(!strncmp(argv[i], "-stack", 6)) {
      STACK_SIZE_ARG = atoi(argv[++i]);
    }
    else if(!strncmp(argv[i], "-printout", 9)) {
      PRINT_OUT = 1;
    }
    else if(!strncmp(argv[i], "-singlestep", 11)) {
      SINGLE_STEP = 1;
    }
    else if(!strncmp(argv[i], "-stagger", 8)) {
      STAGGER = atoi(argv[++i]);
    }
    else if(!strncmp(argv[i], "-calls_list", 11)) {
      /* setup calls list */
      callsList = NULL;
      if(setupCallsList(argv[i+1]) != 0) {
	return -1;
      }
      i++;
    }
    else if(!strncmp(argv[i], "-llvm", 5)) {
      isLLVM = 1;
    }
    else {
      printf("Unknown argument: %s\n", argv[i]);
    }
  }

  /* call config to setup the galaxy */
  if(setupGalaxy() == -1) {
    printf("error setting up galaxy\n");
    return -1;
  }

  /* then run through like we do */

  /* for each system
        for each context
	  for each hypercontext
  */


  SYS = (systemConfig *)((size_t)SYSTEM + (0 * sizeof(systemConfig)));
  system = (systemT *)((size_t)galaxyT + (0 * sizeof(systemT)));
  context = (contextT *)((size_t)system->context + (0 * sizeof(contextT)));

  /* check stack size */
  if((SYS->STACK_SIZE == 0) && (STACK_SIZE_ARG == 0)) {
    /* this means it isn't set in the XML file or command line */
    printf("Using default Stack Size / hypercontext of %d KiB\n", STACK_SIZE);
  }
  else if(STACK_SIZE_ARG != 0){
    /* set at command line, this overrides others */
    printf("Using Stack Size / hypercontext of %d KiB\n", STACK_SIZE_ARG);
    if(STACK_SIZE_ARG != SYS->STACK_SIZE) {
      printf("\tThis is different from Stack Size set in XML config file\n");
    }
    STACK_SIZE = STACK_SIZE_ARG;
  }
  else if(SYS->STACK_SIZE != 0) {
    /* set in XML */
    printf("Using Stack Size / hypercontext of %d KiB\n", SYS->STACK_SIZE);
    STACK_SIZE = SYS->STACK_SIZE;
  }

#ifdef VTHREAD
  /* need to set single hypercontext to active
     c 0 hc 0
  */
  for(i=0;i<(GALAXY_CONFIG & 0xff);i++)
    {
      SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig)));
      system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT)));

      /* loop through contexts */
#if 0
      for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++)
	{
	  context = (contextT *)((size_t)system->context + (j * sizeof(contextT)));
	  hypercontext = (hyperContextT *)((size_t)context->hypercontext + (0 * sizeof(hyperContextT)));
	  hypercontext->VT_CTRL |= RUNNING << 3;
	}
#else
      context = (contextT *)((size_t)system->context + (0 * sizeof(contextT)));
      hypercontext = (hyperContextT *)((size_t)context->hypercontext + (0 * sizeof(hyperContextT)));
      hypercontext->VT_CTRL |= RUNNING << 3;
#endif
    }

  /* Initialise ThreadControlUnit */
  ThreadControlUnit.status = 0;
#endif

  int totalHC = 0;

  /* loop through systems in the galaxy */
  for(i=0;i<(GALAXY_CONFIG & 0xff);i++)
    {
      SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig)));
      system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT)));
      /*printf("dram_size: 0x%x\n", (((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024));*/

      /* loop through contexts */
      for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++)
	{
	  CNT = (contextConfig *)((size_t)SYS->CONTEXT + (j * sizeof(contextConfig)));
	  context = (contextT *)((size_t)system->context + (j * sizeof(contextT)));

	  /* loop through hypercontexts */
	  for(k=0;k<((CNT->CONTEXT_CONFIG >> 4) & 0xf);k++)
	    {
	      HCNT = (hyperContextConfig *)((size_t)CNT->HCONTEXT + (k * sizeof(hyperContextConfig)));
	      hypercontext = (hyperContextT *)((size_t)context->hypercontext + (k * sizeof(hyperContextT)));

	      /*printf("hypercontext: %d\n", k);*/
	      hypercontext->initialStackPointer = (((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - ((STACK_SIZE * 1024) * totalHC);
	      *(hypercontext->S_GPR + (size_t)1) = ((((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - 256) - ((STACK_SIZE * 1024) * totalHC);
	      *(hypercontext->pS_GPR + (size_t)1) = ((((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - 256) - ((STACK_SIZE * 1024) * totalHC);
	      /*printf("\tr1: 0x%x\n", *(hypercontext->S_GPR + (unsigned)1));*/
	      /*printf("\tr1: 0x%x\n", *(hypercontext->pS_GPR + (unsigned)1));*/
	      totalHC++;
	    }

	}
    }

#endif
  start = time(NULL);
#endif

#ifdef INSIZZLEAPI
  int insizzleAPIClock(galaxyConfigT *galaxyConfig, hcTracePacketT gTracePacket[][MASTERCFG_CONTEXTS_MAX][MASTERCFG_HYPERCONTEXTS_MAX])
  {
    unsigned i, j, k;

    systemConfig *SYS;
    contextConfig *CNT;
    hyperContextConfig *HCNT;
    /*clusterTemplateConfig *CLUT;*/

    systemT *system;
    contextT *context;
    hyperContextT *hypercontext;
    unsigned bundleCount;
    unsigned long long *bundleCountP;
    unsigned bundlePos;
#else
  while(checkActive())
    {
      if(PRINT_OUT) {
	printf("------------------------------------------------------------ end of cycle %lld\n", cycleCount);
      }
#endif

#ifdef INSDEBUG
      printf("galaxy: 0\n");
#endif
      /* loop through systems in the galaxy */
      for(i=0;i<(GALAXY_CONFIG & 0xff);i++)
	{
#ifdef INSDEBUG
	  printf("\tsystem: %d\n", i);
#endif
	  SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig)));
	  system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT)));

	  /* loop through contexts */
	  for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++)
	    {
#ifdef INSDEBUG
	      printf("\t\tcontext: %d\n", j);
#endif
	      CNT = (contextConfig *)((size_t)SYS->CONTEXT + (j * sizeof(contextConfig)));
	      context = (contextT *)((size_t)system->context + (j * sizeof(contextT)));

	      /* loop through hypercontexts */
	      for(k=0;k<((CNT->CONTEXT_CONFIG >> 4) & 0xf);k++)
		{
#ifdef INSDEBUG
		  printf("\t\t\thypercontext: %d\n", k);
#endif
		  HCNT = (hyperContextConfig *)((size_t)CNT->HCONTEXT + (k * sizeof(hyperContextConfig)));
		  hypercontext = (hyperContextT *)((size_t)context->hypercontext + (k * sizeof(hyperContextT)));
#ifdef INSIZZLEAPI
		  bundlePos = 0;
#endif
#ifdef INSDEBUG
		  printf("\t\t\t\thypercontext totalWidth: %d\n", hypercontext->totalWidth);
#endif
#ifdef INSDEBUG
		  printf("hypercontext cycleCount: %lld\n", hypercontext->cycleCount);
#endif
		  /* TODO: here will be the status check of the hypercontext to see what
		     state it is in
		  */
		  /* check the state VT_CTRL */
#ifdef INSDEBUG
		  printf("hypercontext->VT_CTRL: 0x%08x\n", hypercontext->VT_CTRL);
#endif

		  unsigned int deepstate = (hypercontext->VT_CTRL >> 3) & 0xff;
		  unsigned int sstep = (hypercontext->VT_CTRL >> 2) & 0x1;
		  unsigned int debug = (hypercontext->VT_CTRL >> 1) & 0x1;
		  /*unsigned int kernel = hypercontext->VT_CTRL & 0x1;*/

#ifdef INSDEBUG
		  printf("\tdeepstate: %d\n", deepstate);
		  printf("\tsstep:     %d\n", sstep);
		  printf("\tdebug:     %d\n", debug);
		  /*printf("\tkernel:    %d\n", kernel);*/
#endif

#ifdef INSIZZLEAPI
		  /* full 32 bit register */
		  /*gTracePacket[i][j][k].vt_ctrl = hypercontext->VT_CTRL;*/
		  /* just the deepstate */
		  gTracePacket[i][j][k].vt_ctrl = (hypercontext->VT_CTRL >> 3) & 0xff;
#endif
		  if(debug)
		    {

#ifdef INSDEBUG
		      printf("HC STATE: DEBUG\n");
#endif
		      /* nothing to do here */
		    }
		  else
		    {
		      /* TODO: need to implement this
			 it will be dependant on having something to say go
		       */
		      if(sstep)
			{
			  int sstmode = 0;
			  do {
			      printf("SINGLE STEP MODE: ");
			      if(scanf("%d", &sstmode) == EOF)
				return -1;
			  } while(!sstmode);

			  if(deepstate == READY)
			    printf("HC STATE: SSTEP_READY\n");
			  else if(deepstate == RUNNING)
			    printf("HC STATE: SSTEP_RUNNING\n");
			  else if(deepstate == BLOCKED_MUTEX_LOCK)
			    printf("HC STATE: SSTEP_BLOCKED_MUTEX_LOCK\n");
			  else if(deepstate == TERMINATED_SYNC)
			    printf("HC STATE: SSTEP_TERMINATED_SYNC\n");
			  else
			    {
			      printf("HC STATE: UNKNOWN\n");
			      return -1;
			    }
			}
		      else
			{
			  if(deepstate == READY)
			    {
#ifdef INSDEBUG
			      printf("HC STATE: READY\n");
#endif
			      hypercontext->idleCount++;
			    }
			  else if(deepstate == RUNNING)
			    {
#ifdef INSDEBUG
			      printf("HC STATE: RUNNING\n");
			      printf("%d:%d:%d (system:context:hypercontext)\n", i, j, k);
#endif

			      /* TODO: check the microarchitectural state of the hypercontext */
			      /* stalled, running */
			      bundleCount = 0;
			      if(hypercontext->stalled > 0)
				{
				  hypercontext->stallCount++;
				  hypercontext->stalled--;
				}
			      else
				{
				  if(hypercontext->checkedPC != (int)hypercontext->programCounter)
				    {
				      hypercontext->checkedPC = (int)hypercontext->programCounter;
#ifdef INGDEBUG
				      printf("checking bundle for PC: 0x%x\n", hypercontext->programCounter);
#endif
				      instructionPacket this;
				      unsigned startPC = hypercontext->programCounter;
				      unsigned endPC = hypercontext->programCounter;

				      do {
					this = fetchInstruction(context, endPC, CNT);
					if((this.op >> 31) & 0x1)
					  {
					    if(this.immValid)
					      {
						endPC += 4;
					      }
					    break;
					  }
					endPC  = this.nextPC;
				      } while(!(this.op >> 31) & 0x1);
#ifdef INSDEBUG
				      printf("startPC: 0x%x\n", startPC);
				      printf("endPC: 0x%x\n", endPC);
#endif

				      unsigned cB = checkBundle(hypercontext, startPC, endPC);
				      if(cB > 0) {
					if(cB > hypercontext->memoryStall) {
					  hypercontext->decodeStallCount += cB;
#ifdef NOSTALLS
					  hypercontext->stallCount += cB;
#else
					  unsigned long long *bundleCountP;
					  bundleCountP = (unsigned long long *)((size_t)hypercontext->bundleCount);
					  *bundleCountP = *bundleCountP + 1;

					  hypercontext->stalled += (cB-1);
					  hypercontext->cycleCount++;
					  hypercontext->stallCount++;
					  continue;
#endif					
					}
					else {
					  /* don't need to add extra stall, because the memory stalls hides it */
					}
				      }
				    }

				  /* Memory Stalls here */
				  if(hypercontext->memoryStall > 0) {
				    hypercontext->memoryStall--;
				    hypercontext->cycleCount++;
				    continue;
				  }

#ifdef INSDEBUG
				  printf("already checked bundle for PC: 0x%x\n", hypercontext->programCounter);
#endif
				  /*if(cycle(context, hypercontext, (HCNT->HCONTEXT_CONFIG & 0xf)) == -1)
				    {
				    printf("Error\n");
				    return -1;
				    }*/
				  instructionPacket this;
				  instruction inst;
				  /* TODO: possibly zero these out */
				  do {
				    bundleCount++;
				    this = fetchInstruction(context, hypercontext->programCounter, CNT);

#ifdef INSDEBUG
				    printf("PC: 0x%x, this.op: 0x%08x\n", hypercontext->programCounter, this.op);
				    if(this.immValid)
				      printf("PC: 0x%x, this.imm: 0x%08x\n", (hypercontext->programCounter + 4), this.imm);
#endif

				    inst = instructionDecode(this.op, this.imm, /*system->dram,*/ hypercontext, system, /*context, hypercontext->VT_CTRL, */(((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024));

				    /*printf("%d : %d : ", *(hypercontext->S_GPR + 60), *(hypercontext->pS_GPR + 60));*/
  if((inst.packet.addr == 0) && (inst.packet.target == 1)) {
    /*    printf("\nsetting stack register\n");
    printf("initialStackPointer: 0x%x\n", hypercontext->initialStackPointer);
    printf("stackSize: %d\n", STACK_SIZE);
    printf("diff: %d\n", (hypercontext->initialStackPointer - inst.packet.data));*/
    if((hypercontext->initialStackPointer - inst.packet.data) >= (STACK_SIZE * 1024)) {
      /*
      printf("POSSIBLY OUT OF STACK?\n");
      printf("diff: %d\n", (hypercontext->initialStackPointer - inst.packet.data));*/
      int system_id = (((hypercontext->VT_CTRL) >> 24) & 0xff);
      int context_id = (((hypercontext->VT_CTRL) >> 16) & 0xff);
      int hypercontext_id = (((hypercontext->VT_CTRL) >> 12) & 0xf);
      printf("\tStack Overflow detected in [%d][%d][%d]:\n", system_id, context_id, hypercontext_id);
      printf("\t\tStack Pointer initially: 0x%x (%d)\n", hypercontext->initialStackPointer, hypercontext->initialStackPointer);
      printf("\t\tStack Size: 0x%x (%d)\n", (STACK_SIZE * 1024), (STACK_SIZE * 1024));
      printf("\t\tStack Pointer now: 0x%x (%d)\n", inst.packet.data, inst.packet.data);
      printf("\t\tTry setting stack pointer to %d K ( -stack=%d )\n", (hypercontext->initialStackPointer - inst.packet.data),
	     ((int)ceil((hypercontext->initialStackPointer - inst.packet.data) / 1024) + 1));
    }
  }
				    if(PRINT_OUT) {
#ifndef INSIZZLEAPI
				      printOut(inst, this, hypercontext, cycleCount);
#else
				      printOut(inst, this, hypercontext, 0);
#endif
				    }
				    if(SINGLE_STEP) {
				      stateDumpToTerminal(inst, hypercontext, cycleCount);
				      stateDump();
				      printf("Press enter to continue.");
				      getchar();

				    }

#ifdef INSIZZLEAPI
				    /* populate the gTracePacketT here */
				    gTracePacket[i][j][k].bundle[bundlePos].executed = inst.packet.executed;
				    gTracePacket[i][j][k].bundle[bundlePos].syll = this.op;
				    /*gTracePacket[i][j][k].bundle[bundlePos].syllValid = 1;*/
				    gTracePacket[i][j][k].bundle[bundlePos].pc = hypercontext->programCounter;

				    if(this.immValid) {
				      gTracePacket[i][j][k].bundle[bundlePos].imm = this.imm;
				      /*gTracePacket[i][j][k].bundle[bundlePos].immValid = this.immValid;*/
				    }
				    else {
				      gTracePacket[i][j][k].bundle[bundlePos].imm = 0;
				      /*gTracePacket[i][j][k].bundle[bundlePos].immValid = this.immValid;*/
				    }

				    gTracePacket[i][j][k].bundle[bundlePos].maddr = inst.packet.maddr;
				    gTracePacket[i][j][k].bundle[bundlePos].maddrValid = inst.packet.maddrValid;

				    /* source register 1 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs1.regType = inst.packet.source[0].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs1.reg = inst.packet.source[0].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs1.valid = inst.packet.source[0].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs1.val = inst.packet.source[0].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs1.cluster = inst.packet.source[0].cluster;

				    /* source register 2 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs2.regType = inst.packet.source[1].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs2.reg = inst.packet.source[1].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs2.valid = inst.packet.source[1].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs2.val = inst.packet.source[1].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs2.cluster = inst.packet.source[1].cluster;

				    /* source register 3 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs3.regType = inst.packet.source[2].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs3.reg = inst.packet.source[2].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs3.valid = inst.packet.source[2].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs3.val = inst.packet.source[2].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs3.cluster = inst.packet.source[2].cluster;

				    /* source register 4 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs4.regType = inst.packet.source[3].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs4.reg = inst.packet.source[3].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs4.valid = inst.packet.source[3].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs4.val = inst.packet.source[3].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs4.cluster = inst.packet.source[3].cluster;

				    /* source register 5 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs5.regType = inst.packet.source[4].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs5.reg = inst.packet.source[4].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs5.valid = inst.packet.source[4].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs5.val = inst.packet.source[4].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs5.cluster = inst.packet.source[4].cluster;

				    /* source register 6 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs6.regType = inst.packet.source[5].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs6.reg = inst.packet.source[5].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs6.valid = inst.packet.source[5].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs6.val = inst.packet.source[5].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs6.cluster = inst.packet.source[5].cluster;

				    /* source register 7 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rs7.regType = inst.packet.source[6].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rs7.reg = inst.packet.source[6].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rs7.valid = inst.packet.source[6].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rs7.val = inst.packet.source[6].value;
				    gTracePacket[i][j][k].bundle[bundlePos].rs7.cluster = inst.packet.source[6].cluster;

				    /* destination register 1 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rd1.regType = inst.packet.dest[0].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rd1.chk = inst.packet.dest[0].chk;
				    gTracePacket[i][j][k].bundle[bundlePos].rd1.reg = inst.packet.dest[0].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rd1.valid = inst.packet.dest[0].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rd1.cluster = inst.packet.dest[0].cluster;
				    gTracePacket[i][j][k].bundle[bundlePos].rd1.res = inst.packet.dest[0].res;

				    /* destination register 2 */
				    /*gTracePacket[i][j][k].bundle[bundlePos].rd2.regType = inst.packet.dest[1].target;*/
				    gTracePacket[i][j][k].bundle[bundlePos].rd2.chk = inst.packet.dest[1].chk;
				    gTracePacket[i][j][k].bundle[bundlePos].rd2.reg = inst.packet.dest[1].reg;
				    gTracePacket[i][j][k].bundle[bundlePos].rd2.valid = inst.packet.dest[1].valid;
				    gTracePacket[i][j][k].bundle[bundlePos].rd2.cluster = inst.packet.dest[1].cluster;
				    gTracePacket[i][j][k].bundle[bundlePos].rd2.res = inst.packet.dest[1].res;

				    bundlePos++;
#endif
				    if(inst.packet.newPCValid)
				      {
					hypercontext->programCounter = inst.packet.newPC;
					inst.packet.newPCValid = 0;
					/* TODO: add stalls for control flow change */
#ifndef INSIZZLEAPI
#ifdef NOSTALLS
					hypercontext->stallCount += PIPELINE_REFILL;
#else
					hypercontext->stalled += PIPELINE_REFILL;
#endif
#else
					hypercontext->stallCount += PIPELINE_REFILL;
#endif
#ifdef INSDEBUG
					printf("control flow change!\n");
#endif
					hypercontext->controlFlowChange++;
				      }
				    else
				      {
					hypercontext->programCounter = this.nextPC;
				      }

				    if(inst.packet.opcode == NOP)
				      {
					hypercontext->nopCount++;
				      }
#if 0
				    else {
				      /* set previous stall count to zero */
				      if(hypercontext->MemoryStall > 0) {
					hypercontext->MemoryStall--;
				      }
				    }
#endif
				  } while(!(this.op >> 31) & 0x1);
				}
			      /* TODO bundleCount */
			      bundleCountP = (unsigned long long *)((size_t)hypercontext->bundleCount + (bundleCount * (sizeof(unsigned long long))));
			      *bundleCountP = *bundleCountP + 1;

			      hypercontext->cycleCount++;
			    }
			  else if(deepstate == BLOCKED_MUTEX_LOCK)
			    printf("HC STATE: BLOCKED_MUTEX_LOCK\n");
			  else if(deepstate == TERMINATED_ASYNC_HOST)
			    {
			      /* TODO: this is the vthread_join thing */
#if 1
#ifdef INSDEBUG
			      printf("HC STATE: TERMINATED_ASYNC_HOST\n");
			      printf("\twaiting for: 0x%x\n", hypercontext->joinWaiting);
#endif
			      hypercontext->cycleCount++;
#endif
			    }
			  else if(deepstate == TERMINATED_ASYNC)
			    printf("HC STATE: TERMINATED_ASYNC\n");
			  else if(deepstate == TERMINATED_SYNC)
			    printf("HC STATE: TERMINATED_SYNC\n");
			  else
			    {
			      printf("HC STATE: UNKNOWN\n");
			      return -1;
			    }
			}
		    }
		}
Beispiel #9
0
/*--------------------------------- MAIN -------------------------------------*/
int main(int argc, char *argv[])
{
	int ret=0;
	gboolean control_only = FALSE;

	/*
   	* In order to register the reading end of the pipe with the event loop
   	* we must convert it into a GIOChannel.
   	*/
  	GIOChannel *g_signal_in;
  	long fd_flags; 	    /* used to change the pipe into non-blocking mode */
  	GError *error = NULL;	/* handle errors */

	/*print package name and version*/
	g_print("%s\n", PACKAGE_STRING);

	//g_type_init ();
	//gdk_threads_init();

#ifdef ENABLE_NLS
	char* lc_all = setlocale (LC_ALL, "");
	char* lc_dir = bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	char* txtdom = textdomain (GETTEXT_PACKAGE);
	const gchar * const * langs = g_get_language_names (); //get ordered list of defined languages
#endif
	/*structure containing all shared data - passed in callbacks*/
	struct ALL_DATA all_data;
	memset(&all_data,0,sizeof(struct ALL_DATA));

	/** initGlobals needs codecs registered
	 * so do it here
	 */
#if !LIBAVCODEC_VER_AT_LEAST(53,34)
	avcodec_init();
#endif
	// register all the codecs (you can also register only the codec
	//you wish to have smaller code)
	avcodec_register_all();
	
	/*allocate global variables*/
	global = g_new0(struct GLOBAL, 1);
	initGlobals(global);

	/*------------------------ reads command line options --------------------*/
	readOpts(argc,argv,global);

	/*------------------------- reads configuration file ---------------------*/
	readConf(global);

	//sets local control_only flag - prevents several initializations/allocations
	control_only = (global->control_only || global->add_ctrls) ;
    if(global->no_display && (global->control_only || !(global->exit_on_close && (global->Capture_time || global->image_timer))))
    {
        if(!(global->exit_on_close && (global->Capture_time || global->image_timer)))
            g_printerr("no_display must be used with exit_on_close and a timed capture: enabling display");
        else
            g_printerr("incompatible options (control_only and no_display): enabling display");
        global->no_display = FALSE;
    }

	/*---------------------------------- Allocations -------------------------*/

	gwidget = g_new0(struct GWIDGET, 1);
	gwidget->vid_widget_state = TRUE;

	/* widgets */
	GtkWidget *scroll1;
	GtkWidget *Tab1;
	GtkWidget *Tab1Label;
	GtkWidget *Tab1Icon;
	GtkWidget *ImgButton_Img;
	GtkWidget *VidButton_Img;
	GtkWidget *QButton_Img;
	GtkWidget *HButtonBox;


	s = g_new0(struct VidState, 1);

	if(!control_only) /*control_only exclusion (video and Audio) */
	{
		pdata = g_new0(struct paRecordData, 1);
		//pdata->maincontext = g_main_context_default();
		/*create mutex for sound buffers*/
		__INIT_MUTEX(__AMUTEX);

		/* Allocate the video Format struct */
		videoF = g_new0(struct VideoFormatData, 1);

		/*---------------------------- Start PortAudio API -----------------------*/
		if(global->debug) g_print("starting portaudio...\n");
		Pa_Initialize();
	}