Cleanup - Multiple changes, see description
[tpg/opendispense2.git] / src / server / handler_door.c
1 /*
2  * OpenDispense 2 
3  * UCC (University [of WA] Computer Club) Electronic Accounting System
4  *
5  * handler_doror.c - Door Relay code
6  *
7  * This file is licenced under the 3-clause BSD Licence. See the file
8  * COPYING for full details.
9  */
10 #include "common.h"
11 #include <stdio.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16
17 // === IMPORTS ===
18
19 // === PROTOTYPES ===
20  int    Door_InitHandler();
21  int    Door_CanDispense(int User, int Item);
22  int    Door_DoDispense(int User, int Item);
23
24 // === GLOBALS ===
25 tHandler        gDoor_Handler = {
26         "door",
27         Door_InitHandler,
28         Door_CanDispense,
29         Door_DoDispense
30 };
31 //char  *gsDoor_SerialPort = "/dev/ttyS0";
32 // int  giDoor_SerialFD;
33
34 // == CODE ===
35 int Door_InitHandler()
36 {
37 //      printf("connecting to door...\n");
38 //      giDoor_SerialFD = open(gsDoor_SerialPort, O_RDWR);
39 //      if( giDoor_SerialFD == -1 ) {
40 //              fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsDoor_SerialPort);
41 //      }
42         return 0;
43 }
44
45 /**
46  */
47 int Door_CanDispense(int User, int Item)
48 {
49         // Sanity please
50         if( Item == 0 ) return -1;
51         
52         if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
53                 return 1;
54         
55         return 0;
56 }
57
58 /**
59  * \brief Actually do a dispense from the coke machine
60  */
61 int Door_DoDispense(int User, int Item)
62 {
63         // Sanity please
64         if( Item != 0 ) return -1;
65         
66         // Check if user is in door
67         if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
68                 return 1;
69         
70         // llogin or other
71
72         return 0;
73 }
74
75

UCC git Repository :: git.ucc.asn.au