1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2024-11-21 16:23:22 +00:00

Suppression de trucs nuls et ecapsulation

This commit is contained in:
Antoine Bartuccio 2018-06-11 11:09:08 +02:00
parent ce0e2ca931
commit 741a98f926
Signed by: klmp200
GPG Key ID: E7245548C53F904B
3 changed files with 7 additions and 7 deletions

View File

@ -73,6 +73,10 @@ void wait_all_threads_SharedData(THIS(SharedData)){
pthread_join(this->threads[i], NULL);
}
int use_call_box_SharedData(THIS(SharedData), char * resident_name){
return this->main_building->use_call_box(this->main_building, resident_name);
}
void _free__SharedData(THIS(SharedData)){
int i;
if (this->threads != NULL){
@ -102,6 +106,7 @@ SharedData *_get_instance_SharedData(){
wait_all_threads,
set_main_building,
get_main_building,
use_call_box,
call_elevator
);
}

View File

@ -9,15 +9,9 @@
#include "../Objects.h"
#include "../Building/Building.h"
#define MUTEX_NB 3
enum {mutex_1, mutex_2, mutex_3};
typedef struct o_SharedData {
PRIVATE int threads_nb;
PRIVATE pthread_t *threads;
PRIVATE pthread_mutex_t mutex_array[MUTEX_NB];
PRIVATE Building * main_building;
PRIVATE void (*start_thread)(_THIS(SharedData), void * (*thread)(void *), void * data, int thread_number);
@ -28,6 +22,7 @@ typedef struct o_SharedData {
PUBLIC Building * (*get_main_building)(_THIS(SharedData));
PUBLIC void (*wait_threads)(_THIS(SharedData));
PUBLIC int (*call_elevator)(_THIS(SharedData), int starting_floor, int destination_floor);
PUBLIC int (*use_call_box)(_THIS(SharedData), char * resident_name);
DESTRUCTOR(SharedData);
} SharedData;

View File

@ -13,7 +13,7 @@ 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));
printf("Bip, %s appel a l'interphone\n%s habite a l'etage %d\n", this->name, this->contact_name, data->use_call_box(data, this->contact_name));
return NULL;
}