2018-06-05 23:15:23 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 05/06/2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LO41_BUILDING_H
|
|
|
|
#define LO41_BUILDING_H
|
|
|
|
|
|
|
|
#define ELEVATOR_NB 3
|
2018-06-06 18:29:02 +00:00
|
|
|
#define FLOORS 25
|
2018-06-05 23:15:23 +00:00
|
|
|
|
|
|
|
#include "../Objects.h"
|
|
|
|
#include "../List/List.h"
|
|
|
|
#include "../Elevator/Elevator.h"
|
|
|
|
#include "../CommunicationBox/CommunicationBox.h"
|
2018-06-10 02:00:01 +00:00
|
|
|
#include "../Resident/Resident.h"
|
|
|
|
#include "../Visitor/Visitor.h"
|
|
|
|
|
2018-06-11 00:01:56 +00:00
|
|
|
typedef enum {RESIDENT, VISITOR} PASSENGER_TYPE;
|
2018-06-10 02:00:01 +00:00
|
|
|
|
|
|
|
typedef union u_Passenger {
|
|
|
|
Resident * resident;
|
|
|
|
Visitor * visitor;
|
|
|
|
} Passenger;
|
2018-06-05 23:15:23 +00:00
|
|
|
|
|
|
|
typedef struct o_Building {
|
2018-06-10 02:00:01 +00:00
|
|
|
PRIVATE int floors;
|
|
|
|
PRIVATE List * residents;
|
|
|
|
PRIVATE List * visitors;
|
|
|
|
PRIVATE CommunicationBox * box;
|
|
|
|
PRIVATE Elevator ** elevators;
|
|
|
|
PRIVATE pthread_mutex_t * mutex_get_inside_elevator;
|
|
|
|
PRIVATE pthread_mutex_t * mutex_get_outside_elevator;
|
|
|
|
PRIVATE pthread_cond_t ** condition_floors;
|
2018-06-06 01:00:35 +00:00
|
|
|
|
2018-06-06 18:29:02 +00:00
|
|
|
PRIVATE void (*parse_residents)(_THIS(Building), char * file);
|
|
|
|
PRIVATE void (*parse_visitors)(_THIS(Building), char * file);
|
2018-06-10 02:00:01 +00:00
|
|
|
PRIVATE int (*get_inside_elevator)(_THIS(Building), int current_floor, Passenger passenger, PASSENGER_TYPE type);
|
|
|
|
|
|
|
|
SYNCHRONIZE PUBLIC void (*go_to_floor)(_THIS(Building), int origin, int destination, Passenger passenger, PASSENGER_TYPE type);
|
2018-06-06 01:00:35 +00:00
|
|
|
|
|
|
|
DESTRUCTOR(Building);
|
2018-06-05 23:15:23 +00:00
|
|
|
} Building;
|
|
|
|
|
2018-06-10 23:58:52 +00:00
|
|
|
FRIENDLY(residents, SharedData)
|
|
|
|
FRIENDLY(visitors, SharedData)
|
|
|
|
FRIENDLY(elevators, SharedData)
|
|
|
|
|
2018-06-06 18:29:02 +00:00
|
|
|
Building *_init_Building(char * residents_file, char * visitors_file);
|
2018-06-05 23:15:23 +00:00
|
|
|
|
|
|
|
#endif //LO41_BUILDING_H
|