tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
manager.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * manager.h
4  * -- Travel reservation resource manager
5  *
6  * =============================================================================
7  *
8  * Copyright (C) Stanford University, 2006. All Rights Reserved.
9  * Author: Chi Cao Minh
10  *
11  * =============================================================================
12  *
13  * For the license of bayes/sort.h and bayes/sort.c, please see the header
14  * of the files.
15  *
16  * ------------------------------------------------------------------------
17  *
18  * For the license of kmeans, please see kmeans/LICENSE.kmeans
19  *
20  * ------------------------------------------------------------------------
21  *
22  * For the license of ssca2, please see ssca2/COPYRIGHT
23  *
24  * ------------------------------------------------------------------------
25  *
26  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
27  * header of the files.
28  *
29  * ------------------------------------------------------------------------
30  *
31  * For the license of lib/rbtree.h and lib/rbtree.c, please see
32  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33  *
34  * ------------------------------------------------------------------------
35  *
36  * Unless otherwise noted, the following license applies to STAMP files:
37  *
38  * Copyright (c) 2007, Stanford University
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions are
43  * met:
44  *
45  * * Redistributions of source code must retain the above copyright
46  * notice, this list of conditions and the following disclaimer.
47  *
48  * * Redistributions in binary form must reproduce the above copyright
49  * notice, this list of conditions and the following disclaimer in
50  * the documentation and/or other materials provided with the
51  * distribution.
52  *
53  * * Neither the name of Stanford University nor the names of its
54  * contributors may be used to endorse or promote products derived
55  * from this software without specific prior written permission.
56  *
57  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
58  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
61  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
62  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
67  * THE POSSIBILITY OF SUCH DAMAGE.
68  *
69  * =============================================================================
70  */
71 
72 
73 #ifndef MANAGER_H
74 #define MANAGER_H 1
75 
76 
77 #include "map.h"
78 #include "tm.h"
79 #include "types.h"
80 
81 typedef struct manager {
82  MAP_T* carTablePtr;
83  MAP_T* roomTablePtr;
86 } manager_t;
87 
88 
89 /* =============================================================================
90  * manager_alloc
91  * =============================================================================
92  */
93 manager_t*
94 manager_alloc ();
95 
96 
97 /* =============================================================================
98  * manager_free
99  * =============================================================================
100  */
101 void
102 manager_free (manager_t* managerPtr);
103 
104 
105 /* =============================================================================
106  * ADMINISTRATIVE INTERFACE
107  * =============================================================================
108  */
109 
110 
111 /* =============================================================================
112  * manager_addCar
113  * -- Add cars to a city
114  * -- Adding to an existing car overwrite the price if 'price' >= 0
115  * -- Returns TRUE on success, else FALSE
116  * =============================================================================
117  */
119 bool_t
121  manager_t* managerPtr, long carId, long numCar, long price);
122 
123 bool_t
124 manager_addCar_seq (manager_t* managerPtr, long carId, long numCar, long price);
125 
126 
127 /* =============================================================================
128  * manager_deleteCar
129  * -- Delete cars from a city
130  * -- Decreases available car count (those not allocated to a customer)
131  * -- Fails if would make available car count negative
132  * -- If decresed to 0, deletes entire entry
133  * -- Returns TRUE on success, else FALSE
134  * =============================================================================
135  */
137 bool_t
138 manager_deleteCar (TM_ARGDECL manager_t* managerPtr, long carId, long numCar);
139 
140 
141 /* =============================================================================
142  * manager_addRoom
143  * -- Add rooms to a city
144  * -- Adding to an existing room overwrites the price if 'price' >= 0
145  * -- Returns TRUE on success, else FALSE
146  * =============================================================================
147  */
149 bool_t
151  manager_t* managerPtr, long roomId, long numRoom, long price);
152 
153 bool_t
154 manager_addRoom_seq (manager_t* managerPtr, long roomId, long numRoom, long price);
155 
156 
157 /* =============================================================================
158  * manager_deleteRoom
159  * -- Delete rooms from a city
160  * -- Decreases available room count (those not allocated to a customer)
161  * -- Fails if would make available room count negative
162  * -- If decresed to 0, deletes entire entry
163  * -- Returns TRUE on success, else FALSE
164  * =============================================================================
165  */
167 bool_t
168 manager_deleteRoom (TM_ARGDECL manager_t* managerPtr, long roomId, long numRoom);
169 
170 
171 /* =============================================================================
172  * manager_addFlight
173  * -- Add seats to a flight
174  * -- Adding to an existing flight overwrites the price if 'price' >= 0
175  * -- Returns TRUE on success, FALSE on failure
176  * =============================================================================
177  */
179 bool_t
181  manager_t* managerPtr, long flightId, long numSeat, long price);
182 
183 bool_t
184 manager_addFlight_seq (manager_t* managerPtr, long flightId, long numSeat, long price);
185 
186 
187 /* =============================================================================
188  * manager_deleteFlight
189  * -- Delete an entire flight
190  * -- Fails if customer has reservation on this flight
191  * -- Returns TRUE on success, else FALSE
192  * =============================================================================
193  */
195 bool_t
196 manager_deleteFlight (TM_ARGDECL manager_t* managerPtr, long flightId);
197 
198 
199 /* =============================================================================
200  * manager_addCustomer
201  * -- If customer already exists, returns success
202  * -- Returns TRUE on success, else FALSE
203  * =============================================================================
204  */
206 bool_t
207 manager_addCustomer (TM_ARGDECL manager_t* managerPtr, long customerId);
208 
209 bool_t
210 manager_addCustomer_seq (manager_t* managerPtr, long customerId);
211 
212 
213 /* =============================================================================
214  * manager_deleteCustomer
215  * -- Delete this customer and associated reservations
216  * -- If customer does not exist, returns success
217  * -- Returns TRUE on success, else FALSE
218  * =============================================================================
219  */
221 bool_t
222 manager_deleteCustomer (TM_ARGDECL manager_t* managerPtr, long customerId);
223 
224 
225 /* =============================================================================
226  * QUERY INTERFACE
227  * =============================================================================
228  */
229 
230 
231 /* =============================================================================
232  * manager_queryCar
233  * -- Return the number of empty seats on a car
234  * -- Returns -1 if the car does not exist
235  * =============================================================================
236  */
238 long
239 manager_queryCar (TM_ARGDECL manager_t* managerPtr, long carId);
240 
241 
242 /* =============================================================================
243  * manager_queryCarPrice
244  * -- Return the price of the car
245  * -- Returns -1 if the car does not exist
246  * =============================================================================
247  */
249 long
250 manager_queryCarPrice (TM_ARGDECL manager_t* managerPtr, long carId);
251 
252 
253 /* =============================================================================
254  * manager_queryRoom
255  * -- Return the number of empty seats on a room
256  * -- Returns -1 if the room does not exist
257  * =============================================================================
258  */
260 long
261 manager_queryRoom (TM_ARGDECL manager_t* managerPtr, long roomId);
262 
263 
264 /* =============================================================================
265  * manager_queryRoomPrice
266  * -- Return the price of the room
267  * -- Returns -1 if the room does not exist
268  * =============================================================================
269  */
271 long
272 manager_queryRoomPrice (TM_ARGDECL manager_t* managerPtr, long roomId);
273 
274 
275 /* =============================================================================
276  * manager_queryFlight
277  * -- Return the number of empty seats on a flight
278  * -- Returns -1 if the flight does not exist
279  * =============================================================================
280  */
282 long
283 manager_queryFlight (TM_ARGDECL manager_t* managerPtr, long flightId);
284 
285 
286 /* =============================================================================
287  * manager_queryFlightPrice
288  * -- Return the price of the flight
289  * -- Returns -1 if the flight does not exist
290  * =============================================================================
291  */
293 long
294 manager_queryFlightPrice (TM_ARGDECL manager_t* managerPtr, long flightId);
295 
296 
297 /* =============================================================================
298  * manager_queryCustomerBill
299  * -- Return the total price of all reservations held for a customer
300  * -- Returns -1 if the customer does not exist
301  * =============================================================================
302  */
304 long
305 manager_queryCustomerBill (TM_ARGDECL manager_t* managerPtr, long customerId);
306 
307 
308 /* =============================================================================
309  * RESERVATION INTERFACE
310  * =============================================================================
311  */
312 
313 
314 /* =============================================================================
315  * manager_reserveCar
316  * -- Returns failure if the car or customer does not exist
317  * -- Returns TRUE on success, else FALSE
318  * =============================================================================
319  */
321 bool_t
323  manager_t* managerPtr, long customerId, long carId);
324 
325 
326 /* =============================================================================
327  * manager_reserveRoom
328  * -- Returns failure if the room or customer does not exist
329  * -- Returns TRUE on success, else FALSE
330  * =============================================================================
331  */
333 bool_t
335  manager_t* managerPtr, long customerId, long roomId);
336 
337 
338 /* =============================================================================
339  * manager_reserveFlight
340  * -- Returns failure if the flight or customer does not exist
341  * -- Returns TRUE on success, else FALSE
342  * =============================================================================
343  */
345 bool_t
347  manager_t* managerPtr, long customerId, long flightId);
348 
349 
350 /* =============================================================================
351  * manager_cancelCar
352  * -- Returns failure if the car, reservation, or customer does not exist
353  * -- Returns TRUE on success, else FALSE
354  * =============================================================================
355  */
357 bool_t
359  manager_t* managerPtr, long customerId, long carId);
360 
361 
362 /* =============================================================================
363  * manager_cancelRoom
364  * -- Returns failure if the room, reservation, or customer does not exist
365  * -- Returns TRUE on success, else FALSE
366  * =============================================================================
367  */
369 bool_t
371  manager_t* managerPtr, long customerId, long roomId);
372 
373 
374 /* =============================================================================
375  * manager_cancelFlight
376  * -- Returns failure if the flight, reservation, or customer does not exist
377  * -- Returns TRUE on success, else FALSE
378  * =============================================================================
379  */
381 bool_t
383  manager_t* managerPtr, long customerId, long flightId);
384 
385 
386 #define MANAGER_ADD_CAR(mgr, id, num, price) \
387  manager_addCar(TM_ARG mgr, id, num, price)
388 #define MANAGER_DELETE_CAR(mgr, id, num) \
389  manager_deleteCar(TM_ARG mgr, id, num)
390 #define MANAGER_ADD_ROOM(mgr, id, num, price) \
391  manager_addRoom(TM_ARG mgr, id, num, price)
392 #define MANAGER_DELETE_ROOM(mgr, id, num) \
393  manager_deleteRoom(TM_ARG mgr, id, num)
394 #define MANAGER_ADD_FLIGHT(mgr, id, num, price) \
395  manager_addFlight(TM_ARG mgr, id, num, price)
396 #define MANAGER_DELETE_FLIGHT(mgr, id) \
397  manager_deleteFlight(TM_ARG mgr, id)
398 #define MANAGER_ADD_CUSTOMER(mgr, id) \
399  manager_addCustomer(TM_ARG mgr, id)
400 #define MANAGER_DELETE_CUSTOMER(mgr, id) \
401  manager_deleteCustomer(TM_ARG mgr, id)
402 #define MANAGER_QUERY_CAR(mgr, id) \
403  manager_queryCar(TM_ARG mgr, id)
404 #define MANAGER_QUERY_CAR_PRICE(mgr, id) \
405  manager_queryCarPrice(TM_ARG mgr, id)
406 #define MANAGER_QUERY_ROOM(mgr, id) \
407  manager_queryRoom(TM_ARG mgr, id)
408 #define MANAGER_QUERY_ROOM_PRICE(mgr, id) \
409  manager_queryRoomPrice(TM_ARG mgr, id)
410 #define MANAGER_QUERY_FLIGHT(mgr, id) \
411  manager_queryFlight(TM_ARG mgr, id)
412 #define MANAGER_QUERY_FLIGHT_PRICE(mgr, id) \
413  manager_queryFlightPrice(TM_ARG mgr, id)
414 #define MANAGER_QUERY_CUSTOMER_BILL(mgr, id) \
415  manager_queryCustomerBill(TM_ARG mgr, id)
416 #define MANAGER_RESERVE_CAR(mgr, cust, id) \
417  manager_reserveCar(TM_ARG mgr, cust, id)
418 #define MANAGER_RESERVE_ROOM(mgr, cust, id) \
419  manager_reserveRoom(TM_ARG mgr, cust, id)
420 #define MANAGER_RESERVE_FLIGHT(mgr, cust, id) \
421  manager_reserveFlight(TM_ARG mgr, cust, id)
422 #define MANAGER_CANCEL_CAR(mgr, cust, id) \
423  manager_cancelCar(TM_ARG mgr, cust, id)
424 #define MANAGER_CANCEL_ROOM(mgr, cust, id) \
425  manager_cancelRoom(TM_ARG mgr, cust, id)
426 #define MANAGER_CANCEL_FLIGHT(mgr, cust, id) \
427  manager_cancelFlight(TM_ARG mgr, cust, id)
428 
429 
430 #endif /* MANAGER_H */
431 
432 
433 /* =============================================================================
434  *
435  * End of manager.h
436  *
437  * =============================================================================
438  */
#define TM_CALLABLE
Definition: cxxtm.hpp:32
bool_t manager_addCustomer_seq(manager_t *managerPtr, long customerId)
Definition: manager.c:403
TM_CALLABLE bool_t manager_addRoom(TM_ARGDECL manager_t *managerPtr, long roomId, long numRoom, long price)
Definition: manager.c:291
manager_t * manager_alloc()
Definition: manager.c:116
Definition: manager.h:81
TM_CALLABLE long manager_queryCarPrice(TM_ARGDECL manager_t *managerPtr, long carId)
Definition: manager.c:543
MAP_T * carTablePtr
Definition: manager.h:82
TM_CALLABLE bool_t manager_reserveFlight(TM_ARGDECL manager_t *managerPtr, long customerId, long flightId)
Definition: manager.c:718
bool_t manager_addRoom_seq(manager_t *managerPtr, long roomId, long numRoom, long price)
Definition: manager.c:299
int bool_t
Definition: portable_defns.h:32
#define TM_ARGDECL
Definition: tm.h:532
TM_CALLABLE bool_t manager_reserveCar(TM_ARGDECL manager_t *managerPtr, long customerId, long carId)
Definition: manager.c:682
TM_CALLABLE long manager_queryFlightPrice(TM_ARGDECL manager_t *managerPtr, long flightId)
Definition: manager.c:595
MAP_T * roomTablePtr
Definition: manager.h:83
TM_CALLABLE bool_t manager_cancelFlight(TM_ARGDECL manager_t *managerPtr, long customerId, long flightId)
Definition: manager.c:815
TM_CALLABLE long manager_queryFlight(TM_ARGDECL manager_t *managerPtr, long flightId)
Definition: manager.c:582
void manager_free(manager_t *managerPtr)
Definition: manager.c:154
TM_CALLABLE bool_t manager_addFlight(TM_ARGDECL manager_t *managerPtr, long flightId, long numSeat, long price)
Definition: manager.c:331
TM_CALLABLE bool_t manager_deleteFlight(TM_ARGDECL manager_t *managerPtr, long flightId)
Definition: manager.c:354
MAP_T * flightTablePtr
Definition: manager.h:84
TM_CALLABLE long manager_queryCar(TM_ARGDECL manager_t *managerPtr, long carId)
Definition: manager.c:530
TM_CALLABLE bool_t manager_addCustomer(TM_ARGDECL manager_t *managerPtr, long customerId)
Definition: manager.c:382
bool_t manager_addFlight_seq(manager_t *managerPtr, long flightId, long numSeat, long price)
Definition: manager.c:340
TM_CALLABLE bool_t manager_deleteRoom(TM_ARGDECL manager_t *managerPtr, long roomId, long numRoom)
Definition: manager.c:316
struct manager manager_t
TM_CALLABLE long manager_queryRoomPrice(TM_ARGDECL manager_t *managerPtr, long roomId)
Definition: manager.c:569
TM_CALLABLE bool_t manager_cancelCar(TM_ARGDECL manager_t *managerPtr, long customerId, long carId)
Definition: manager.c:778
TM_CALLABLE bool_t manager_reserveRoom(TM_ARGDECL manager_t *managerPtr, long customerId, long roomId)
Definition: manager.c:700
TM_CALLABLE bool_t manager_cancelRoom(TM_ARGDECL manager_t *managerPtr, long customerId, long roomId)
Definition: manager.c:796
TM_CALLABLE bool_t manager_addCar(TM_ARGDECL manager_t *managerPtr, long carId, long numCar, long price)
Definition: manager.c:252
MAP_T * customerTablePtr
Definition: manager.h:85
TM_CALLABLE long manager_queryCustomerBill(TM_ARGDECL manager_t *managerPtr, long customerId)
Definition: manager.c:608
TM_CALLABLE bool_t manager_deleteCar(TM_ARGDECL manager_t *managerPtr, long carId, long numCar)
Definition: manager.c:276
TM_CALLABLE bool_t manager_deleteCustomer(TM_ARGDECL manager_t *managerPtr, long customerId)
Definition: manager.c:429
bool_t manager_addCar_seq(manager_t *managerPtr, long carId, long numCar, long price)
Definition: manager.c:260
TM_CALLABLE long manager_queryRoom(TM_ARGDECL manager_t *managerPtr, long roomId)
Definition: manager.c:556