mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-12-25 01:01:12 +00:00
Bip, je suis l'interphone
This commit is contained in:
parent
e52cb25c55
commit
ce0e2ca931
@ -1,4 +1,4 @@
|
||||
image: ubuntu:bionic
|
||||
image: ubuntu:artful
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -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);
|
||||
|
@ -8,4 +8,4 @@ if(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
||||
endif()
|
||||
|
||||
add_executable(LO41 main.c List/List.h List/List.c Objects.h List/Element.c List/Element.h Objects.c Building/Building.c Building/Building.h Elevator/Elevator.c Elevator/Elevator.h CommunicationBox/CommunicationBox.c CommunicationBox/CommunicationBox.h SharedData/SharedData.c SharedData/SharedData.h Visitor/Visitor.c Visitor/Visitor.h Resident/Resident.c Resident/Resident.h)
|
||||
add_executable(LO41 main.c List/List.h List/List.c Objects.h List/Element.c List/Element.h Objects.c Building/Building.c Building/Building.h Elevator/Elevator.c Elevator/Elevator.h SharedData/SharedData.c SharedData/SharedData.h Visitor/Visitor.c Visitor/Visitor.h Resident/Resident.c Resident/Resident.h)
|
@ -1,17 +0,0 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 05/06/2018.
|
||||
//
|
||||
|
||||
#include "CommunicationBox.h"
|
||||
|
||||
void _free__CommunicationBox(THIS(CommunicationBox)){
|
||||
free(this);
|
||||
}
|
||||
|
||||
CommunicationBox *_init_CommunicationBox(){
|
||||
CommunicationBox * new_box = malloc_or_die(sizeof(CommunicationBox));
|
||||
|
||||
LINK(CommunicationBox, new_box, _free_);
|
||||
|
||||
return new_box;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 05/06/2018.
|
||||
//
|
||||
|
||||
#ifndef LO41_COMMUNICATIONBOX_H
|
||||
#define LO41_COMMUNICATIONBOX_H
|
||||
|
||||
#include "../Objects.h"
|
||||
|
||||
typedef struct o_CommunicationBox {
|
||||
|
||||
DESTRUCTOR(CommunicationBox);
|
||||
} CommunicationBox;
|
||||
|
||||
CommunicationBox *_init_CommunicationBox();
|
||||
|
||||
#endif //LO41_COMMUNICATIONBOX_H
|
@ -5,12 +5,7 @@
|
||||
#include "SharedData.h"
|
||||
|
||||
GETTER(SharedData, Building *, main_building)
|
||||
GETTER(SharedData, CommunicationBox *, box)
|
||||
|
||||
void set_main_building_SharedData(THIS(SharedData), Building * building){
|
||||
this->main_building = building;
|
||||
this->box = (building != NULL ) ? building->box : NULL;
|
||||
}
|
||||
SETTER(SharedData, Building *, main_building)
|
||||
|
||||
void wait_threads_SharedData(THIS(SharedData)){
|
||||
int i;
|
||||
@ -97,8 +92,7 @@ SharedData *_get_instance_SharedData(){
|
||||
new_shared_data = malloc_or_die(sizeof(SharedData));
|
||||
|
||||
new_shared_data->threads = NULL;
|
||||
new_shared_data->main_building = NULL; /* Should be set to NULL if freed */
|
||||
new_shared_data->box = NULL; /* freed inside main_building */
|
||||
new_shared_data->main_building = NULL; /* Should be set to NULL if freed before */
|
||||
new_shared_data->threads_nb = 0;
|
||||
|
||||
LINK_ALL(SharedData, new_shared_data,
|
||||
@ -108,7 +102,6 @@ SharedData *_get_instance_SharedData(){
|
||||
wait_all_threads,
|
||||
set_main_building,
|
||||
get_main_building,
|
||||
get_box,
|
||||
call_elevator
|
||||
);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ typedef struct o_SharedData {
|
||||
PRIVATE pthread_mutex_t mutex_array[MUTEX_NB];
|
||||
|
||||
PRIVATE Building * main_building;
|
||||
PRIVATE CommunicationBox * box;
|
||||
|
||||
PRIVATE void (*start_thread)(_THIS(SharedData), void * (*thread)(void *), void * data, int thread_number);
|
||||
|
||||
@ -27,7 +26,6 @@ typedef struct o_SharedData {
|
||||
PUBLIC void (*start_all_threads)(_THIS(SharedData));
|
||||
PUBLIC void (*set_main_building)(_THIS(SharedData), Building * building);
|
||||
PUBLIC Building * (*get_main_building)(_THIS(SharedData));
|
||||
PUBLIC CommunicationBox * (*get_box)(_THIS(SharedData));
|
||||
PUBLIC void (*wait_threads)(_THIS(SharedData));
|
||||
PUBLIC int (*call_elevator)(_THIS(SharedData), int starting_floor, int destination_floor);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "Visitor.h"
|
||||
#include "../SharedData/SharedData.h"
|
||||
#include <string.h>
|
||||
|
||||
GETTER(Visitor, char*, name);
|
||||
@ -10,7 +11,9 @@ GETTER(Visitor, int, id);
|
||||
|
||||
void * runnable_Visitor(void * void_this){
|
||||
Visitor *this = (Visitor*) void_this;
|
||||
SharedData * data = GET_INSTANCE(SharedData);
|
||||
printf("Bonjour, je suis %s et je souhaite rendre visite a %s\n", this->name, this->contact_name);
|
||||
printf("Bip, %s appel a l'interphone\n%s habite a l'etage %d\n", this->name, this->contact_name, data->main_building->use_call_box(data->main_building, this->contact_name));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user