mirror of
				https://gitlab.com/klmp200/LO41.git
				synced 2025-10-31 01:03:05 +00:00 
			
		
		
		
	refactored printing
This commit is contained in:
		| @@ -180,7 +180,7 @@ int get_inside_elevator_Building(THIS(Building), int current_floor, Passenger * | ||||
| 	int i; | ||||
| 	/* Make assumption that a waiting elevator is not full */ | ||||
| 	pthread_mutex_lock(this->mutex_func_get_inside_elevator); | ||||
| 	printf("Test d'entrée à l'étage %d de %s : id %d\n", current_floor, passenger->get_name(passenger), passenger->get_id(passenger)); | ||||
| 	printf("Passager %s : J'essaye de rentrer dans un ascenseur, à l'étage %d ( id : %d )\n", passenger->get_name(passenger), current_floor, passenger->get_id(passenger)); | ||||
| 	for (i=0; i<ELEVATOR_NB; i++){ | ||||
| 		if (this->elevators[i]->can_get_inside(this->elevators[i], current_floor)){ | ||||
| 			this->elevators[i]->add_passenger(this->elevators[i], passenger); | ||||
| @@ -212,9 +212,9 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger | ||||
| 		this->elevators[elevator_number]->remove_passenger(this->elevators[elevator_number], passenger); | ||||
| 	}else{ | ||||
| 		if (passenger->type == RESIDENT) | ||||
| 			printf("Le résident %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->get_name(passenger), origin); | ||||
| 			printf("Résident %s : L'ascenseur à l'étage %d était plein et je n'ai pas pu monter\n", passenger->get_name(passenger), origin); | ||||
| 		else if (passenger->type == VISITOR) | ||||
| 		        printf("Le visiteur %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->get_name(passenger), origin); | ||||
| 			printf("Visiteur %s : L'ascenseur à l'étage %d était plein et je n'ai pas pu monter\n", passenger->get_name(passenger), origin); | ||||
| 		//reloading fire | ||||
| 		this->waiting_floors[origin]--; | ||||
| 		this->go_to_floor(this, origin, destination, passenger); | ||||
|   | ||||
| @@ -33,12 +33,10 @@ void _free__Elevator(THIS(Elevator)){ | ||||
| void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){ | ||||
| 	pthread_mutex_lock(&this->mutex_passengers); | ||||
| 	this->passengers->insert_tail(this->passengers, ((void *)passenger), sizeof(Passenger)); | ||||
| 	printf("L'ascenseur %s recoit le passager %s à l'étage %d\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name, | ||||
| 	printf("Ascenseur %s : Je recoit le passager %s à l'étage %d\nAscenseur %s : J'ai désormais %d passager(s) à mon bord\n", this->name, | ||||
| 	       passenger->get_name(passenger), | ||||
| 	       this->get_floor(this), | ||||
| 	       this->passengers->get_size(this->passengers), this->name); | ||||
| 	/*if (this->passengers->get_size(this->passengers) >= MAX_ELEVATOR_CAPACITY) | ||||
| 	  this->set_state(this, SLEEPING);*/ | ||||
| 	       this->name, this->passengers->get_size(this->passengers)); | ||||
| 	pthread_mutex_unlock(&this->mutex_passengers); | ||||
| } | ||||
|  | ||||
| @@ -51,11 +49,11 @@ void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){ | ||||
| void remove_passenger_Elevator(THIS(Elevator), Passenger * passenger){ | ||||
| 	pthread_mutex_lock(&this->mutex_passengers); | ||||
| 	if (passenger->type == RESIDENT) | ||||
| 		printf("Le résident %s sort de l'ascenseur %s à l'étage %d\n", passenger->get_name(passenger), this->name, this->get_floor(this)); | ||||
| 		printf("Ascenseur %s : Le résident %s sort à l'étage %d\n", this->name, passenger->get_name(passenger), this->get_floor(this)); | ||||
| 	else if (passenger->type == VISITOR) | ||||
| 		printf("Le visiteur %s sort de l'ascenseur %s à l'étage %d\n", passenger->get_name(passenger), this->name, this->get_floor(this));	 | ||||
| 		printf("Ascenseur %s : Le passager %s sort à l'étage %d\n", this->name, passenger->get_name(passenger), this->get_floor(this)); | ||||
| 	this->passengers->remove_inside(this->passengers, passenger, passenger->compare); | ||||
| 	printf("Ascenseur %s : j'ai encore %d passagers\n", this->name, this->passengers->get_size(this->passengers)); | ||||
| 	printf("Ascenseur %s : Il reste encore à mon bord %d passagers\n", this->name, this->passengers->get_size(this->passengers)); | ||||
| 	pthread_mutex_unlock(&this->mutex_passengers); | ||||
| } | ||||
|  | ||||
| @@ -134,7 +132,7 @@ void *runnable_Elevator(void * void_this){ | ||||
|  | ||||
| 	AGENT_OPTIONS | ||||
|  | ||||
| 	printf("Initialisation de l'ascenseur %s\n", this->name); | ||||
| 	printf("Ascenseur %s : Initialisation...\n", this->name); | ||||
| 	for (;;){ | ||||
| 		usleep(250000); | ||||
| 		if(this->target_floor == this->get_floor(this)){ | ||||
| @@ -166,7 +164,7 @@ void *runnable_Elevator(void * void_this){ | ||||
| 		} | ||||
| 		if(this->get_floor(this) != this->target_floor){ | ||||
| 			this->set_floor(this, this->target_floor); | ||||
| 			printf("Ascenseur %s en route vers l'étage %d\n", this->name, this->target_floor); | ||||
| 			printf("Ascenseur %s :  Je suis en route vers l'étage %d\n", this->name, this->target_floor); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -23,10 +23,10 @@ void * runnable_Resident(void * void_this){ | ||||
| 	passenger->resident = this; | ||||
| 	passenger->type = RESIDENT; | ||||
|  | ||||
| 	printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n", | ||||
| 	printf("Résident %s : Je suis a l'etage %d, je vais en direction de l'etage %d\n", | ||||
| 		this->name, this->apartment_floor, this->destination); | ||||
| 	if(this->position == this->destination) | ||||
| 		printf("Résident %s : je reste chez moi\n", this->name); | ||||
| 		printf("Résident %s : Je reste chez moi\n", this->name); | ||||
| 	else | ||||
| 		data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger); | ||||
| 	return NULL; | ||||
|   | ||||
| @@ -20,8 +20,8 @@ void * runnable_Visitor(void * void_this){ | ||||
|  | ||||
| 	passenger->visitor = this; | ||||
|  | ||||
| 	printf("Bonjour, je suis %s et je souhaite rendre visite a %s\n", this->name, this->contact_name); | ||||
| 	printf("Bip, %s appel a l'interphone\n%s habite a l'etage %d\n", this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name))); | ||||
| 	printf("Visiteur %s : Je souhaite rendre visite a %s\n", this->name, this->contact_name); | ||||
| 	printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name))); | ||||
| 	data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger); | ||||
| 	return NULL; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user