コード例 #1
0
void ProcessEvent(unsigned int me, time_type now, int event_type, event_content_type *event_content, unsigned int size, void *pointer) {

	state_type *state = (state_type *) pointer;
	char *conf_file = NULL, *conf_file_1 = NULL, *conf_file_2 = NULL;
	simulation_conf configuration;
	int i;

	// Upon reception of INIT, install the simulation state
	if (event_type == INIT) {

		// Get the file to load the configuration from
		for (i = 0; i < size; i += 2) {
			if (checkParameter("conf-file", event_content, i)) {
				conf_file = getParameter(event_content, i+1);
			}
			else if(checkParameter("conf-file_1", event_content, i)) {
				conf_file_1 = getParameter(event_content, i+1);
			}
			else if(checkParameter("conf-file_2", event_content, i)) {
				conf_file_2 = getParameter(event_content, i+1);
			}
		}

		// Sanity check
		if (conf_file == NULL) {
			fprintf(stderr, "Configuration file not specified. Please set conf-file before running the simulation.\n");
			exit(-1);
		}

		// Try to load the configuration
		if (!configuration_parse(&configuration, conf_file)) {
			fprintf(stderr, "Error loading configuration file %s\n", conf_file);
			exit(-1);
		}

		if(configuration.client_conf.data_items_access_distribution==TOPKEYS){

			if(!configuration_parse_top_keys(&configuration,"PUTS",conf_file_1)){
				fprintf(stderr, "Error loading puts topkeys' configuration file");
				exit(-1);
			}
			if(!configuration_parse_top_keys(&configuration,"GETS",conf_file_2)){
				fprintf(stderr, "Error loading gets topkeys' configuration file");
				exit(-1);
			}
			/*int x;
			for(x=0; x<configuration.cache_objects;x++){
				if(configuration.client_conf.topkeys_cache_objects_get_probability[x]==0) break;
				printf("%f\n",configuration.client_conf.topkeys_cache_objects_get_probability[x]);
			}*/
		}

		// Allocate simulation state
		state = (state_type *) malloc(sizeof(state_type));
		SetState(state);

		// Store the global configuration
		state->start_stat_time = configuration.start_stat_time;
		state->num_clients = configuration.num_clients;
		state->num_servers = configuration.num_servers;
		state->cache_objects = configuration.cache_objects;
		state->object_replication_degree = configuration.object_replication_degree;
		state->average_server_to_server_net_delay = configuration.average_server_to_server_net_delay;
		state->average_client_to_server_net_delay = configuration.average_client_to_server_net_delay;
		// Now, depending on who I am, store the remainder of the configuration
		switch (who_am_i(me, state)) {

		case CLIENT:
			state->type.client_state.configuration = configuration.client_conf;
			break;

		case SERVER:
			state->type.server_state.configuration = configuration.server_conf;
			break;

		default:
			fprintf(stderr, "Internal error at %s:%d\n", __FILE__, __LINE__);
			break;
		}
	}

	// Dispatch the event to the correct handler
	switch (who_am_i(me, state)) {

	case CLIENT:
		CLIENT_ProcessEvent(me, now, event_type, event_content, size, state);
		break;

	case SERVER:
		SERVER_ProcessEvent(me, now, event_type, event_content, size, state);
		break;

	default:
		fprintf(stderr, "Internal error at %s:%d\n", __FILE__, __LINE__);
		break;
	}

}
コード例 #2
0
ファイル: main.c プロジェクト: jucs/musicfs
int main(int argc, char *argv[]) {
	configuration_parse(&argc, &argv);
	
	return filesystem_init(argc, argv, &fuse_initialised, &fuse_destroyed);
}