mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-11-22 00:33:22 +00:00
c'est plus beau
This commit is contained in:
parent
f6dc3e5f3a
commit
7315e1595e
@ -146,9 +146,7 @@ int get_inside_elevator_Building(THIS(Building), int current_floor, Passenger *
|
|||||||
int i;
|
int i;
|
||||||
/* Make assumption that a waiting elevator is not full */
|
/* Make assumption that a waiting elevator is not full */
|
||||||
pthread_mutex_lock(this->mutex_func_get_inside_elevator);
|
pthread_mutex_lock(this->mutex_func_get_inside_elevator);
|
||||||
printf("Test d'entrée à l'étage %d de %s : id %d\n", current_floor,
|
printf("Test d'entrée à l'étage %d de %s : id %d\n", current_floor, passenger->get_name(passenger), passenger->get_id(passenger));
|
||||||
passenger->type == VISITOR ? passenger->visitor->name : passenger->resident->name,
|
|
||||||
passenger->type == VISITOR ? passenger->visitor->id : passenger->resident->id);
|
|
||||||
for (i=0; i<ELEVATOR_NB; i++){
|
for (i=0; i<ELEVATOR_NB; i++){
|
||||||
if (this->elevators[i]->can_get_inside(this->elevators[i], current_floor)){
|
if (this->elevators[i]->can_get_inside(this->elevators[i], current_floor)){
|
||||||
this->elevators[i]->add_passenger(this->elevators[i], passenger);
|
this->elevators[i]->add_passenger(this->elevators[i], passenger);
|
||||||
@ -174,25 +172,25 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
|
|||||||
|
|
||||||
if (elevator_number != -1){ //passenger accepted in elevator
|
if (elevator_number != -1){ //passenger accepted in elevator
|
||||||
if (passenger->type == RESIDENT)
|
if (passenger->type == RESIDENT)
|
||||||
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->resident->name,
|
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
|
||||||
this->elevators[elevator_number]->name, origin);
|
this->elevators[elevator_number]->name, origin);
|
||||||
else if (passenger->type == VISITOR)
|
else if (passenger->type == VISITOR)
|
||||||
printf("Le visiteur %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->visitor->name,
|
printf("Le visiteur %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
|
||||||
this->elevators[elevator_number]->name, origin);
|
this->elevators[elevator_number]->name, origin);
|
||||||
|
|
||||||
pthread_cond_wait(this->condition_floors[destination], this->mutex_cond_get_outside_elevator);
|
pthread_cond_wait(this->condition_floors[destination], this->mutex_cond_get_outside_elevator);
|
||||||
if (passenger->type == RESIDENT)
|
if (passenger->type == RESIDENT)
|
||||||
printf("Le résident %s sort de l'ascenseur %s à l'étage %d\n", passenger->resident->name,
|
printf("Le résident %s sort de l'ascenseur %s à l'étage %d\n", passenger->get_name(passenger),
|
||||||
this->elevators[elevator_number]->name, destination);
|
this->elevators[elevator_number]->name, destination);
|
||||||
else if (passenger->type == VISITOR)
|
else if (passenger->type == VISITOR)
|
||||||
printf("Le visiteur %s sort de l'ascenseur %s à l'étage %d\n", passenger->visitor->name,
|
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]->name, destination);
|
||||||
}else{
|
}else{
|
||||||
if (passenger->type == RESIDENT)
|
if (passenger->type == RESIDENT)
|
||||||
printf("Le résident %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->resident->name, origin);
|
printf("Le résident %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->get_name(passenger), origin);
|
||||||
else if (passenger->type == VISITOR)
|
else if (passenger->type == VISITOR)
|
||||||
printf("Le visiteur %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->visitor->name, origin);
|
printf("Le visiteur %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->get_name(passenger), origin);
|
||||||
//réarmement
|
//reloading fire
|
||||||
this->go_to_floor(this, origin, destination, passenger);
|
this->go_to_floor(this, origin, destination, passenger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){
|
|||||||
pthread_mutex_lock(&this->mutex_passengers);
|
pthread_mutex_lock(&this->mutex_passengers);
|
||||||
this->passengers->insert_tail(this->passengers, ((void *)passenger), sizeof(Passenger));
|
this->passengers->insert_tail(this->passengers, ((void *)passenger), sizeof(Passenger));
|
||||||
printf("L'ascenseur %s recoit le visiteur %s\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name,
|
printf("L'ascenseur %s recoit le visiteur %s\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name,
|
||||||
passenger->type == VISITOR ? passenger->visitor->get_name(passenger->visitor) : passenger->resident->get_name(passenger->resident),
|
passenger->get_name(passenger),
|
||||||
this->passengers->get_size(this->passengers), this->name);
|
this->passengers->get_size(this->passengers), this->name);
|
||||||
if (this->passengers->get_size(this->passengers) >= MAX_ELEVATOR_CAPACITY)
|
if (this->passengers->get_size(this->passengers) >= MAX_ELEVATOR_CAPACITY)
|
||||||
this->set_state(this, SLEEPING);
|
this->set_state(this, SLEEPING);
|
||||||
|
@ -9,6 +9,14 @@ int compare_Passenger(void * passenger1, void * passenger2){
|
|||||||
((Passenger*) passenger2)->get_name((Passenger*) passenger2)) == 0);
|
((Passenger*) passenger2)->get_name((Passenger*) passenger2)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_destination_Passenger(THIS(Passenger)){
|
||||||
|
if (this->type == RESIDENT)
|
||||||
|
return this->resident->get_destination(this->resident);
|
||||||
|
if (this->type == VISITOR)
|
||||||
|
return this->visitor->get_destination(this->visitor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int get_id_Passenger(THIS(Passenger)){
|
int get_id_Passenger(THIS(Passenger)){
|
||||||
if (this->type == RESIDENT)
|
if (this->type == RESIDENT)
|
||||||
return this->resident->get_id(this->resident);
|
return this->resident->get_id(this->resident);
|
||||||
@ -54,6 +62,7 @@ Passenger *_init_Passenger(void* passenger_data, PASSENGER_TYPE type){
|
|||||||
LINK_ALL(Passenger, new_passenger,
|
LINK_ALL(Passenger, new_passenger,
|
||||||
get_id,
|
get_id,
|
||||||
get_name,
|
get_name,
|
||||||
|
get_destination,
|
||||||
compare,
|
compare,
|
||||||
runnable
|
runnable
|
||||||
)
|
)
|
||||||
|
@ -20,6 +20,7 @@ typedef struct o_Passenger {
|
|||||||
|
|
||||||
PUBLIC char * (*get_name)(_THIS(Passenger));
|
PUBLIC char * (*get_name)(_THIS(Passenger));
|
||||||
PUBLIC int (*get_id)(_THIS(Passenger));
|
PUBLIC int (*get_id)(_THIS(Passenger));
|
||||||
|
PUBLIC int (*get_destination)(_THIS(Passenger));
|
||||||
PUBLIC void * (*runnable)(void* void_this);
|
PUBLIC void * (*runnable)(void* void_this);
|
||||||
PUBLIC int (*compare)(void * passenger1, void * passenger2);//yeah I know, but i needed int (*) (void*, void*)
|
PUBLIC int (*compare)(void * passenger1, void * passenger2);//yeah I know, but i needed int (*) (void*, void*)
|
||||||
|
|
||||||
|
@ -8,13 +8,14 @@
|
|||||||
#include "../SharedData/SharedData.h"
|
#include "../SharedData/SharedData.h"
|
||||||
|
|
||||||
GETTER(Resident, char *, name);
|
GETTER(Resident, char *, name);
|
||||||
|
GETTER(Resident, int, destination);
|
||||||
GETTER(Resident, int, id);
|
GETTER(Resident, int, id);
|
||||||
GETTER(Resident, int, apartment_floor);
|
GETTER(Resident, int, apartment_floor);
|
||||||
|
|
||||||
void * runnable_Resident(void * void_this){
|
void * runnable_Resident(void * void_this){
|
||||||
Resident * this = (Resident*) void_this;
|
Resident * this = (Resident*) void_this;
|
||||||
SharedData* data = GET_INSTANCE(SharedData);
|
SharedData* data = GET_INSTANCE(SharedData);
|
||||||
Passenger * passenger = NEW(Passenger, this, RESIDENT);
|
Passenger * passenger = NEW(Passenger, (void*) this, RESIDENT);
|
||||||
|
|
||||||
AGENT_OPTIONS;
|
AGENT_OPTIONS;
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ void * runnable_Resident(void * void_this){
|
|||||||
printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n",
|
printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n",
|
||||||
this->name, this->apartment_floor, this->destination);
|
this->name, this->apartment_floor, this->destination);
|
||||||
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
|
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
|
||||||
|
DELETE(passenger);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +46,7 @@ Resident *_init_Resident(int id, char* name, int apartment_floor, int destinatio
|
|||||||
|
|
||||||
LINK_ALL(Resident, new_resident,
|
LINK_ALL(Resident, new_resident,
|
||||||
get_name,
|
get_name,
|
||||||
|
get_destination,
|
||||||
get_id,
|
get_id,
|
||||||
runnable,
|
runnable,
|
||||||
get_apartment_floor
|
get_apartment_floor
|
||||||
|
@ -18,6 +18,7 @@ typedef struct o_Resident {
|
|||||||
PUBLIC char * (*get_name)(_THIS(Resident));
|
PUBLIC char * (*get_name)(_THIS(Resident));
|
||||||
PUBLIC int (*get_id)(_THIS(Resident));
|
PUBLIC int (*get_id)(_THIS(Resident));
|
||||||
PUBLIC int (*get_apartment_floor)(_THIS(Resident));
|
PUBLIC int (*get_apartment_floor)(_THIS(Resident));
|
||||||
|
PUBLIC int (*get_destination)(_THIS(Resident));
|
||||||
|
|
||||||
DESTRUCTOR(Resident);
|
DESTRUCTOR(Resident);
|
||||||
} Resident;
|
} Resident;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
GETTER(Visitor, char*, name);
|
GETTER(Visitor, char*, name);
|
||||||
|
GETTER(Visitor, int, destination);
|
||||||
GETTER(Visitor, int, id);
|
GETTER(Visitor, int, id);
|
||||||
|
|
||||||
void * runnable_Visitor(void * void_this){
|
void * runnable_Visitor(void * void_this){
|
||||||
@ -47,6 +48,7 @@ Visitor *_init_Visitor(int id, char* name, char * contact_name){
|
|||||||
|
|
||||||
LINK_ALL(Visitor, new_visitor,
|
LINK_ALL(Visitor, new_visitor,
|
||||||
get_name,
|
get_name,
|
||||||
|
get_destination,
|
||||||
get_id,
|
get_id,
|
||||||
runnable
|
runnable
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,7 @@ typedef struct o_Visitor {
|
|||||||
PUBLIC void * (*runnable)(void* void_this);
|
PUBLIC void * (*runnable)(void* void_this);
|
||||||
PUBLIC char * (*get_name)(_THIS(Visitor));
|
PUBLIC char * (*get_name)(_THIS(Visitor));
|
||||||
PUBLIC int (*get_id)(_THIS(Visitor));
|
PUBLIC int (*get_id)(_THIS(Visitor));
|
||||||
|
PUBLIC int (*get_destination)(_THIS(Visitor));
|
||||||
|
|
||||||
DESTRUCTOR(Visitor);
|
DESTRUCTOR(Visitor);
|
||||||
} Visitor;
|
} Visitor;
|
||||||
|
Loading…
Reference in New Issue
Block a user