mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-11 20:29:24 +00:00
Bip, je suis l'interphone
This commit is contained in:
@ -114,7 +114,6 @@ void _free__Building(THIS(Building)){
|
||||
|
||||
DELETE(this->residents);
|
||||
DELETE(this->visitors);
|
||||
DELETE(this->box);
|
||||
for (i=0; i<ELEVATOR_NB; i++)
|
||||
DELETE(this->elevators[i]);
|
||||
for (i=0; i<FLOORS; i++)
|
||||
@ -166,6 +165,17 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
|
||||
this->elevators[elevator_number]->name, destination);
|
||||
}
|
||||
|
||||
int use_call_box_Building(THIS(Building), char * resident_name){
|
||||
/* Return negative number if not found */
|
||||
Element * current = this->residents->get_head(this->residents);
|
||||
while (current != NULL){
|
||||
if (!strcmp(((Resident *) current->get_data(current))->name, resident_name))
|
||||
return ((Resident *) current->get_data(current))->apartment_floor;
|
||||
current = current->get_next(current);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
Building * new_building = malloc_or_die(sizeof(Building));
|
||||
char elevator_name[] = "@";
|
||||
@ -178,7 +188,6 @@ Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
new_building->condition_floors = malloc_or_die(sizeof(pthread_cond_t*) * FLOORS);
|
||||
new_building->residents = NEW(List);
|
||||
new_building->visitors = NEW(List);
|
||||
new_building->box = NEW(CommunicationBox);
|
||||
for (i=0; i<ELEVATOR_NB; i++) {
|
||||
elevator_name[0]++;
|
||||
new_building->elevators[i] = NEW(Elevator, elevator_name);
|
||||
@ -194,6 +203,7 @@ Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
parse_residents,
|
||||
parse_visitors,
|
||||
get_inside_elevator,
|
||||
use_call_box,
|
||||
go_to_floor
|
||||
)
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "../Objects.h"
|
||||
#include "../List/List.h"
|
||||
#include "../Elevator/Elevator.h"
|
||||
#include "../CommunicationBox/CommunicationBox.h"
|
||||
#include "../Resident/Resident.h"
|
||||
#include "../Visitor/Visitor.h"
|
||||
|
||||
@ -26,7 +25,6 @@ typedef struct o_Building {
|
||||
PRIVATE int floors;
|
||||
PRIVATE List * residents;
|
||||
PRIVATE List * visitors;
|
||||
PRIVATE CommunicationBox * box;
|
||||
PRIVATE Elevator ** elevators;
|
||||
PRIVATE pthread_mutex_t * mutex_get_inside_elevator;
|
||||
PRIVATE pthread_mutex_t * mutex_get_outside_elevator;
|
||||
@ -36,6 +34,8 @@ typedef struct o_Building {
|
||||
PRIVATE void (*parse_visitors)(_THIS(Building), char * file);
|
||||
PRIVATE int (*get_inside_elevator)(_THIS(Building), int current_floor, Passenger passenger, PASSENGER_TYPE type);
|
||||
|
||||
PUBLIC int (*use_call_box)(_THIS(Building), char * resident_name);
|
||||
|
||||
SYNCHRONIZE PUBLIC void (*go_to_floor)(_THIS(Building), int origin, int destination, Passenger passenger, PASSENGER_TYPE type);
|
||||
|
||||
DESTRUCTOR(Building);
|
||||
|
Reference in New Issue
Block a user