mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-12-23 00:01:11 +00:00
To the moooo.... oh wait, not yet.
This commit is contained in:
parent
55126c9ca6
commit
653734ec1f
@ -212,12 +212,7 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
|
||||
this->elevators[elevator_number]->name, origin);
|
||||
|
||||
pthread_cond_wait(this->condition_floors[destination], this->mutex_cond_get_outside_elevator);
|
||||
if (passenger->type == RESIDENT)
|
||||
printf("Le résident %s sort de l'ascenseur %s à l'étage %d\n", passenger->get_name(passenger),
|
||||
this->elevators[elevator_number]->name, destination);
|
||||
else if (passenger->type == VISITOR)
|
||||
printf("Le visiteur %s sort de l'ascenseur %s à l'étage %d\n", passenger->get_name(passenger),
|
||||
this->elevators[elevator_number]->name, destination);
|
||||
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);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include "Elevator.h"
|
||||
#include "../SharedData/SharedData.h"
|
||||
|
||||
@ -40,9 +41,20 @@ void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){
|
||||
pthread_mutex_unlock(&this->mutex_passengers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a passenger from an elevator. Efectively remove him from the elevator's passenger list.
|
||||
* @SYNCHRONIZED passengers : this elevator's list of passenger is accessed via mutex
|
||||
* @param THIS(Elevator) : this
|
||||
* @param passenger : the passenger to remove
|
||||
*/
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
pthread_mutex_unlock(&this->mutex_passengers);
|
||||
}
|
||||
|
||||
@ -155,6 +167,7 @@ Elevator *_init_Elevator(char * name){
|
||||
get_number_of_passengers,
|
||||
get_next_passenger_stop,
|
||||
can_get_inside,
|
||||
remove_passenger,
|
||||
add_passenger,
|
||||
get_state,
|
||||
set_state,
|
||||
|
@ -33,6 +33,7 @@ typedef struct o_Elevator {
|
||||
|
||||
SYNCHRONIZE PUBLIC void (*repair)(_THIS(Elevator));
|
||||
SYNCHRONIZE PUBLIC int (*get_number_of_passengers)(_THIS(Elevator));
|
||||
SYNCHRONIZE PUBLIC void (*remove_passenger) (_THIS(Elevator), Passenger * passenger);
|
||||
SYNCHRONIZE PUBLIC void (*add_passenger)(_THIS(Elevator), Passenger * passenger);
|
||||
SYNCHRONIZE PUBLIC ELEVATOR_STATE (*get_state)(_THIS(Elevator));
|
||||
SYNCHRONIZE PUBLIC int (*get_floor)(_THIS(Elevator));
|
||||
|
Loading…
Reference in New Issue
Block a user