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

48 lines
1.2 KiB
C

//
// Created by Antoine Bartuccio on 06/06/2018.
//
#include "Visitor.h"
#include "../SharedData/SharedData.h"
#include <string.h>
GETTER(Visitor, char*, name);
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->use_call_box(data, this->contact_name));
return NULL;
}
void _free__Visitor(THIS(Visitor)){
if (this->name != NULL)
free(this->name);
if (this->contact_name != NULL)
free(this->contact_name);
free(this);
}
Visitor *_init_Visitor(int id, char* name, char * contact_name){
Visitor * new_visitor = malloc_or_die(sizeof(Visitor));
new_visitor->name = strdup(name);
new_visitor->id = id;
new_visitor->position = 0;
new_visitor->destination = -1;
if (contact_name != NULL)
new_visitor->contact_name = strdup(contact_name);
else
new_visitor->contact_name = NULL;
LINK_ALL(Visitor, new_visitor,
get_name,
get_id,
runnable
);
return new_visitor;
}