Added periodic thread (reloads item config, checks coke slots)
[tpg/opendispense2.git] / src / server / common.h
1 /*
2  * OpenDispense2
3  *
4  * This code is published under the terms of the Acess licence.
5  * See the file COPYING for details.
6  *
7  * common.h - Core Header
8  */
9 #ifndef _COMMON_H_
10 #define _COMMON_H_
11
12 #include <regex.h>
13 #include "../cokebank.h"
14
15 // === CONSTANTS ===
16 #define DEFAULT_CONFIG_FILE     "/etc/opendispense/main.cfg"
17 #define DEFAULT_ITEM_FILE       "/etc/opendispense/items.cfg"
18
19 // === HELPER MACROS ===
20 #define _EXPSTR(x)      #x
21 #define EXPSTR(x)       _EXPSTR(x)
22
23 #define UNUSED(var)     unused__##var __attribute__((__unused__))
24
25 // === STRUCTURES ===
26 typedef struct sItem    tItem;
27 typedef struct sUser    tUser;
28 typedef struct sConfigItem      tConfigItem;
29 typedef struct sHandler tHandler;
30
31 struct sItem
32 {
33         char    *Name;  //!< Display Name
34          int    Price;  //!< Price
35          int    bHidden;        //!< Hidden item?
36         
37         tHandler        *Handler;       //!< Handler for the item
38         short   ID;     //!< Item ID
39 };
40
41 struct sUser
42 {
43          int    ID;             //!< User ID (LDAP ID)
44          int    Balance;        //!< Balance in cents
45          int    Bytes;  //!< Traffic Usage
46         char    Name[]; //!< Username
47 };
48
49 struct sConfigItem
50 {
51         char    *Name;
52         char    *Value;
53 };
54
55 struct sHandler
56 {
57         char    *Name;
58          int    (*Init)(int NConfig, tConfigItem *Config);
59         /**
60          * \brief Check if an item can be dispensed
61          * \return Boolean Failure
62          */
63          int    (*CanDispense)(int User, int ID);
64          int    (*DoDispense)(int User, int ID);
65 };
66
67 // === GLOBALS ===
68 extern tItem    *gaItems;
69 extern int      giNumItems;
70 extern tHandler *gaHandlers[];
71 extern int      giNumHandlers;
72 extern int      giDebugLevel;
73
74 // === FUNCTIONS ===
75 // --- Helpers --
76 extern void     AddPeriodicFunction(void (*Fcn)(void));
77 extern void     CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
78 extern int      RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
79 extern int      InitSerial(const char *Path, int BaudRate);
80 extern char     *mkstr(const char *Format, ...);
81
82 // --- Dispense ---
83 extern int      DispenseItem(int ActualUser, int User, tItem *Item);
84 extern int      DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven);
85 extern int      DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven);
86 extern int      DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven);
87 extern int      DispenseDonate(int ActualUser, int User, int Ammount, const char *ReasonGiven);
88
89 // --- Logging ---
90 extern void     Log_Error(const char *Format, ...);
91 extern void     Log_Info(const char *Format, ...);
92
93 #endif

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