1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2025-07-13 05:09:30 +00:00

refactored printing

This commit is contained in:
Aethor
2018-06-22 01:50:27 +02:00
parent 3e73835b81
commit 3bcb7faf66
4 changed files with 14 additions and 16 deletions

View File

@ -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);
}
}