2018-06-05 23:15:23 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 05/06/2018.
|
|
|
|
//
|
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
#include <string.h>
|
2018-06-05 23:15:23 +00:00
|
|
|
#include "Elevator.h"
|
2018-06-06 01:00:35 +00:00
|
|
|
|
|
|
|
void _free__Elevator(THIS(Elevator)){
|
2018-06-07 20:04:30 +00:00
|
|
|
DELETE(this->passenger_ids);
|
|
|
|
if (this->name != NULL)
|
|
|
|
free(this->name);
|
|
|
|
pthread_mutex_unlock(&this->passenger_mutex);
|
|
|
|
pthread_mutex_destroy(&this->passenger_mutex);
|
2018-06-06 01:00:35 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
int get_number_of_passengers_Elevator(THIS(Elevator)){
|
|
|
|
int num;
|
|
|
|
pthread_mutex_lock(&this->passenger_mutex);
|
|
|
|
num = this->passenger_ids->get_size(this->passenger_ids);
|
|
|
|
pthread_mutex_lock(&this->passenger_mutex);
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
int can_get_more_passengers_Elevator(_THIS(Elevator)){
|
|
|
|
return (this->get_number_of_passengers(this) < MAX_ELEVATOR_CAPACITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
Elevator *_init_Elevator(char * name){
|
2018-06-06 01:00:35 +00:00
|
|
|
Elevator * new_elevator = malloc_or_die(sizeof(Elevator));
|
2018-06-07 20:04:30 +00:00
|
|
|
new_elevator->state = waiting;
|
|
|
|
new_elevator->name = strdup(name);
|
|
|
|
new_elevator->passenger_ids = NEW(List);
|
|
|
|
pthread_mutex_init(&new_elevator->passenger_mutex, NULL);
|
2018-06-06 01:00:35 +00:00
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
LINK_ALL(Elevator, new_elevator,
|
|
|
|
get_number_of_passengers,
|
|
|
|
can_get_more_passengers
|
|
|
|
);
|
2018-06-06 01:00:35 +00:00
|
|
|
|
|
|
|
return new_elevator;
|
|
|
|
}
|