1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2024-11-14 12:53:22 +00:00
LO41/main.c

79 lines
2.4 KiB
C

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "Objects.h"
#include "List/List.h"
#include "Building/Building.h"
#include "SharedData/SharedData.h"
#include "Visitor/Visitor.h"
#include "Resident/Resident.h"
pthread_cond_t cond;
void * test_sub(void *bite){
usleep(2000000);
printf("Je relache le programme\n");
pthread_cond_signal(&cond);
return bite;
}
void clean_exit(int error_code){
printf("Signal %d received, exiting app\n", error_code);
DELETE(GET_INSTANCE(SharedData));
exit(0);
}
int main() {
List *l = NEW(List);
Visitor * roger = NEW(Visitor, 8, "Roger");
Resident * sli = NEW(Resident, 1, "Sli", 2);
char text1[30] = "Patate";
char text2[30] = "Patator";
pthread_mutex_t mutex;
pthread_t thread;
GET_INSTANCE(SharedData);
signal(SIGINT, clean_exit);
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
printf("La taille est de %d\n", l->get_size(l));
pthread_create(&thread, 0, test_sub, NULL);
printf("FREEEZZZE\n");
pthread_cond_wait(&cond, &mutex);
pthread_cond_destroy(&cond);
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);
printf("La taille est de %d\n", l->get_size(l));
DELETE(l);
Building *main_building = NEW(Building, "../residents.txt", "../visitors.txt");
printf("Il y a %d étages dans l'immeuble\n", main_building->floors);
printf("%s est le second visiteur\n", ((Visitor *) main_building->visitors->get_element_data(main_building->visitors, 1))->name);
printf("%s est le second resident\n", ((Resident *) main_building->residents->get_element_data(main_building->residents, 1))->name);
for (int i=0; i < ELEVATOR_NB; i++)
printf("Ascenseur %s\n", main_building->elevators[i]->name);
DELETE(main_building);
printf("Hello, World!\n");
printf("%s veut rentrer\n", roger->get_name(roger));
printf("%s habite dans l'appartement %d\n", sli->get_name(sli), sli->get_apartment_floor(sli));
DELETE(GET_INSTANCE(SharedData));
DELETE(roger);
DELETE(sli);
return 0;
}