mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-11 20:29:24 +00:00
Petit refactor avec des signaux
This commit is contained in:
@ -38,8 +38,9 @@ void parse_residents_Building(THIS(Building), char * file){
|
||||
char * trash;
|
||||
int i = 0;
|
||||
|
||||
if (f == NULL)
|
||||
if (f == NULL) {
|
||||
CRASH("File for residents does not exist");
|
||||
}
|
||||
|
||||
while (getline(&line, &len, f) > 0) {
|
||||
remove_end_char(line, '\n');
|
||||
@ -68,8 +69,9 @@ void parse_visitors_Building(THIS(Building), char * file){
|
||||
char * line = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (f == NULL)
|
||||
if (f == NULL) {
|
||||
CRASH("File for visitors does not exist");
|
||||
}
|
||||
|
||||
while (getline(&line, &len, f) > 0) {
|
||||
remove_end_char(line, '\n');
|
||||
@ -131,9 +133,10 @@ int get_inside_elevator_Building(THIS(Building), int current_floor, Passenger pa
|
||||
/* Make assumption that a waiting elevator is not full */
|
||||
for (i=0; i<ELEVATOR_NB; i++){
|
||||
if (this->elevators[i]->get_floor(this->elevators[i]) == current_floor &&
|
||||
this->elevators[i]->get_state(this->elevators[i]) == waiting){
|
||||
this->elevators[i]->get_state(this->elevators[i]) == WAITING){
|
||||
/* pour faire taire le compilateur le temps que je revienne sur cette fonction */
|
||||
printf("visiteur %s, de type %d\n", passenger.visitor->name, type);
|
||||
if (type == VISITOR)
|
||||
this->elevators[i]->add_passenger(this->elevators[i], passenger.visitor->get_id(passenger.visitor));
|
||||
/* Il faut faire des trucs ici */
|
||||
return i;
|
||||
}
|
||||
@ -144,8 +147,8 @@ int get_inside_elevator_Building(THIS(Building), int current_floor, Passenger pa
|
||||
void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger passenger, PASSENGER_TYPE type){
|
||||
int elevator_number;
|
||||
|
||||
if (origin < 0 || origin >= FLOORS) CRASH("You are trying to start from a non existing floor\n");
|
||||
if (destination < 0 || origin >= FLOORS) CRASH("You are trying to reach a non existing floor\n");
|
||||
if (origin < 0 || origin >= FLOORS) {CRASH("You are trying to start from a non existing floor\n");}
|
||||
if (destination < 0 || origin >= FLOORS) {CRASH("You are trying to reach a non existing floor\n");}
|
||||
|
||||
pthread_cond_wait(this->condition_floors[origin], this->mutex_get_inside_elevator);
|
||||
elevator_number = this->get_inside_elevator(this, origin, passenger, type);
|
||||
|
Reference in New Issue
Block a user