-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboard.cpp
executable file
·115 lines (95 loc) · 2.96 KB
/
Keyboard.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*************************************************************************
Keyboard - description
-------------------
date : Feb. 19 2014
copyright : (C) 2014 Yannick Marion & Gustave Monod
e-mail : [email protected]
*************************************************************************/
//-------- Realization of the <Keyboard> task (file Keyboard.cpp) --------
///////////////////////////////////////////////////////////////// INCLUDE
//--------------------------------------------------------- System include
#include <unistd.h> // for _exit
#include <cstdio> // for perror
#include <sys/ipc.h> // for all IPCS
#include <sys/msg.h> // for msgget
//------------------------------------------------------- Personal include
#include "Outils.h"
#include "Menu.h"
#include "Information.h"
#include "Keyboard.h"
///////////////////////////////////////////////////////////////// PRIVATE
//-------------------------------------------------------------- Constants
//------------------------------------------------------------------ Types
//------------------------------------------------------- Static variables
static int mbCommandId;
//------------------------------------------------------ Private functions
//static type name ( parameter list )
// How to use:
//
// Contract:
//
// Algorithm:
//
//{
//} //----- End of name
////////////////////////////////////////////////////////////////// PUBLIC
//------------------------------------------------------- Public functions
// type Name ( parameter list )
// Algorithm:
//
//{
//} //----- End of Name
void Keyboard ( )
// Algorithm:
// Infinitely asks the Menu for input
{
// Getting the mailbox for the commands
mbCommandId = msgget( ftok( PROGRAM_NAME, FTOK_CHAR ), RIGHTS );
for ( ; ; )
{
Menu( );
}
perror( "Error: exited the Keyboard loop" );
_exit( EXIT_FAILURE );
} //----- End of Keyboard
void Commande ( char code, unsigned int valeur )
// Algorithm:
// Checks the code and does the appropiate action
{
switch ( code )
{
case 'Q' :
_exit( EXIT_SUCCESS );
break;
case 'P' :
{
// The command to send:
struct EnterCommand command;
command.doorType = 1 == valeur ?
PROF_BLAISE_PASCAL : ENTREE_GASTON_BERGER;
command.userType = PROF;
msgsnd( mbCommandId, &command, ENTER_CMD_SIZE, IPC_NOWAIT );
break;
}
case 'A' :
{
// The command to send:
struct EnterCommand command;
command.doorType = 1 == valeur ?
AUTRE_BLAISE_PASCAL : ENTREE_GASTON_BERGER;
command.userType = AUTRE;
msgsnd( mbCommandId, &command, ENTER_CMD_SIZE, IPC_NOWAIT );
break;
}
case 'S' :
{
// The command to send:
struct ExitCommand command;
command.doorType = SORTIE_GASTON_BERGER;
command.position = valeur;
msgsnd( mbCommandId, &command, EXIT_CMD_SIZE, IPC_NOWAIT );
break;
}
}
} //----- End of Commande