mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-12-22 15:51:11 +00:00
Suppression de trucs nuls et ecapsulation
This commit is contained in:
parent
ce0e2ca931
commit
741a98f926
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user