2018-06-05 23:15:23 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 05/06/2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LO41_ELEVATOR_H
|
|
|
|
#define LO41_ELEVATOR_H
|
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
#include <pthread.h>
|
2018-06-05 23:15:23 +00:00
|
|
|
#include "../Objects.h"
|
2018-06-07 20:04:30 +00:00
|
|
|
#include "../List/List.h"
|
2018-06-18 13:51:48 +00:00
|
|
|
#include "../Passenger/Passenger.h"
|
2018-06-07 20:04:30 +00:00
|
|
|
|
2018-06-15 09:50:38 +00:00
|
|
|
//#define MAX_ELEVATOR_CAPACITY 10
|
2018-06-21 23:35:46 +00:00
|
|
|
#define MAX_ELEVATOR_CAPACITY 12
|
2018-06-07 20:04:30 +00:00
|
|
|
|
2018-06-15 09:50:38 +00:00
|
|
|
typedef enum {RUNNING, WAITING, SLEEPING, BROKEN} ELEVATOR_STATE;
|
2018-06-05 23:15:23 +00:00
|
|
|
|
|
|
|
typedef struct o_Elevator {
|
2018-06-07 20:04:30 +00:00
|
|
|
PRIVATE ELEVATOR_STATE state;
|
2018-06-18 13:51:48 +00:00
|
|
|
PRIVATE List * passengers;
|
2018-06-07 20:04:30 +00:00
|
|
|
PRIVATE char * name;
|
2018-06-10 02:00:01 +00:00
|
|
|
PRIVATE int floor;
|
2018-06-21 15:39:30 +00:00
|
|
|
PRIVATE int target_floor;
|
2018-06-22 00:50:04 +00:00
|
|
|
PRIVATE int thread_number;
|
2018-06-18 17:24:35 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_passengers;
|
2018-06-07 22:08:18 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_state;
|
2018-06-10 02:00:01 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_floor;
|
2018-06-05 23:15:23 +00:00
|
|
|
|
2018-06-07 22:08:18 +00:00
|
|
|
PUBLIC void * (*runnable)(void * void_this);
|
2018-06-22 00:50:04 +00:00
|
|
|
PUBLIC void (*set_thread_number)(_THIS(Elevator), int data);
|
2018-06-07 22:08:18 +00:00
|
|
|
|
|
|
|
SYNCHRONIZE PRIVATE void (*set_state)(_THIS(Elevator), ELEVATOR_STATE var);
|
2018-06-10 10:47:07 +00:00
|
|
|
SYNCHRONIZE PRIVATE void (*set_floor)(_THIS(Elevator), int var);
|
2018-06-21 15:39:30 +00:00
|
|
|
SYNCHRONIZE PRIVATE int (*get_next_passenger_stop)(_THIS(Elevator));
|
2018-06-07 22:08:18 +00:00
|
|
|
|
|
|
|
SYNCHRONIZE PUBLIC void (*repair)(_THIS(Elevator));
|
2018-06-22 01:59:36 +00:00
|
|
|
SYNCHRONIZE PUBLIC void (*damage)(_THIS(Elevator));
|
2018-06-07 20:04:30 +00:00
|
|
|
SYNCHRONIZE PUBLIC int (*get_number_of_passengers)(_THIS(Elevator));
|
2018-06-21 18:26:35 +00:00
|
|
|
SYNCHRONIZE PUBLIC void (*remove_passenger) (_THIS(Elevator), Passenger * passenger);
|
2018-06-20 17:36:00 +00:00
|
|
|
SYNCHRONIZE PUBLIC void (*add_passenger)(_THIS(Elevator), Passenger * passenger);
|
2018-06-07 22:08:18 +00:00
|
|
|
SYNCHRONIZE PUBLIC ELEVATOR_STATE (*get_state)(_THIS(Elevator));
|
2018-06-10 02:00:01 +00:00
|
|
|
SYNCHRONIZE PUBLIC int (*get_floor)(_THIS(Elevator));
|
2018-06-15 13:38:26 +00:00
|
|
|
SYNCHRONIZE PUBLIC int (*can_get_inside)(_THIS(Elevator), int floor);
|
2018-06-06 01:00:35 +00:00
|
|
|
DESTRUCTOR(Elevator);
|
2018-06-07 22:08:18 +00:00
|
|
|
|
2018-06-05 23:15:23 +00:00
|
|
|
} Elevator;
|
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
FRIENDLY(state, Building)
|
|
|
|
|
|
|
|
Elevator *_init_Elevator(char* name);
|
2018-06-06 01:00:35 +00:00
|
|
|
|
2018-06-05 23:15:23 +00:00
|
|
|
#endif //LO41_ELEVATOR_H
|