2018-06-06 18:29:02 +00:00
//
// Created by Antoine Bartuccio on 06/06/2018.
//
# include "Visitor.h"
2018-06-11 08:52:58 +00:00
# include "../SharedData/SharedData.h"
2018-06-06 18:29:02 +00:00
# include <string.h>
GETTER ( Visitor , char * , name ) ;
2018-06-20 20:06:45 +00:00
GETTER ( Visitor , int , destination ) ;
2018-06-06 18:29:02 +00:00
GETTER ( Visitor , int , id ) ;
2018-06-10 23:58:52 +00:00
void * runnable_Visitor ( void * void_this ) {
Visitor * this = ( Visitor * ) void_this ;
2018-06-11 08:52:58 +00:00
SharedData * data = GET_INSTANCE ( SharedData ) ;
2018-06-20 17:36:00 +00:00
Passenger * passenger = NEW ( Passenger , ( void * ) this , VISITOR ) ;
2018-06-15 17:14:30 +00:00
2018-06-20 16:05:37 +00:00
AGENT_OPTIONS ;
2018-06-21 14:15:33 +00:00
this - > passenger = ( void * ) passenger ;
2018-06-15 17:14:30 +00:00
2018-06-20 17:36:00 +00:00
passenger - > visitor = this ;
2018-06-15 09:50:38 +00:00
2018-06-10 23:58:52 +00:00
printf ( " Bonjour, je suis %s et je souhaite rendre visite a %s \n " , this - > name , this - > contact_name ) ;
2018-06-15 09:50:38 +00:00
printf ( " Bip, %s appel a l'interphone \n %s habite a l'etage %d \n " , this - > name , this - > contact_name , ( this - > destination = data - > use_call_box ( data , this - > contact_name ) ) ) ;
2018-06-18 14:09:28 +00:00
data - > main_building - > go_to_floor ( data - > main_building , this - > position , this - > destination , passenger ) ;
2018-06-10 23:58:52 +00:00
return NULL ;
}
2018-06-06 18:29:02 +00:00
void _free__Visitor ( THIS ( Visitor ) ) {
if ( this - > name ! = NULL )
free ( this - > name ) ;
2018-06-10 15:57:39 +00:00
if ( this - > contact_name ! = NULL )
free ( this - > contact_name ) ;
2018-06-21 14:15:33 +00:00
if ( this - > passenger ! = NULL )
free ( this - > passenger ) ;
2018-06-06 18:29:02 +00:00
free ( this ) ;
}
2018-06-10 15:57:39 +00:00
Visitor * _init_Visitor ( int id , char * name , char * contact_name ) {
2018-06-06 18:29:02 +00:00
Visitor * new_visitor = malloc_or_die ( sizeof ( Visitor ) ) ;
2018-06-06 18:33:34 +00:00
new_visitor - > name = strdup ( name ) ;
2018-06-06 18:29:02 +00:00
new_visitor - > id = id ;
new_visitor - > position = 0 ;
new_visitor - > destination = - 1 ;
2018-06-21 14:15:33 +00:00
new_visitor - > passenger = NULL ;
2018-06-06 18:29:02 +00:00
2018-06-10 15:57:39 +00:00
if ( contact_name ! = NULL )
new_visitor - > contact_name = strdup ( contact_name ) ;
else
new_visitor - > contact_name = NULL ;
2018-06-06 18:29:02 +00:00
LINK_ALL ( Visitor , new_visitor ,
2018-06-20 20:06:45 +00:00
get_name ,
get_destination ,
get_id ,
runnable
2018-06-06 18:29:02 +00:00
) ;
return new_visitor ;
}