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"
|
|
|
|
|
|
|
|
#define MAX_ELEVATOR_CAPACITY 10
|
|
|
|
|
2018-06-07 22:08:18 +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;
|
|
|
|
PRIVATE List * passenger_ids;
|
|
|
|
PRIVATE char * name;
|
2018-06-10 02:00:01 +00:00
|
|
|
PRIVATE int floor;
|
2018-06-07 22:08:18 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_passenger;
|
|
|
|
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);
|
|
|
|
|
|
|
|
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-07 22:08:18 +00:00
|
|
|
|
|
|
|
SYNCHRONIZE PUBLIC void (*repair)(_THIS(Elevator));
|
2018-06-07 20:04:30 +00:00
|
|
|
SYNCHRONIZE PUBLIC int (*get_number_of_passengers)(_THIS(Elevator));
|
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-07 20:05:39 +00:00
|
|
|
SYNCHRONIZE PUBLIC int (*can_get_more_passengers)(_THIS(Elevator));
|
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
|