-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
124 lines (92 loc) · 2.37 KB
/
server.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
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
115
116
117
118
119
120
121
122
123
124
#ifndef STORE_OPERATIONS_H
#define STORE_OPERATIONS_H
// Error codes
#define SO_SUCCESS 0
#define SO_FILE_ERROR 1
//Inventory error codes
#define INVENTORY_ADD_FAILED 2
#define INVENTORY_ITEM_NOT_FOUND 3
#define INVENTORY_ALREADY_OPEN 4
#define INVENTORY_NOT_OPEN 5
#define INVENTORY_DELETE_FAILED 6
//Cart error codes
#define CART_ADD_FAILED 7
#define CART_ITEM_NOT_FOUND 8
#define CART_ALREADY_OPEN 9
#define CART_NOT_OPEN 10
#define INV_NDX_SAVE_FAILED 11
#define CART_NDX_SAVE_FAILED 12
// Status values
#define INVENTORY_OPEN 13
#define INVENTORY_CLOSED 14
#define CART_OPEN 15
#define CART_CLOSED 16
#define BUY_FAILED 17
#define MAX_INVENTORY_SIZE 100
#define MAX_FREE 100 // Maximum of deleted entries info
#define MAX_CARTS 100 // Maximum number items in a cart
#define MAX_CART_SIZE 10 // Maximum number items in a cart
#define PORT_NO 7762
struct InventoryItem
{
int productID;
char productName[100];
int price;
int valid;
};
struct InventoryInfo
{
int inv_data_fd;
int inv_quantity_fd;
int inv_status;
int inv_entry_size; // size of one inventory entry
int inv_count; // For the number of items in the inventory, to be incremented each time an item is added by the admin
};
struct InventoryCount
{
char prodName[100];
int quantity;
};
extern struct InventoryInfo inv_handle;
struct CartEntry
{
char prodName[100];
int price;
int amount;
};
struct Cart
{
int custID;
struct CartEntry cartItems[MAX_CART_SIZE];
int noOfProducts;
};
struct CartInfo
{
int cart_data_fd;
int cart_ndx_fd;
int cart_status;
int cart_entry_size; //size of one cart entry
int cart_count; //number of entries in the cart file
};
extern struct CartInfo cart_handle;
int inv_create();
int inv_open();
int inv_quantity_load();
int inv_add(int prodID,char* prodName,int price);
int inv_delete(int prodID);
int inv_update(int prodID,char* prodName, int price);
int inv_add_quantity(char prodName[],int quantity,int price);
int inv_display();
int inv_close();
int cart_create();
int cart_open();
int cart_load_ndx();
int cart_add(int custID,char prodName[],int price, int quantity);
int cart_edit_quantity(int custID, char prodName[], int quantity);
int cart_display(int custID, int nsd);
int cart_delete_item(int custID, char prodName[]);
int insert_cart(struct Cart* cart);
int cart_get_rec(int id, struct Cart *cart);
int cart_update(struct Cart *cart);
int cart_close();
#endif