Ejemplo n.º 1
0
void
WRATHTripleBufferEnabler::
signal_begin_presentation_frame(void)
{

    WRATHLockMutex(m_phase_mutex);
    m_phase2.splice(m_phase2.end(), m_phase1);
    WRATHUnlockMutex(m_phase_mutex);

    fire_signal(m_sigs[on_begin_presentation_frame][pre_update_no_lock]);

    WRATHLockMutex(m_mutex);
    fire_signal(m_sigs[on_begin_presentation_frame][pre_update_lock]);

    m_present_ID=m_last_simulation_ID;

    WRATHassert(m_current_simulation_ID!=m_last_simulation_ID);
    WRATHassert(m_current_simulation_ID!=m_present_ID);




    fire_signal(m_sigs[on_begin_presentation_frame][post_update_lock]);

    WRATHUnlockMutex(m_mutex);
    fire_signal(m_sigs[on_begin_presentation_frame][post_update_no_lock]);
    do_actions(m_render_actions, m_render_actions_mutex);

    {
        WRATHAutoLockMutex(m_counter_lock);
        ++m_number_begin_presentation_frame_calls;
        ++m_number_begin_presentation_calls_since_last_simulation_complete_frame;
        m_number_complete_simulation_calls_since_last_begin_presentation_frame=0;
    }
}
Ejemplo n.º 2
0
int
main (int argc, char *argv[])
{
        struct state state = {0, };

        state.need_op_write = 1;
        state.need_op_read = 1;

        state.need_iface_fileio = 1;
        state.need_iface_xattr = 0;

        state.need_mode_posix = 1;

        state.block_size = 4096;

        strcpy (state.prefix, "tmpfile");
        state.count = 1048576;

        if (argp_parse (&argp, argc, argv, 0, 0, &state) != 0) {
                fprintf (stderr, "argp_parse() failed\n");
                return 1;
        }

        do_actions (&state);

        return 0;
}
Ejemplo n.º 3
0
void			game(t_env *env)
{
  while (stop == 42)
    {
      init_fds(env);
      do_select(env);
      check_fds(env);
      apply_timers(env);
      do_actions(env);
    }
}
Ejemplo n.º 4
0
void check_turn_ready() {
    if (current_turn && !check_gameover(0)) {
        if (recv_all_actions(current_turn)) {
            if ((queued_screen == GAME_SCREEN_WORLD && !door_dir) || screen == GAME_SCREEN_WORLD) {
                if (server) {
                    do_ai();		/*	computer players select their actions	*/
                    send_ai_actions();
                    server_prepare_actions();
                }
                do_actions();
                current_turn++;
            }
        }
    }
}
Ejemplo n.º 5
0
uint8_t check_events(event_ref * e_ptr) {
	event_ref e_cur = *e_ptr;
	event_ref e_prev = 0;
	uint8_t triggered_events = 0;

	while(e_cur) { // For each event
		if (check_actions(e_cur->check_list)) { //Check the event
			do_actions(e_cur->actions_list);
			triggered_events++;
			if(e_cur->repeat_mode == REPEAT_FOREVER) {
				e_prev = e_cur;
				e_cur = e_cur->next_event;
				continue;
			}
			if(e_cur->repeat_mode == REPEAT_LIMITED) {
				e_cur->repeat_count++;
				if (e_cur->repeat_count >= e_cur->max_repetitions) {
					//repeated too many times, have to delete it
					e_cur = e_cur->next_event; //first move to the next
					if (e_prev) {
						//It was not the first event, go back one to get the pointer
						event_delete(&e_prev->next_event);
					} else {
						//This was the first event, so just use the pointer we were given.
						event_delete(e_ptr);
					}
					continue;
				}
			}
			if(e_cur->repeat_mode == NO_REPEAT) {
				//have to delete it
				e_cur = e_cur->next_event; //first move to the next
				if (e_prev) {
					//It was not the first event, go back one to get the pointer
					event_delete(&e_prev->next_event);
				} else {
					//This was the first event, so just use the pointer we were given.
					event_delete(e_ptr);
				}
				continue;
			}
		}
		e_prev = e_cur;
		e_cur = e_cur->next_event;
	}
	return triggered_events;
}
Ejemplo n.º 6
0
void MC::one_iteration()
{
    m_success = true;
    ++m_niter;
    ++m_nitercount;

    m_trial_coords.assign(m_coords);

    // take a step with the trial coords
    //_takestep->takestep(_trial_coords, _stepsize, this);
    take_steps();

    // perform the initial configuration tests
    m_success = do_conf_tests(m_trial_coords);

    // if the trial configuration is OK, compute the energy, and run the acceptance tests
    if (m_success) {
        // compute the energy
        m_trial_energy = compute_energy(m_trial_coords);

        // perform the acceptance tests.  Stop as soon as one of them fails
        m_success = do_accept_tests(m_trial_coords, m_trial_energy, m_coords, m_energy);
    }

    // Do some final checks to ensure the configuration is OK.
    // These come last because they might be computationally demanding.
    if (m_success) {
        m_success = do_late_conf_tests(m_trial_coords);
    }

    // adapt stepsize etc.
    if (get_iterations_count() <= m_report_steps) {
        m_take_step->report(m_coords, m_energy, m_trial_coords, m_trial_energy, m_success, this);
    }

    // if the step is accepted, copy the coordinates and energy
    if (m_success) {
        m_coords.assign(m_trial_coords);
        m_energy = m_trial_energy;
        ++m_accept_count;
    }

    // perform the actions on the new configuration
    do_actions(m_coords, m_energy, m_success);
}
Ejemplo n.º 7
0
int main()
{
	if(read_config_files(&cf)== -1)
	{
		printf("\nError in reading config files");
		exit(0);
	}
//---declare variable of program----//
	
	int listen_sd, accept_sd;
	struct sockaddr_in addr;  
	int i;
 
//--------------load action record from file-----------------------//
	int numberofac;
	char *filename = cf.action_record;
	ActionRecord *ac;
	ac = ReadOutputFile(filename,&numberofac);
	if(ac == NULL)
	{
		printf("\nCannot read action record file");
		return 0;

	}
	//sort the array with the action's starting time
	SortActionArray(ac,numberofac);
	printf("\nnumber of action record:%d",numberofac);

	
//-------------load action mapping file------------------------//
	char *action_mapping_file = cf.action_mapping;
	action_mapping *ap ;
	int numberofap =0;
	ap = read_action_mapping_file(action_mapping_file,&numberofap);
	if(ap == NULL)
	{
		printf("\nCannot read action mapping file");
		return 0;

	}
	action_mapping *temp;
	temp = ap;
	while(temp!=NULL)
	{
		print_action_mapping(temp);
		temp=temp->next;
	}

		
	
	

//-------------------------------load setting file ---------------//

	char *setting_file = cf.setting_file;
	id_ip *ID_IP;
	int numberofnode;
	ID_IP =  read_setting_file(setting_file,&numberofnode);
	if(ID_IP == NULL)
	{
		printf("\nCannot read setting file");
		return 0;
	}
	printf("\nnumber of node in setting file:%d\n",numberofnode);
	

//------------INIT main process to control child processes----------------//

	main_process_init();

//--------------INIT server for listening the time value from QOMET-------//
    /* If an argument was specified, use it to */
    /* control the number of incoming connections */
     listen_sd = InitTCPServer(SERVER_PORT);
	if(listen_sd < 1)
	{
		fprintf(stderr,"Server cannot init");
		return 0;
	}

//--------------------------main loop----------------------//
	
	do_actions(listen_sd,ac,numberofac,ap,ID_IP);

//------------------------close program--------------------//
    /* Close the listen socket */
    close(listen_sd);
	//kill all child processes//
	kill_all_processes(main_p->pgid);
	//wait for close main process//
	wait_to_close();
    return 0;
//--------------close program in bad cases-----------------------//
bad_main:
	printf("\nclose do action program\n");
	close(listen_sd);
	close(accept_sd);
	kill_all_processes(main_p->pgid);
	exit(-1);
}
Ejemplo n.º 8
0
int oversight_main(int argc,char **argv,int send_content_type_header)
{
    int result=0;
    int done=0;

    g_start_clock = time(NULL);
    assert(sizeof(long long) >= 8);

    init_view();
    adjust_path();

    char *q=getenv("QUERY_STRING");
    char *sp=getenv("SCRIPT_NAME");

    char *p;
    char *req;
    if (q && (p = delimited_substring(q,"&",REMOTE_VOD_PREFIX2,"=",1,0)) != NULL) {

        gaya_auto_load(p+strlen(REMOTE_VOD_PREFIX2)+1);
        done=1;

    } else if (q && strstr(q,YAMJ_PREFIX2)) {

        g_query=parse_query_string(q,g_query);
        //req = url_decode(q+strlen(YAMJ_PREFIX2));
        req = url_decode(query_val("yamj"));
        yamj_xml(req);
        FREE(req);
        done=1;
    } else if (sp && (req=strstr(sp,YAMJ_PREFIX)) != NULL) {
        // If oversight script is launched as /oversight/yamj/xxxxx.xml
        // then use xxxxxx.xml as a yamj xml request.
        // This is to allow for Apache ModAlias to serve static images whilst calling oversight for CGI
        // The rewrite rules should be 
        //    ScriptAliasMatch ^/oversight/yamj/(.*).xml  /share/Apps/oversight/oversight.cgi
        //    AliasMatch ^/oversight/yamj/banner_(.*jpg) /oversight/db/global/_b/ovs_$1
        //    AliasMatch ^/oversight/yamj/fanart_(.*jpg) /oversight/db/global/_fa/ovs_$1
        //    AliasMatch ^/oversight/yamj/poster_(.*jpg) /oversight/db/global/_J/ovs_$1
        //    AliasMatch ^/oversight/yamj/thumb_(.*).jpg  /oversight/db/global/_J/ovs_$1.thumb.jpg
        //    AliasMatch ^/oversight/yamj/boxset_(.*).jpg  /oversight/db/global/_J/ovs_$1.thumb.boxset.jpg`
        //
        req += strlen(YAMJ_PREFIX);
        yamj_xml(req);
        done=1;

    } else if (q == NULL || strchr(q,'=') == NULL ) {

        if (argc > 1 ) {

            if ( argv[1] && *argv[1] && argv[2] == NULL && util_starts_with(argv[1],YAMJ_PREFIX) ) {
                char *req = url_decode(argv[1]+strlen(YAMJ_PREFIX));
                yamj_xml(req);
                FREE(req);
                done=1;

            } else if ( argv[1] && *argv[1] && argv[2] == NULL && strchr(argv[1],'=') == NULL) {
                // Single argument passed.
                //
                char *path = url_decode(argv[1]);
                char *dot = strrchr(path,'.');
                if (dot < path) dot = strchr(path,'\0');
                int result = 0;

                fprintf(stderr,"path=[%s]",path);

                // should really use file command or magic number to determine file type

                if (dot && STRCMP(dot,".png") == 0 ) {

                    result = cat(CONTENT_TYPE"image/png",path);

                } else if (dot &&  STRCMP(dot,".jpg") == 0 ) {

                    result = cat(CONTENT_TYPE"image/jpeg",path);

                } else if (dot &&  STRCMP(dot,".gif") == 0) {

                    result = cat(CONTENT_TYPE"image/gif",path);

                } else if (dot &&  (STRCMP(dot,".swf") == 0 || STRCMP(dot,".phf" ) == 0) ) {

                    result = cat(CONTENT_TYPE"application/x-shockwave-flash",path);

                } else if (browsing_from_lan() ) {

                    if (is_dir(path)) {

                        // load_configs(); // load configs so we can use file_to_url() functions 
                        result = ls(path);
                    } else {
                        int exists = is_file(path);

                        char *all_headers = NULL;
                        char *content_headers = NULL;

                        if (exists) {
                            if (strstr(path,".tar.gz") || strcmp(dot,".tgz") == 0) {

                                ovs_asprintf(&content_headers,"%s%s\n%s%s",
                                        CONTENT_TYPE,"application/x-tar",CONTENT_ENC,"gzip");

                            } else if (strcmp(dot,".gz") == 0 ) {

                                ovs_asprintf(&content_headers,"%s%s\n%s%s",
                                        CONTENT_TYPE,"application/x-gzip",CONTENT_ENC,"identity");

                            } else if (strcmp(dot,".html") == 0 ) {

                                ovs_asprintf(&content_headers,"%s%s",
                                        CONTENT_TYPE,"text/html;charset=utf-8");

                            } else {
                                ovs_asprintf(&content_headers,"%s%s",
                                        CONTENT_TYPE,"text/plain;charset=utf-8");
                            }
                        } else {
                            // .gz.txt is a fake extension added by the ls command to view log.gz inline without browser downloading.
                            if (strstr(path,".gz.txt")) {
                                ovs_asprintf(&content_headers,"%s%s\n%s%s",
                                        CONTENT_TYPE,"text/plain;charset=utf-8", CONTENT_ENC,"gzip");
                                // remove .txt to get real zip file.
                                // .txt is needed so a certain browser displays inline. (might be other ways)
                                *dot = '\0';
                            } else {
                                // 404 error would be here
                            }
                        }
                        ovs_asprintf(&all_headers,"%s\n%s%ld",content_headers,CONTENT_LENGTH,file_size(path));
                        FREE(content_headers);
                        result = cat(all_headers,path);
                        FREE(all_headers);

                    }
                }
                FREE(path);
                fflush(stdout);
                done=1;
            }
        }
    }



    if (!done) {
        if (send_content_type_header) {
            printf("Content-Type: text/html; charset=utf-8\n\n");

            start_page("CGI");
        } else {
            start_page("WGET");
        }

        html_log_level_set(2);

        load_configs();
        //html_hashtable_dump(0,"settings",g_nmt_settings);

        long log_level;
        if (config_check_long(g_oversight_config,"ovs_log_level",&log_level)) {
            html_log_level_set(log_level);
        }

        html_comment("Appdir= [%s]",appDir());

        //array_unittest();
        //util_unittest();
        //config_unittest();

        g_query = string_string_hashtable("g_query2",16);

        html_comment("default query ... ");
        add_default_html_parameters(g_query);
        html_hashtable_dump(0,"prequery",g_query);

        html_comment("read query ... ");
        g_query=parse_query_string(getenv("QUERY_STRING"),g_query);
        html_hashtable_dump(0,"query",g_query);

        html_comment("read post ... ");

        struct hashtable *post=read_post_data(getenv("TEMP_FILE"));
        html_hashtable_dump(0,"post",g_query);
        
        html_comment("merge query and post data");
        merge_hashtables(g_query,post,1); // post is destroyed

        html_hashtable_dump(0,"query final",g_query);


#if 0
        html_comment("utf8len expect 2 = %d",utf8len("a"));
        html_comment("utf8len expect 2 = %d",utf8len("à€€a"));
        html_comment("utf8len expect 2 = %d",utf8len("ü€€€€€a"));
        html_comment("utf8cmp_char 0 = %d",utf8cmp_char("ü€€€€€a","ü€€€€€b"));
        html_comment("utf8cmp_char !0 = %d",utf8cmp_char("ü€€€€€a","ü€€€€€a"));
        html_comment("utf8cmp_char 0 = %d",utf8cmp_char("a","a"));
        html_comment("utf8cmp_char !0 = %d",utf8cmp_char("a","b"));
        html_comment("utf8cmp_char !0 = %d",utf8cmp_char("ü€€€€€a","üa"));
        html_comment("utf8cmp_char !0 = %d",utf8cmp_char("a","ü€€€€€a"));
        Abet *a = abet_create("abcdefghijklmnopqrstuvwxyz");
        html_comment("inc a %d",abet_letter_inc_or_add(a,"a",1));
        html_comment("inc a %d",abet_letter_inc_or_add(a,"a",1));
        html_comment("inc z %d",abet_letter_inc_or_add(a,"z",1));
        html_comment("inc 4 %d",abet_letter_inc_or_add(a,"4",1));
        html_comment("inc 5 %d",abet_letter_inc_or_add(a,"5",1));
        html_comment("inc 5 %d",abet_letter_inc_or_add(a,"5",1));
        html_comment("inc 6* %d",abet_letter_inc_or_add(a,"6",0));
        html_comment("inc 7* %d",abet_letter_inc_or_add(a,"7",0));
        html_comment("inc a %d",abet_letter_inc_or_add(a,"a",1));
        abet_free(a);
#endif


        config_read_dimensions(1);

        HTML_LOG(0,"Begin Actions");
        do_actions();
       
        ViewMode *view;

        DbSortedRows *sortedRows = NULL;


        while(1) {
            view=get_view_mode(1);  
            HTML_LOG(0,"view mode = [%s]",view->name);

            // If movie view but all ids have been removed , then move up
            if (view == VIEW_MOVIE && !*query_val(QUERY_PARAM_IDLIST)) {
                query_pop();
                view=get_view_mode(1);  
            }

            sortedRows = get_sorted_rows_from_params();
            dump_all_rows("sorted",sortedRows->num_rows,sortedRows->rows);

            // If it's not a tv/movie detail or boxset view then break
            if (view == VIEW_MENU ||  view == VIEW_ADMIN ) {
                break;
            }

            // Found some data - as we are on a smaller view - filter it
            if (sortedRows->num_rows && sortedRows->num_rows < 50 ) {
                int new_num = sortedRows->num_rows;
                int max_new = sortedRows->num_rows;
                DbItem **new_list = filter_page_items(0,sortedRows->num_rows,sortedRows->rows,max_new,&new_num);
                FREE(sortedRows->rows);
                sortedRows->rows = new_list;
                sortedRows->num_rows=new_num;
            }
            if (sortedRows->num_rows) break;

            // No data found in this view - try to return to the previous view.
            query_pop();
            // Adjust config - 
            // TODO Change the config structure to reload more efficiently.
            //reload_configs();

            config_read_dimensions(1);

            // Now refetch all data again with new parameters.
            sorted_rows_free_all(sortedRows);
            HTML_LOG(0,"reparsing database");
        }

        // Remove and store the last navigation cell. eg if user clicked on cell 12 this is passed in 
        // the URL as @i=12. The url that returns to this page then has i=12. If we have returned to this
        // page we must remove i=12 from the query so that it is not passed to the new urls created for this 
        // page.
        set_selected_item();

        char *skin_name=get_skin_name();


        if (strchr(skin_name,'/') || *skin_name == '.' || !*skin_name ) {

            html_error("Invalid skin name[%s]",skin_name);

        } else {

            playlist_open();
            //exp_test();

            if (view->view_class == VIEW_CLASS_ADMIN) {

                setPermissions();
                display_admin(sortedRows);

            } else {

                char *template = query_val(QUERY_PARAM_TEMPLATE_NAME);
                if (EMPTY_STR(template)) {
Ejemplo n.º 9
0
void
WRATHTripleBufferEnabler::
signal_complete_simulation_frame(void)
{


    /*
      Do pending deletes:
     */
    std::list<PhasedDeletedObjectEntry> ct;

    WRATHLockMutex(m_phase_mutex);
    std::swap(ct, m_phase2);
    WRATHUnlockMutex(m_phase_mutex);

    for(std::list<PhasedDeletedObjectEntry>::iterator
            iter=ct.begin(), end=ct.end();
            iter!=end; ++iter)
    {
        WRATHDelete(iter->m_object);
    }


    WRATHLockMutex(m_phase_mutex);
    m_phase1.splice(m_phase1.end(), m_phase0);
    WRATHUnlockMutex(m_phase_mutex);

    /*
      do pending actions
     */
    do_actions(m_simulation_actions, m_simulation_actions_mutex);




    fire_signal(m_sigs[on_complete_simulation_frame][pre_update_no_lock]);


    WRATHLockMutex(m_mutex);

    //pre-conditions:
    WRATHassert(m_current_simulation_ID!=m_last_simulation_ID);
    WRATHassert(m_current_simulation_ID!=m_present_ID);


    fire_signal(m_sigs[on_complete_simulation_frame][pre_update_lock]);

    const int local_table[3][3]=
    {
        {-1, 2, 1},// (0,0), (0,1), (0,2)
        { 2,-1, 0},// (1,0), (1,1), (1,2)
        { 1, 0,-1},// (2,0), (2,1), (2,2)
    };

    m_last_simulation_ID=m_current_simulation_ID;

    WRATHassert(m_last_simulation_ID>=0);
    WRATHassert(m_last_simulation_ID<3);
    WRATHassert(m_present_ID>=0);
    WRATHassert(m_present_ID<3);

    m_current_simulation_ID=local_table[m_last_simulation_ID][m_present_ID];

    WRATHassert(m_current_simulation_ID>=0);
    WRATHassert(m_current_simulation_ID<3);

    //post-conditions:
    WRATHassert(m_current_simulation_ID!=m_last_simulation_ID);
    WRATHassert(m_current_simulation_ID!=m_present_ID);

    fire_signal(m_sigs[on_complete_simulation_frame][post_update_lock]);

    WRATHUnlockMutex(m_mutex);
    fire_signal(m_sigs[on_complete_simulation_frame][post_update_no_lock]);

    {
        WRATHAutoLockMutex(m_counter_lock);
        ++m_number_complete_simulation_frame_calls;
        ++m_number_complete_simulation_calls_since_last_begin_presentation_frame;
        m_number_begin_presentation_calls_since_last_simulation_complete_frame=0;
    }
}
Ejemplo n.º 10
0
void
tgevent_loop(void)
{
	int err;
	struct timeval now;

	if (logfile) {
		extern char prefix[], suffix[];
		extern char *ofile;
		char *cp = logfile;

		ofile = logfile;
		strcpy(prefix, strsep(&cp, "."));
		if (cp)
			strcpy(suffix, cp);
		else
			strcpy(suffix, "log");
#ifdef EVENTDEBUG
		fprintf(stderr, "trafgen: logfile=%s.%s\n", prefix, suffix);
#endif
	}

	/*
	 * XXX hand build a wait forever command.
	 * Setup happens when the first event arrives.
	 */
	memset(actions, 0, sizeof(actions));
	actions[0].tg_flags = TG_WAIT;

	while (1) {
		gettimeofday(&now, NULL);
#ifdef EVENTDEBUG
		fprintf(stderr, "%lu.%03lu: trafgen (re)started\n",
			now.tv_sec, now.tv_usec / 1000);
#endif

		/*
		 * We loop in here til we get a reset event.
		 */
		tg_first = &actions[0];
		do_actions();

		/*
		 * Got a reset.  Build a SETUP/WAIT combo and jump back
		 * into the fray.
		 */
		actions[0].tg_flags = TG_SETUP;
		actions[0].next = &actions[1];
		actions[1].tg_flags = TG_WAIT;

		/*
		 * Restart the log
		 */
		if (logfile) {
			FlushOutput = 1;
			log_close();
			start_log(now, "%s");
		}
	}

	log_close();
	tgevent_shutdown();
}