mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-12 12:49:24 +00:00
Le réparateur, j'ai pas testé lol
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
//
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include "Building.h"
|
||||
#include "../Resident/Resident.h"
|
||||
#include "../Visitor/Visitor.h"
|
||||
@ -150,6 +151,9 @@ void _free__Building(THIS(Building)){
|
||||
pthread_mutex_unlock(&this->mutex_waiting_floors);
|
||||
pthread_mutex_destroy(&this->mutex_waiting_floors);
|
||||
|
||||
pthread_mutex_unlock(&this->mutex_repair);
|
||||
pthread_mutex_destroy(&this->mutex_repair);
|
||||
|
||||
DELETE(this->residents);
|
||||
DELETE(this->visitors);
|
||||
for (i=0; i<ELEVATOR_NB; i++)
|
||||
@ -236,6 +240,15 @@ void signal_elevator_at_floor_Building(THIS(Building), int floor){
|
||||
pthread_cond_signal(this->condition_floors[floor]);
|
||||
}
|
||||
|
||||
void ask_elevator_reparation_Building(THIS(Building), Elevator* elevator){
|
||||
printf("Technicien : l'ascenseur %s attend pour se faire réparer\n", elevator->name);
|
||||
pthread_mutex_lock(&this->mutex_repair);
|
||||
usleep(10000);
|
||||
elevator->repair(elevator);
|
||||
pthread_mutex_unlock(&this->mutex_repair);
|
||||
printf("Technicien : l'ascenseur %s est maintenant réparé\n", elevator->name);
|
||||
}
|
||||
|
||||
Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
Building * new_building = malloc_or_die(sizeof(Building));
|
||||
char elevator_name[] = "@";
|
||||
@ -245,6 +258,7 @@ Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
for (i=0; i<FLOORS; i++)
|
||||
new_building->waiting_floors[i] = 0;
|
||||
pthread_mutex_init(&new_building->mutex_waiting_floors, NULL);
|
||||
pthread_mutex_init(&new_building->mutex_repair, NULL);
|
||||
|
||||
new_building->elevators = malloc_or_die(sizeof(Elevator*) * ELEVATOR_NB);
|
||||
|
||||
@ -273,14 +287,15 @@ Building *_init_Building(char * residents_file, char * visitors_file){
|
||||
|
||||
|
||||
LINK_ALL(Building, new_building,
|
||||
parse_residents,
|
||||
parse_visitors,
|
||||
get_inside_elevator,
|
||||
use_call_box,
|
||||
go_to_floor,
|
||||
get_next_call,
|
||||
get_waiting_floors,
|
||||
signal_elevator_at_floor
|
||||
parse_residents,
|
||||
parse_visitors,
|
||||
get_inside_elevator,
|
||||
use_call_box,
|
||||
go_to_floor,
|
||||
get_next_call,
|
||||
get_waiting_floors,
|
||||
signal_elevator_at_floor,
|
||||
ask_elevator_reparation
|
||||
)
|
||||
|
||||
if (residents_file != NULL)
|
||||
|
@ -22,6 +22,7 @@ typedef struct o_Building {
|
||||
PRIVATE List * visitors;
|
||||
PRIVATE Elevator ** elevators;
|
||||
PRIVATE pthread_mutex_t mutex_waiting_floors;
|
||||
PRIVATE pthread_mutex_t mutex_repair;
|
||||
PRIVATE pthread_mutex_t * mutex_cond_get_inside_elevator;
|
||||
PRIVATE pthread_mutex_t * mutex_cond_get_outside_elevator;
|
||||
PRIVATE pthread_mutex_t * mutex_func_get_inside_elevator;
|
||||
@ -37,6 +38,8 @@ typedef struct o_Building {
|
||||
PUBLIC int (*get_next_call)(_THIS(Building), int elevator_floor);
|
||||
PUBLIC int* (*get_waiting_floors)(_THIS(Building));
|
||||
|
||||
SYNCHRONIZE PUBLIC void (*ask_elevator_reparation)(_THIS(Building), Elevator* elevator);
|
||||
|
||||
SYNCHRONIZE PUBLIC void (*go_to_floor)(_THIS(Building), int origin, int destination, Passenger * passenger);
|
||||
|
||||
DESTRUCTOR(Building);
|
||||
|
Reference in New Issue
Block a user