示例#1
0
int main(int argc, char** args) {
    pthread_t thread1;
    pthread_t thread2;
    pthread_attr_t attr;
    char* job1 = "job1.axy";
    char* job2 = "job2.axy";

    fits_use_error_system();
    
    log_init(LOG_VERB);
    log_set_thread_specific();

	logverb("Hello world!\n");

    be = engine_new();
    engine_parse_config_file(be, "astrometry.cfg");

    pthread_mutex_init(&read_job_mutex, NULL);

    pthread_attr_init(&attr);
    pthread_create(&thread1, &attr, threadfunc, job1);
    pthread_create(&thread2, &attr, threadfunc, job2);

    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    pthread_mutex_destroy(&read_job_mutex);

    engine_free(be);

    return 0;
}
示例#2
0
int main(int argc,char **argv){
	signal(SIGPIPE,SIG_IGN);
	e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]));
	uint32_t size = atoi(argv[3]);
	uint32_t i = 0;
	for( ; i < size; ++i){
		int32_t fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
		easy_noblock(fd,1);
		int32_t ret;
		if(0 == (ret = easy_connect(fd,&server,NULL)))
			on_connected(fd,0,e);
		else if(ret == -EINPROGRESS){
			connector *c = connector_new(fd,e,2000);
			engine_associate(e,c,on_connected);			
		}else{
			close(fd);
			printf("connect to %s %d error\n",argv[1],atoi(argv[2]));
		}
	}
	//engine_regtimer(e,1000,timer_callback,NULL);
	engine_run(e);
	return 0;
}
示例#3
0
/*******************************
 * Engine test functions
 *******************************/ 
void test_engine(void) {
    GraphicControls* controls = NULL;
    const char* modDir = NULL;
    const char* const* names = NULL;
    unsigned int namesNum = 0;
    size_t i = 0;
    Engine* engine = NULL;
    const char* configPath = NULL;
    const char* setupPath = NULL;
    const char* modulesPath = NULL;
    const char* config = "test.cfg";
    const char* setup = "test.cfg";

    modDir = ".";

    /* initialize an empty graphic controls structure */
    controls = g_new0(GraphicControls, 1);
    controls->mainControl = NULL;
    controls->configControl = NULL;
    controls->setupControl = NULL;
    controls->testControl = NULL;

    /* initialization without debug and demo flags */
    g_print("Initialize the engine...\n\r");
    engine = engine_new(controls, NORMAL_MODE, "config", "setup", modDir);
    
    g_print("The number of loaded modules is %i\n\r", engine_get_modules_num(engine));
    names = engine_get_modules_names(engine, &namesNum);

    for (i = 0; i < namesNum; i++) {
        g_print("Loaded module: '%s'\n\r", names[i]);
    }

    /* check mode */
    engine_set_config_path(engine, config);
    engine_set_setup_path(engine, setup);
    engine_set_modules_dir(engine, modDir);

    configPath = engine_get_config_path(engine);
    setupPath = engine_get_setup_path(engine);
    modulesPath = engine_get_modules_dir(engine);

    g_print("The paths are the following ones:\n\r");
    g_print("config = %s, setup = %s, modules = %s\n\r", configPath, setupPath, modulesPath);

    /* close the engine */
    g_print("Release engine resources..\n\r");
    engine_free(engine);
}
示例#4
0
int main(int argc,char **argv){
	test_parse("*2\r");
	test_parse("\n$53\r\nfasdfasdffasdfasdfasdfasdfasdfasfasdffasfsdffasdfadfs\r\n$36\r\nfasfsadfasdfsdafasdfasdfasdfsdafsadf\r\n");

	test_parse("$5\r");
	test_parse("\nhello\r");
	test_parse("\n");

	test_parse(":");
	test_parse("10\r");
	test_parse("\n");

	test_parse("");
	test_parse("+ok haha\r");
	test_parse("\n");				

	char  input[65535];
	char *ptr;

	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,"127.0.0.1",6379);
	redis_client = redis_connect(e,&server,on_disconnect);
	if(!redis_client){
		printf("connect to redis server %s:%u error\n",argv[1],atoi(argv[2]));
		return 0;
	}

	redis_execute(redis_client,"set kenny h\r\nha",cmd_callback,NULL);

	do{
	    ptr = input;	
	    while((*ptr = getchar()) != '\n')
	    	++ptr;
	    *ptr = 0;
	    flag = 1;
	    redis_execute(redis_client,input,cmd_callback,NULL);
	    while(flag && redis_client){
	    	engine_runonce(e,10);
	    };
		if(!redis_client)
			return 0;
	}while(1);
	return 0;
}
示例#5
0
int main(int argc,char **argv){
	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	if(0 != easy_sockaddr_ip4(&server,argv[1],atoi(argv[2]))){
		printf("invaild address:%s\n",argv[1]);
	}
	int32_t fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
	easy_addr_reuse(fd,1);
	if(0 == easy_bind(fd,&server)){
		dgram_socket_ *udpserver = new_datagram_socket(fd); 
		engine_associate(e,udpserver,datagram_callback);
		datagram_socket_recv(udpserver,(iorequest*)new_request(),IO_POST,NULL);
		engine_regtimer(e,1000,timer_callback,NULL);
		engine_run(e);
	}
	return 0;
}
示例#6
0
int main(int argc,char **argv){

	if(argc < 2){
		printf("useage redis_streass set/get\n");
		exit(0);
	}

	int i;
	int testset = 0;
	signal(SIGPIPE,SIG_IGN);
	engine *e = engine_new();
	sockaddr_ server;
	easy_sockaddr_ip4(&server,"127.0.0.1",6379);
	redis_conn *redis_client = redis_connect(e,&server,on_disconnect);
	if(!redis_client){
		printf("connect to redis server %s:%u error\n","127.0.0.1",6379);
		return 0;
	}

	if(argc >= 2 && strcmp(argv[1],"set") == 0)
		testset = 1;
	for(i = 0; i < 1000; ++i){		
		char buff[1024];
		if(!testset){
			//snprintf(buff,1024,"hmget chaid:%d chainfo skills",i + 1);
			int tmp = i + 1;
			redis_execute(redis_client,"hmget chaid:1 chainfo skills",cmd_callback,(void*)tmp);
		}else{
			snprintf(buff,1024,"hmset chaid:%d chainfo %s skills %s",
					 i + 1,"fasfsafasfsaf\rasfasfasdfsadfasdfasdfasfdfasdfasfdasdfasdf",
					 "fasdfasfasdfdsafdsafs\nadfsafa\r\nsdfsadfsadfasdfsadfsdafsdafsadfsdf" 
					);
			redis_execute(redis_client,buff,NULL,NULL);
		}
	}
	engine_regtimer(e,1000,timer_callback,NULL);
	last = systick64();
	engine_run(e);

	return 0;
}
int main(int argc, char** args) {
    char* default_configfn = "astrometry.cfg";
    char* default_config_path = "../etc";

	int c;
	char* configfn = NULL;
	int i;
	engine_t* engine;
    char* mydir = NULL;
    char* basedir = NULL;
    char* me;
    anbool help = FALSE;
    sl* strings = sl_new(4);
    char* cancelfn = NULL;
    char* solvedfn = NULL;
    int loglvl = LOG_MSG;
    anbool tostderr = FALSE;
    char* infn = NULL;
    FILE* fin = NULL;
    anbool fromstdin = FALSE;

	bl* opts = opts_from_array(myopts, sizeof(myopts)/sizeof(an_option_t), NULL);
	sl* inds = sl_new(4);

	char* datalog = NULL;

	engine = engine_new();

	while (1) {
		c = opts_getopt(opts, argc, args);
		if (c == -1)
			break;
		switch (c) {
		case 'D':
			datalog = optarg;
			break;
		case 'p':
			engine->inparallel = TRUE;
			break;
		case 'i':
			sl_append(inds, optarg);
			break;
		case 'd':
		  basedir = optarg;
		  break;
        case 'f':
            infn = optarg;
            fromstdin = streq(infn, "-");
            break;
        case 'E':
            tostderr = TRUE;
            break;
		case 'h':
            help = TRUE;
			break;
        case 'v':
            loglvl++;
            break;
		case 's':
		  solvedfn = optarg;
        case 'C':
            cancelfn = optarg;
            break;
		case 'c':
			configfn = strdup(optarg);
			break;
		case '?':
			break;
		default:
            printf("Unknown flag %c\n", c);
			exit( -1);
		}
	}

	if (optind == argc && !infn) {
		// Need extra args: filename
		printf("You must specify at least one input file!\n\n");
		help = TRUE;
	}
	if (help) {
		print_help(args[0], opts);
		exit(0);
	}
	bl_free(opts);

	gslutils_use_error_system();

    log_init(loglvl);
    if (tostderr)
        log_to(stderr);

	if (datalog) {
		datalogfid = fopen(datalog, "wb");
		if (!datalogfid) {
			SYSERROR("Failed to open data log file \"%s\" for writing", datalog);
			return -1;
		}
		atexit(close_datalogfid);
		data_log_init(100);
		data_log_enable_all();
		data_log_to(datalogfid);
		data_log_start();
	}

    if (infn) {
        logverb("Reading input filenames from %s\n", (fromstdin ? "stdin" : infn));
        if (!fromstdin) {
            fin = fopen(infn, "rb");
            if (!fin) {
                ERROR("Failed to open file %s for reading input filenames", infn);
                exit(-1);
            }
        } else
            fin = stdin;
    }

    // directory containing the 'engine' executable:
    me = find_executable(args[0], NULL);
    if (!me)
        me = strdup(args[0]);
    mydir = sl_append(strings, dirname(me));
    free(me);

	// Read config file
    if (!configfn) {
        int i;
        sl* trycf = sl_new(4);
        sl_appendf(trycf, "%s/%s/%s", mydir, default_config_path, default_configfn);
        // if I'm in /usr/bin, look for config file in /etc
        if (streq(mydir, "/usr/bin")) {
            sl_appendf(trycf, "/etc/%s", default_configfn);
        }
        sl_appendf(trycf, "%s/%s", mydir, default_configfn);
        sl_appendf(trycf, "./%s", default_configfn);
        sl_appendf(trycf, "./%s/%s", default_config_path, default_configfn);
        for (i=0; i<sl_size(trycf); i++) {
            char* cf = sl_get(trycf, i);
            if (file_exists(cf)) {
                configfn = strdup(cf);
                logverb("Using config file \"%s\"\n", cf);
                break;
            } else {
                logverb("Config file \"%s\" doesn't exist.\n", cf);
            }
        }
        if (!configfn) {
            char* cflist = sl_join(trycf, "\n  ");
            logerr("Couldn't find config file: tried:\n  %s\n", cflist);
            free(cflist);
        }
        sl_free2(trycf);
    }

	if (!streq(configfn, "none")) {
		if (engine_parse_config_file(engine, configfn)) {
			logerr("Failed to parse (or encountered an error while interpreting) config file \"%s\"\n", configfn);
			exit( -1);
		}
	}

	if (sl_size(inds)) {
		// Expand globs.
		for (i=0; i<sl_size(inds); i++) {
			char* s = sl_get(inds, i);
			glob_t myglob;
			int flags = GLOB_TILDE | GLOB_BRACE;
			if (glob(s, flags, NULL, &myglob)) {
				SYSERROR("Failed to expand wildcards in index-file path \"%s\"", s);
				exit(-1);
			}
			for (c=0; c<myglob.gl_pathc; c++) {
				if (engine_add_index(engine, myglob.gl_pathv[c])) {
					ERROR("Failed to add index \"%s\"", myglob.gl_pathv[c]);
					exit(-1);
				}
			}
			globfree(&myglob);
		}
	}

	if (!pl_size(engine->indexes)) {
		logerr("\n\n"
			   "---------------------------------------------------------------------\n"
			   "You must list at least one index in the config file (%s)\n\n"
			   "See http://astrometry.net/use.html about how to get some index files.\n"
			   "---------------------------------------------------------------------\n"
			   "\n", configfn);
		exit(-1);
	}

	if (engine->minwidth <= 0.0 || engine->maxwidth <= 0.0) {
		logerr("\"minwidth\" and \"maxwidth\" in the config file %s must be positive!\n", configfn);
		exit(-1);
	}

    free(configfn);

    if (!il_size(engine->default_depths)) {
        parse_depth_string(engine->default_depths,
                           "10 20 30 40 50 60 70 80 90 100 "
                           "110 120 130 140 150 160 170 180 190 200");
    }

    engine->cancelfn = cancelfn;
    engine->solvedfn = solvedfn;

    i = optind;
    while (1) {
		char* jobfn;
        job_t* job;
		struct timeval tv1, tv2;

        if (infn) {
            // Read name of next input file to be read.
            logverb("\nWaiting for next input filename...\n");
            jobfn = read_string_terminated(fin, "\n\r\0", 3, FALSE);
            if (strlen(jobfn) == 0)
                break;
        } else {
            if (i == argc)
                break;
            jobfn = args[i];
            i++;
        }
        gettimeofday(&tv1, NULL);
        logmsg("Reading file \"%s\"...\n", jobfn);
        job = engine_read_job_file(engine, jobfn);
        if (!job) {
            ERROR("Failed to read job file \"%s\"", jobfn);
            exit(-1);
        }

	if (basedir) {
	  logverb("Setting job's output base directory to %s\n", basedir);
	  job_set_output_base_dir(job, basedir);
	}

		if (engine_run_job(engine, job))
			logerr("Failed to run_job()\n");

		job_free(job);
        gettimeofday(&tv2, NULL);
		logverb("Spent %g seconds on this field.\n", millis_between(&tv1, &tv2)/1000.0);
	}

	engine_free(engine);
    sl_free2(strings);
	sl_free2(inds);

    if (fin && !fromstdin)
        fclose(fin);

    return 0;
}
示例#8
0
int main()
{
    char input[16];
    int done = 0, state;

    if (!engine_init())
        return 1;
    init_states();

    while (!done)
    {
        state = read_keyword(input, sizeof(input));
        if (state == 0)
            break;
        if (state == STATE_ERROR)
            continue;
        
        //fprintf(stderr, "cmd %s state %d\n", input, state);


        switch (state)
        {
        case STATE_BLACK:
            engine_set_color(BLACK);
            break;
        case STATE_WHITE:
            engine_set_color(WHITE);
            break;
        case STATE_CGCBOARD:
            write_string("\n");
            break;
        case STATE_DRAW:
            engine_offer_draw();
            break;
        case STATE_FORCE:
            engine_set_go(0);
            break;
        case STATE_GO:
            engine_set_go(1);
            break;
        case STATE_NEW:
            engine_new();
            break;
        case STATE_RANDOM:
            engine_set_random(!engine_get_random());
            break;
        case STATE_RESULT:
            if (!handle_result())
                done = 1;
            break;
        case STATE_REMOVE:
            engine_undo();
            engine_undo();
            break;
        case STATE_QUIT:
            write_string("bye\n");
            done = 1;
            break;
        case STATE_SD:
            if (!handle_sd())
                done = 1;
            break;
        case STATE_UNDO:
            engine_undo();
            break;
        case STATE_MOVE:
            engine_move(str_to_move(input));
            break;
        case STATE_PLAY:
            engine_go();
            break;
        }
    }

    engine_destroy();

    return 0;
}