2018-06-04 22:26:48 +00:00
# include <stdio.h>
2018-06-07 20:04:30 +00:00
# include <signal.h>
2018-06-10 02:00:01 +00:00
# include <unistd.h>
2018-06-07 20:04:30 +00:00
2018-06-04 22:26:48 +00:00
# include "Objects.h"
# include "List/List.h"
2018-06-06 01:00:35 +00:00
# include "Building/Building.h"
2018-06-06 11:50:11 +00:00
# include "SharedData/SharedData.h"
2018-06-06 18:29:02 +00:00
# include "Visitor/Visitor.h"
# include "Resident/Resident.h"
2018-06-04 22:26:48 +00:00
2018-06-10 02:00:01 +00:00
pthread_cond_t cond ;
void * test_sub ( void * bite ) {
usleep ( 2000000 ) ;
printf ( " Je relache le programme \n " ) ;
pthread_cond_signal ( & cond ) ;
return bite ;
}
2018-06-07 20:04:30 +00:00
void clean_exit ( int error_code ) {
2018-06-07 20:35:20 +00:00
printf ( " Signal %d received, exiting app \n " , error_code ) ;
2018-06-07 20:04:30 +00:00
DELETE ( GET_INSTANCE ( SharedData ) ) ;
exit ( 0 ) ;
}
2018-06-04 22:26:48 +00:00
int main ( ) {
List * l = NEW ( List ) ;
2018-06-10 15:57:39 +00:00
Visitor * roger = NEW ( Visitor , 8 , " Roger " , " Sli " ) ;
Resident * sli = NEW ( Resident , 1 , " Sli " , 2 , 2 ) ;
2018-06-05 13:52:48 +00:00
char text1 [ 30 ] = " Patate " ;
char text2 [ 30 ] = " Patator " ;
2018-06-10 02:00:01 +00:00
pthread_mutex_t mutex ;
pthread_t thread ;
2018-06-06 11:50:11 +00:00
GET_INSTANCE ( SharedData ) ;
2018-06-07 20:04:30 +00:00
signal ( SIGINT , clean_exit ) ;
2018-06-06 11:50:11 +00:00
2018-06-10 02:00:01 +00:00
pthread_mutex_init ( & mutex , NULL ) ;
pthread_cond_init ( & cond , NULL ) ;
2018-06-05 13:52:48 +00:00
printf ( " La taille est de %d \n " , l - > get_size ( l ) ) ;
2018-06-10 02:00:01 +00:00
pthread_create ( & thread , 0 , test_sub , NULL ) ;
printf ( " FREEEZZZE \n " ) ;
pthread_cond_wait ( & cond , & mutex ) ;
pthread_cond_destroy ( & cond ) ;
2018-06-05 13:52:48 +00:00
l - > insert_tail ( l , text1 , sizeof ( char ) * 30 ) ;
l - > insert_head ( l , text2 , sizeof ( char ) * 30 ) ;
l - > insert_head ( l , " Bite " , sizeof ( char ) * 30 ) ;
printf ( " La taille est de %d \n " , l - > get_size ( l ) ) ;
printf ( " %s \n " , ( char * ) l - > get_head_data ( l ) ) ;
printf ( " %s \n " , ( char * ) l - > get_tail_data ( l ) ) ;
printf ( " %s \n " , ( char * ) l - > get_element_data ( l , 0 ) ) ;
printf ( " %s \n " , ( char * ) l - > get_element_data ( l , 1 ) ) ;
l - > insert_inside ( l , " Rigolo " , sizeof ( char ) * 30 , 2 ) ;
printf ( " %s \n " , ( char * ) l - > get_element_data ( l , 1 ) ) ;
printf ( " %s \n " , ( char * ) l - > get_element_data ( l , 3 ) ) ;
l - > remove_tail ( l ) ;
2018-06-04 22:26:48 +00:00
printf ( " La taille est de %d \n " , l - > get_size ( l ) ) ;
DELETE ( l ) ;
2018-06-06 18:29:02 +00:00
Building * main_building = NEW ( Building , " ../residents.txt " , " ../visitors.txt " ) ;
2018-06-06 01:00:35 +00:00
printf ( " Il y a %d étages dans l'immeuble \n " , main_building - > floors ) ;
2018-06-10 15:57:39 +00:00
printf ( " %s est le second visiteur, il veut aller voir %s \n " , ( ( Visitor * ) main_building - > visitors - > get_element_data ( main_building - > visitors , 1 ) ) - > name ,
( ( Visitor * ) main_building - > visitors - > get_element_data ( main_building - > visitors , 1 ) ) - > contact_name ) ;
printf ( " %s est le second resident, il veut aller à l'étage %d \n " , ( ( Resident * ) main_building - > residents - > get_element_data ( main_building - > residents , 1 ) ) - > name ,
( ( Resident * ) main_building - > residents - > get_element_data ( main_building - > residents , 1 ) ) - > destination ) ;
2018-06-07 20:04:30 +00:00
for ( int i = 0 ; i < ELEVATOR_NB ; i + + )
printf ( " Ascenseur %s \n " , main_building - > elevators [ i ] - > name ) ;
2018-06-06 01:00:35 +00:00
DELETE ( main_building ) ;
2018-06-04 22:26:48 +00:00
printf ( " Hello, World! \n " ) ;
2018-06-10 15:57:39 +00:00
printf ( " %s veut rentrer et aller voir %s \n " , roger - > get_name ( roger ) , roger - > contact_name ) ;
2018-06-06 18:29:02 +00:00
printf ( " %s habite dans l'appartement %d \n " , sli - > get_name ( sli ) , sli - > get_apartment_floor ( sli ) ) ;
2018-06-07 20:04:30 +00:00
2018-06-06 11:50:11 +00:00
DELETE ( GET_INSTANCE ( SharedData ) ) ;
2018-06-06 18:29:02 +00:00
DELETE ( roger ) ;
DELETE ( sli ) ;
2018-06-04 22:26:48 +00:00
return 0 ;
}