-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.h
86 lines (67 loc) · 1.47 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef UTILS_H
#define UTILS_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include<pthread.h>
#include <semaphore.h>
#define PERMISSOES_MODE 0660
typedef struct
{
//numero de serie do pedido
unsigned int serial_num;
//sexo da pessoa ('F' ou 'M')
char sex;
//duracao da utilizacao
int duration;
//numero de rejeicoes (entre 0 e 3)
int rejeicoes;
} PEDIDO;
char FIFO_ENTRADA[] = "/tmp/entrada";
char FIFO_REJEITADOS[] = "/tmp/rejeitados";
int fd_fifo_entrada;
int fd_fifo_rejeitados;
int fifo_init()
{
int error_fifos;
error_fifos = mkfifo(FIFO_ENTRADA, PERMISSOES_MODE);
if (error_fifos < 0 && errno != EEXIST )
{
perror("ERRO FIFO ENTRADA: ");
return -1;
}
error_fifos = mkfifo(FIFO_REJEITADOS, PERMISSOES_MODE);
if (error_fifos < 0 && errno != EEXIST )
{
perror("ERRO FIFO REJEITADOS: ");
return -1;
}
return 0;
}
int fifo_destroy(){
int error_fifos;
error_fifos = unlink(FIFO_ENTRADA);
if (error_fifos < 0 && errno != ENOENT && errno != EBUSY)
{
perror("ERRO AO APAGAR FIFO ENTRADA: ");
}
error_fifos = unlink(FIFO_REJEITADOS);
if (error_fifos < 0 && errno != ENOENT && errno != EBUSY)
{
perror("ERRO AO APAGAR FIFO REJEITADOS: ");
}
return 0;
}
float convertToMilliseconds(struct timespec t){
float res;
res=(t.tv_sec * 1000);
res+=((float)t.tv_nsec / 1000000);
return res;
}
#endif /* UTILS_H */