forked from Dracotz/SDE-hUberT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhubert.c
73 lines (51 loc) · 1.35 KB
/
hubert.c
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
#include <stdio.h>
#include <stdlib.h>
#include "message.h"
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <signal.h>
#include "hubert.h"
#include <time.h>
#include <string.h>
int main(){
int i ;
for(i=0;i<N_USERS_MAX;i++){
usersId[i]=0;
}
for(i=0;i<N_RESTOS_MAX;i++){
restosId[i]=0;
strcpy(nomsRestos[i],"");
}
nUsersConnected=0;
nRestosConnected=0;
connected = 1;
idFileUser = createFilePublicUser();
idFileResto = createFilePublicResto();
MsgText msgText;
msgText.type = 1;
signal(2,disconnectAll);
while(connected!=0){
carePublicResto(idFileResto);
carePublicUser(idFileUser);
for(i=0;i<N_USERS_MAX;i++){
if(usersId[i]!=0){
if(fileEmpty(usersId[i]) != 1){
printf("Message repéré par hubert dans file priv user %d\n",i);
msgrcv(usersId[i],&msgText,sizeof(msgText.cmd),0,0);
printf("Message recu, type=%ld, cmd = %s\n",msgText.type,msgText.cmd);
}
}
}
for(i=0;i<N_RESTOS_MAX;i++){
if(restosId[i]!=0){
if(fileEmpty(restosId[i]) != 1){
printf("Message repéré par hubert dans file priv resto %d\n",i);
msgrcv(restosId[i],&msgText,sizeof(msgText.cmd),0,0);
printf("Message recu, type=%ld, cmd = %s\n",msgText.type,msgText.cmd);
}
}
}
}
return 0;
}