LO41/Resident/Resident.c

47 lines
1.1 KiB
C
Raw Normal View History

//
// Created by Antoine Bartuccio on 06/06/2018.
//
#include <string.h>
2018-06-15 17:14:30 +00:00
#include <pthread.h>
#include "Resident.h"
GETTER(Resident, char *, name);
GETTER(Resident, int, id);
GETTER(Resident, int, apartment_floor);
2018-06-10 23:58:52 +00:00
void * runnable_Resident(void * void_this){
Resident * this = (Resident*) void_this;
2018-06-15 17:14:30 +00:00
AGENT_OPTIONS
2018-06-11 00:31:03 +00:00
printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n",
2018-06-10 23:58:52 +00:00
this->name, this->apartment_floor, this->destination);
return NULL;
}
void _free__Resident(THIS(Resident)){
if (this->name != NULL)
free(this->name);
free(this);
}
2018-06-10 15:57:39 +00:00
Resident *_init_Resident(int id, char* name, int apartment_floor, int destination){
2018-06-11 00:01:56 +00:00
/* If the destination is the same as the apartment_floor or negative, the RESIDENT will not move */
Resident * new_resident = malloc_or_die(sizeof(Resident));
2018-06-06 18:33:34 +00:00
new_resident->name = strdup(name);
new_resident->id = id;
new_resident->apartment_floor = apartment_floor;
new_resident->position = new_resident->apartment_floor;
2018-06-10 15:57:39 +00:00
new_resident->destination = destination;
LINK_ALL(Resident, new_resident,
get_name,
get_id,
2018-06-10 23:58:52 +00:00
runnable,
get_apartment_floor
)
return new_resident;
}