Пример #1
0
Файл: main.c Проект: rzmz/GoSky
int main(int argc, char *argv[])
{

  int H,i;
  
  int para_R=0;
  int para_x=0;
  int para_y=0;
  int para_inte=0;
  char *fin=0;
  char *fout=0;
  char show_help=0;
  int isLoggingEnabled=0;

//Argumentide otsimine
  for(i=0; i<argc;i++){
	  if((strcmp(argv[i], "-R")==0) && ((i+1)<argc)){
  		  para_R=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-x")==0) && ((i+1)<argc)){
  		  para_x=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-y")==0) && ((i+1)<argc)){
  		  para_y=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-fin")==0) && ((i+1)<argc)){
  		fin=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-fout")==0) && ((i+1)<argc)){
  		fout=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-inte")==0) && ((i+1)<argc)){
  		para_inte=atoi(argv[i+1]);
  	  	  	  }
  	  else if((strcmp(argv[i], "-help")==0)){
  		show_help=1;
  	  	  }
  	  else if((strcmp(argv[i], "-log")==0)){
  		isLoggingEnabled=1;
  	  	  }
  	  else{
  		  //printf("Unknown parameter or missing argument: %s", argv[i]);
  	  	  }
  	  }

//Kui mõni argumentidest on olnud help, siis trüki see ja välju.
  if(show_help==1){
	  HELP();
	  return 0;
  	  }


//Kui Logimine on lubatud, siis tekitan logimise failid
  if(isLoggingEnabled){
  	init_error_log("ERROR.txt");
  	init_progress_log("PROGRESS.txt");
	}


/*
  printf("R %i\n", para_R);
  printf("x %i\n", para_x);
  printf("y %i\n", para_y);
  printf("intensity %i\n", para_inte);
  printf("Fin %s\n", fin);
  printf("Fout %s\n", fout);
*/

//Päris programm

  open_img(fin);
  
  //Antud funktsiooni sees toimub parameetrite korrigeerimine 
  DWPA_set_parameters(get_W(), get_H(), para_x, para_y, para_R, para_inte);
  //DWPA_set_parameters(get_W(), get_H(), para_R, 1 );
  H=DWPA_get_img_size();
  create_map(H, H);
  generate_image_from_map(fout);

  char str_msg[1024];
  sprintf(str_msg, "%s -> %s\n", fin, fout);
  write_progress_log(str_msg);

  close_error_log();
  close_progress_log();
  return 0;
}
Пример #2
0
/* server_main()
 * -> sb_run_* APIs are enabled
 * -> all registries are enabled
 * -> all configs are enabled. config should follow and overwrite registry.
 */
int server_main()
{
	module *mod=NULL;

  /***********************************************************************
   * first-pass config 
   */

	set_proc_desc(NULL, "softbotd: master - loading static modules");
	/* load_static_modules()
	 *  -> hooking APIs. we cannot call sb_run_* APIs before this
	 */
	load_static_modules();

    /* FIXME why should i load kbo module?? */
	//load_kbo_module();

	if (read_config(mConfigFile, NULL) != SUCCESS) {
		crit("failed to read config file");
		exit(1);
	}
	/* 1. load dynamic modules -> make linked list of whole modules
	 * 2. setup each modules's configuration -> call each config function
	 */

	open_error_log(gErrorLogFile, gQueryLogFile);
#ifdef USE_TIMELOG
    if(sb_tstat_log_init(mTimeLogFile) != SUCCESS) {
        exit(1);
    }
#endif

	save_pid(mPidFile);

	load_dynamic_modules();
  /***********************************************************************
   * all the modules has been loaded.
   */

	sb_sort_hook();

	load_each_registry();
	/* 1. register each module to registry
	 * 2. do the shared memory related stuff...
	 * 3. XXX registry module does not guarantee shared memory locking...
	 */

	restore_registry_file(gRegistryFile);

	/* TODO second-pass config */

  /***********************************************************************
   * runtime configuration is done.
   */
	init_all_scoreboards();

	/* method 3 of doc/README.init */
	set_proc_desc(NULL, "softbotd: master - init each module");
	if ( init_core_modules(first_module) != SUCCESS ) goto STOP;
	if ( init_standard_modules(first_module) != SUCCESS ) goto STOP;

	if (clc_listen_port >= 2) { /* show using ports */
		show_portinfo();
		goto STOP;
	}
	set_proc_desc(NULL, "softbotd: master - spawning child");
	/* check debug_module */
	if ( strlen(debug_module) > 0 ) {
		mod = find_module(debug_module);
		if ( mod == NULL ) {
			error("no such module [%s]", debug_module);
			return FAIL;
		}
		else {
			info("debugging module [%s]", debug_module);
			// XXX: in debugging mode, isn't it better not to fork? is it?
			if (mod->main) 
				sb_run_spawn_process_for_module(scoreboard, mod);
			else {
				error("module[%s] has no main",debug_module);
				exit(1);
			}
		}
	}
	else if (unittest) {
		crit("unittesting started");
		do_unittest();
		crit("unittesting ended");
		goto STOP;
	}
	else
		sb_run_spawn_processes_for_each_module(scoreboard, first_module);

	CRIT("*** master monitoring loop ***");
	setproctitle("softbotd: master - monitoring");
	set_proc_desc(NULL, "softbotd: master - monitoring");
	scoreboard->period = CHILD_MONITORING_PERIOD;
	sb_run_monitor_processes_for_modules(scoreboard, first_module);

  /***********************************************************************
   * stopping state.
   */
STOP:	
	if ( save_registry_file(gRegistryFile) != SUCCESS )
		error("save_registry_file(%s) failed: %s",
			gRegistryFile, strerror(errno));
	free_ipcs(); /* release shared memory and semaphore */
	close_error_log(); /* close error_log file and semaphore */

#ifdef USE_TIMELOG
    sb_tstat_log_destroy();
#endif

	return SUCCESS;
}