home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / ada / library / bd3 / bd3.lst < prev    next >
File List  |  1989-03-12  |  22KB  |  541 lines

  1.   1 package BANK is
  2.   2 ------------------------------------------------------------------------
  3.   3 --| BEGIN PROLOGUE
  4.   4 --| DESCRIPTION            : BANK defines a bank, the TELLER objects
  5.   5 --|                        : within it, and the procedure PRINT_REPORT
  6.   6 --|                        : (which reports on the status of the BANK).
  7.   7 --|                        :
  8.   8 --|                        : BANK is an abstract state machine, defining
  9.   9 --|                        : a BANK object which contains TELLER objects.
  10.  10 --|                        :
  11.  11 --| REQUIREMENTS SUPPORTED : Bank Demonstration Program to show
  12.  12 --|                        : object-oriented design and tasking
  13.  13 --|                        : with Ada
  14.  14 --|                        :
  15.  15 --| LIMITATIONS            : None
  16.  16 --| AUTHOR(S)              : Richard Conn (RLC)
  17.  17 --| CHANGE LOG             : 1/16/89  RLC  Initial Design and Code
  18.  18 --| CHANGE LOG             : 2/25/89  RLC  Final Review Prior to Release
  19.  19 --| REMARKS                : None
  20.  20 --| PORTABILITY ISSUES     : None
  21.  21 --| END PROLOGUE
  22.  22 ------------------------------------------------------------------------
  23.  23  
  24.  24     -- TRANSACTION requested of a TELLER
  25.  25     type TRANSACTION  is (ADD_NEW_CUSTOMER,
  26.  26                           GET_BALANCE,
  27.  27                           MAKE_DEPOSIT,
  28.  28                           MAKE_WITHDRAWAL);
  29.  29  
  30.  30     -- Unit of currency
  31.  31     type DOLLAR       is new FLOAT;
  32.  32  
  33.  33     -- Identification of a CUSTOMER
  34.  34     type CUSTOMER_ID  is new NATURAL range 1 .. NATURAL'LAST;
  35.  35  
  36.  36     -- Index of and Number of TELLER objects within the bank
  37.  37     type TELLER_INDEX is new NATURAL range 1 .. 4;
  38.  38  
  39.  39     -- A TELLER_PERSON is an object to which a CUSTOMER may make a REQUEST
  40.  40     -- The BANK tells the TELLER_PERSON to START_WORK, giving the
  41.  41     -- TELLER_PERSON its TELLER_NUMBER
  42.  42     task type TELLER_PERSON is
  43.  43     entry REQUEST(ID     : in out CUSTOMER_ID;
  44.  44               KIND   : in TRANSACTION;
  45.  45               AMOUNT : in out DOLLAR);
  46.  46     end TELLER_PERSON;
  47.  47     -- These are the TELLER objects available at the bank
  48.  48     TELLER : array(TELLER_INDEX) of TELLER_PERSON;
  49.  49  
  50.  50     -- PRINT_REPORT gives the transaction log of all the bank
  51.  51     -- customers
  52.  52     procedure PRINT_REPORT;
  53.  53  
  54.  54     -- STOP_WORK terminates all TELLER tasks
  55.  55     procedure STOP_WORK;
  56.  56 end BANK;
  57.  57 -- 
  58.  58 with CONSOLE;
  59.  59 package body BANK is
  60.  60 ------------------------------------------------------------------------
  61.  61 --| BEGIN PROLOGUE
  62.  62 --| DESCRIPTION            : Package Body BANK implements the TELLER
  63.  63 --|                        : tasks and the PRINT_REPORT procedure.
  64.  64 --|                        : CUSTOMER data is maintained within the
  65.  65 --|                        : BANK as a linked list.
  66.  66 --|                        :
  67.  67 --| REQUIREMENTS SUPPORTED : Bank Demonstration Program to show
  68.  68 --|                        : object-oriented design and tasking
  69.  69 --|                        : with Ada
  70.  70 --|                        :
  71.  71 --| LIMITATIONS            : None
  72.  72 --| AUTHOR(S)              : Richard Conn (RLC)
  73.  73 --| CHANGE LOG             : 1/16/89  RLC  Initial Design and Code
  74.  74 --| CHANGE LOG             : 2/25/89  RLC  Final Review Prior to Release
  75.  75 --| REMARKS                : None
  76.  76 --| PORTABILITY ISSUES     : Uses CONSOLE (TEXT_IO), so is very portable;
  77.  77 --|                        : no known portability problems.
  78.  78 --| END PROLOGUE
  79.  79 ------------------------------------------------------------------------
  80.  80  
  81.  81     -- Identifier of next customer
  82.  82     NEXT_ID                  : CUSTOMER_ID           := CUSTOMER_ID'FIRST;
  83.  83  
  84.  84     -- Linked list of customer data
  85.  85     type CUSTOMER_DATA;
  86.  86     type CUSTOMER_DATA_POINTER is access CUSTOMER_DATA;
  87.  87     type CUSTOMER_DATA is record
  88.  88     ID                  : CUSTOMER_ID;
  89.  89     BALANCE             : DOLLAR                := 0.0;
  90.  90     TRANSACTION_COUNT   : NATURAL               := 0;
  91.  91     ATTEMPTED_OVERDRAWS : NATURAL               := 0;
  92.  92     NEXT                : CUSTOMER_DATA_POINTER := null;
  93.  93     end record;
  94.  94  
  95.  95     -- Count of number of transactions for each TELLER object
  96.  96     TELLER_TRANSACTION_COUNT : array(TELLER_INDEX) of NATURAL 
  97.  97       := (others => 0);
  98.  98  
  99.  99     -- Pointers to first and last customer data entries
  100. 100     FIRST_CUSTOMER           : CUSTOMER_DATA_POINTER := null;
  101. 101     LAST_CUSTOMER            : CUSTOMER_DATA_POINTER := null;
  102. 102  
  103. 103 -- 
  104. 104 -- package body BANK
  105. 105     -- Print a report of the status of the BANK
  106. 106     procedure PRINT_REPORT is
  107. 107     CURRENT_CUSTOMER : CUSTOMER_DATA_POINTER;
  108. 108     begin
  109. 109  
  110. 110         -- Check for any customers and issue an error message if none
  111. 111     if NEXT_ID = CUSTOMER_ID'FIRST then
  112. 112         CONSOLE.WRITE("The bank doesn't have any customers");
  113. 113         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  114. 114  
  115. 115         -- Generate report
  116. 116     else
  117. 117  
  118. 118             -- Customer balance, transaction count, attempted overdraw
  119. 119             -- count report
  120. 120         CONSOLE.WRITE("**** BANK STATUS REPORT ****");
  121. 121         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  122. 122         CONSOLE.WRITE(
  123. 123               "Customer      Balance  Transactions  Attempted_Overdraws");
  124. 124         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  125. 125         CURRENT_CUSTOMER := FIRST_CUSTOMER;
  126. 126         while CURRENT_CUSTOMER /= null loop
  127. 127         CONSOLE.WRITE(INTEGER(CURRENT_CUSTOMER.ID), 5);
  128. 128         CONSOLE.WRITE("     ");
  129. 129         CONSOLE.WRITE(FLOAT(CURRENT_CUSTOMER.BALANCE), 8, 2);
  130. 130         CONSOLE.WRITE("      ");
  131. 131         CONSOLE.WRITE(INTEGER(CURRENT_CUSTOMER.TRANSACTION_COUNT), 8);
  132. 132         CONSOLE.WRITE("             ");
  133. 133         CONSOLE.WRITE(INTEGER(CURRENT_CUSTOMER.ATTEMPTED_OVERDRAWS),
  134. 134           8);
  135. 135         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  136. 136         CURRENT_CUSTOMER := CURRENT_CUSTOMER.NEXT;
  137. 137         end loop;
  138. 138         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  139. 139  
  140. 140             -- Teller transaction count report
  141. 141         CONSOLE.WRITE("Teller           : ");
  142. 142         for I in TELLER_INDEX loop
  143. 143         CONSOLE.WRITE(INTEGER(I), 8);
  144. 144         end loop;
  145. 145         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  146. 146         CONSOLE.WRITE("Transaction_Count: ");
  147. 147         for I in TELLER_INDEX loop
  148. 148         CONSOLE.WRITE(INTEGER(TELLER_TRANSACTION_COUNT(I)), 8);
  149. 149         end loop;
  150. 150         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  151. 151  
  152. 152     end if;
  153. 153     end PRINT_REPORT;
  154. 154  
  155. 155     -- Terminate all TELLER tasks
  156. 156     procedure STOP_WORK is
  157. 157     begin
  158. 158     for I in TELLER_INDEX loop
  159. 159         abort TELLER(I);
  160. 160     end loop;
  161. 161     end STOP_WORK;
  162. 162 -- 
  163. 163 -- package body BANK
  164. 164  
  165. 165     -- FIND_CUSTOMER is used to find a CUSTOMER_DATA record
  166. 166     -- based on a CUSTOMER_ID number
  167. 167     function FIND_CUSTOMER(ID : in CUSTOMER_ID)
  168. 168                 return CUSTOMER_DATA_POINTER is
  169. 169     CURRENT_CUSTOMER : CUSTOMER_DATA_POINTER;
  170. 170     begin
  171. 171     CURRENT_CUSTOMER := FIRST_CUSTOMER;
  172. 172     while CURRENT_CUSTOMER /= null loop
  173. 173         exit when CURRENT_CUSTOMER.ID = ID;
  174. 174         CURRENT_CUSTOMER := CURRENT_CUSTOMER.NEXT;
  175. 175     end loop;
  176. 176     return CURRENT_CUSTOMER;
  177. 177     end FIND_CUSTOMER;
  178. 178  
  179. 179  
  180. 180 -- 
  181. 181 -- package body BANK
  182. 182  
  183. 183     task TELLER_ASSIGNER is
  184. 184     -- This task assigns an ID number to a teller.
  185. 185     -- TELLER_ASSIGNER is called by the TELLER_PERSON task when the
  186. 186     -- TELLER_PERSON task first starts up.
  187. 187     entry GET_TELLER_ID(ID : out TELLER_INDEX);
  188. 188     end TELLER_ASSIGNER;
  189. 189  
  190. 190     task body TELLER_ASSIGNER is
  191. 191     NEXT_TELLER_ID : TELLER_INDEX := TELLER_INDEX'FIRST;
  192. 192     begin
  193. 193     loop
  194. 194         accept GET_TELLER_ID(ID : out TELLER_INDEX) do
  195. 195         ID := NEXT_TELLER_ID;
  196. 196         if NEXT_TELLER_ID /= TELLER_INDEX'LAST then
  197. 197             NEXT_TELLER_ID := NEXT_TELLER_ID + 1;
  198. 198         end if;
  199. 199         end GET_TELLER_ID;
  200. 200     end loop;
  201. 201     end TELLER_ASSIGNER;
  202. 202  
  203. 203 -- 
  204. 204 -- package body BANK
  205. 205  
  206. 206     -- Implementation of a TELLER task
  207. 207     task body TELLER_PERSON is
  208. 208  
  209. 209     THIS_CUSTOMER : CUSTOMER_DATA_POINTER;
  210. 210     MY_NUMBER     : TELLER_INDEX;
  211. 211  
  212. 212     begin
  213. 213  
  214. 214         -- TELLER gets his ID number
  215. 215     TELLER_ASSIGNER.GET_TELLER_ID(MY_NUMBER);
  216. 216  
  217. 217         -- TELLER loops on REQUESTs from CUSTOMERs
  218. 218     loop
  219. 219         accept REQUEST(ID     : in out CUSTOMER_ID;
  220. 220                KIND   : in TRANSACTION;
  221. 221                AMOUNT : in out DOLLAR) do
  222. 222  
  223. 223                 -- Increment teller's transaction count
  224. 224         TELLER_TRANSACTION_COUNT(MY_NUMBER)
  225. 225                     := TELLER_TRANSACTION_COUNT(MY_NUMBER) + 1;
  226. 226  
  227. 227 -- 
  228. 228 -- package body BANK
  229. 229  
  230. 230                 -- Process REQUEST
  231. 231         case KIND is
  232. 232  
  233. 233             when ADD_NEW_CUSTOMER =>
  234. 234             if LAST_CUSTOMER = null then
  235. 235                 LAST_CUSTOMER := new CUSTOMER_DATA;
  236. 236                 FIRST_CUSTOMER := LAST_CUSTOMER;
  237. 237             else
  238. 238                 LAST_CUSTOMER.NEXT := new CUSTOMER_DATA;
  239. 239                 LAST_CUSTOMER := LAST_CUSTOMER.NEXT;
  240. 240             end if;
  241. 241             LAST_CUSTOMER.ID := NEXT_ID;
  242. 242             ID := NEXT_ID;
  243. 243             NEXT_ID := NEXT_ID + 1;
  244. 244             THIS_CUSTOMER := LAST_CUSTOMER;
  245. 245  
  246. 246             when GET_BALANCE =>
  247. 247             THIS_CUSTOMER := FIND_CUSTOMER(ID);
  248. 248             AMOUNT := THIS_CUSTOMER.BALANCE;
  249. 249  
  250. 250             when MAKE_DEPOSIT =>
  251. 251             THIS_CUSTOMER := FIND_CUSTOMER(ID);
  252. 252             THIS_CUSTOMER.BALANCE
  253. 253                             := THIS_CUSTOMER.BALANCE + AMOUNT;
  254. 254             AMOUNT := THIS_CUSTOMER.BALANCE;
  255. 255  
  256. 256             when MAKE_WITHDRAWAL =>
  257. 257             THIS_CUSTOMER := FIND_CUSTOMER(ID);
  258. 258             if THIS_CUSTOMER.BALANCE < AMOUNT then
  259. 259                 AMOUNT := 0.0;
  260. 260                 THIS_CUSTOMER.ATTEMPTED_OVERDRAWS :=
  261. 261                   THIS_CUSTOMER.ATTEMPTED_OVERDRAWS + 1;
  262. 262             else
  263. 263                 THIS_CUSTOMER.BALANCE
  264. 264                                 := THIS_CUSTOMER.BALANCE - AMOUNT;
  265. 265             end if;
  266. 266  
  267. 267         end case;
  268. 268  
  269. 269                 -- Increment CUSTOMER's transaction count
  270. 270         THIS_CUSTOMER.TRANSACTION_COUNT
  271. 271                     := THIS_CUSTOMER.TRANSACTION_COUNT + 1;
  272. 272  
  273. 273         end REQUEST;
  274. 274  
  275. 275     end loop;
  276. 276  
  277. 277     end TELLER_PERSON;
  278. 278  
  279. 279 end BANK;
  280. 280  
  281. 281 -- 
  282. 282 package CUSTOMER_WORLD is
  283. 283 ------------------------------------------------------------------------
  284. 284 --| BEGIN PROLOGUE
  285. 285 --| DESCRIPTION            : CUSTOMER_WORLD is an abstract state machine
  286. 286 --|                        : which defines the collection of all CUSTOMERs
  287. 287 --|                        : of the BANK.  It allows the mainline procedure
  288. 288 --|                        : to ADD a new CUSTOMER and TERMINATE_ALL
  289. 289 --|                        : current CUSTOMERs.  The CUSTOMER itself acts
  290. 290 --|                        : as an independent task and requires no
  291. 291 --|                        : direct interaction with the mainline once
  292. 292 --|                        : it starts.
  293. 293 --|                        :
  294. 294 --| REQUIREMENTS SUPPORTED : Bank Demonstration Program to show
  295. 295 --|                        : object-oriented design and tasking
  296. 296 --|                        : with Ada
  297. 297 --|                        :
  298. 298 --| LIMITATIONS            : None
  299. 299 --| AUTHOR(S)              : Richard Conn (RLC)
  300. 300 --| CHANGE LOG             : 1/16/89  RLC  Initial Design and Code
  301. 301 --| CHANGE LOG             : 2/25/89  RLC  Final Review Prior to Release
  302. 302 --| REMARKS                : None
  303. 303 --| PORTABILITY ISSUES     : None
  304. 304 --| END PROLOGUE
  305. 305 ------------------------------------------------------------------------
  306. 306  
  307. 307     -- Add another CUSTOMER task to the system
  308. 308     procedure ADD;
  309. 309  
  310. 310     -- Terminate all CUSTOMERs in the system
  311. 311     procedure TERMINATE_ALL;
  312. 312  
  313. 313 end CUSTOMER_WORLD;
  314. 314  
  315. 315 -- 
  316. 316 with BANK;
  317. 317 with RANDOM;
  318. 318 package body CUSTOMER_WORLD is
  319. 319  
  320. 320     -- Support infix operations, like DOLLAR < DOLLAR
  321. 321     use  BANK;
  322. 322  
  323. 323     -- This is the amount that a CUSTOMER initially deposits
  324. 324     -- into his account
  325. 325     INITIAL_DEPOSIT : constant BANK.DOLLAR          := 100.0;
  326. 326  
  327. 327     -- A CUSTOMER is a task, running concurrently with the TELLERs,
  328. 328     -- other CUSTOMERs, and the mainline task
  329. 329     task type CUSTOMER;
  330. 330  
  331. 331     -- CUSTOMER_POINTER is a pointer to a CUSTOMER, used to
  332. 332     -- create new customers and track old customers in the linked
  333. 333     -- list of customers used for task termination when the
  334. 334     -- program is complete
  335. 335     type CUSTOMER_POINTER              is access CUSTOMER;
  336. 336  
  337. 337     -- These are the constructs used to create a linked list of
  338. 338     -- the customers
  339. 339     type CUSTOMER_LIST_ELEMENT;
  340. 340     type CUSTOMER_LIST_ELEMENT_POINTER is access CUSTOMER_LIST_ELEMENT;
  341. 341     type CUSTOMER_LIST_ELEMENT is record
  342. 342     THIS_CUSTOMER : CUSTOMER_POINTER;
  343. 343     NEXT          : CUSTOMER_LIST_ELEMENT_POINTER := null;
  344. 344     end record;
  345. 345  
  346. 346     -- Pointer to the first of the customers
  347. 347     FIRST_CUSTOMER  : CUSTOMER_LIST_ELEMENT_POINTER := null;
  348. 348     LAST_CUSTOMER   : CUSTOMER_LIST_ELEMENT_POINTER := null;
  349. 349  
  350. 350 -- 
  351. 351 -- package body CUSTOMER_WORLD
  352. 352  
  353. 353     -- Implementation of the CUSTOMER task
  354. 354     task body CUSTOMER is
  355. 355  
  356. 356     ID                 : BANK.CUSTOMER_ID   := BANK.CUSTOMER_ID'FIRST;
  357. 357     BALANCE            : BANK.DOLLAR        := 0.0;
  358. 358     AMOUNT             : BANK.DOLLAR        := 0.0;
  359. 359     MY_TRANSACTION     : BANK.TRANSACTION;
  360. 360  
  361. 361         -- SELECT_TELLER makes a random selection of one of the
  362. 362         -- BANK's tellers
  363. 363     function SELECT_TELLER return BANK.TELLER_INDEX is
  364. 364     begin
  365. 365         return BANK.TELLER_INDEX(
  366. 366                 RANDOM.NUMBER * FLOAT(BANK.TELLER_INDEX'LAST) + 1.0);
  367. 367     exception
  368. 368         when others =>
  369. 369         return BANK.TELLER_INDEX'LAST;
  370. 370     end SELECT_TELLER;
  371. 371  
  372. 372     begin    -- CUSTOMER activity
  373. 373  
  374. 374         -- As a new CUSTOMER, the first two transactions of the
  375. 375         -- CUSTOMER are to ask the TELLER to add him as a new
  376. 376         -- CUSTOMER and make an initial deposit
  377. 377     BANK.TELLER(SELECT_TELLER).REQUEST(ID, BANK.ADD_NEW_CUSTOMER,
  378. 378       BALANCE);
  379. 379     BALANCE := INITIAL_DEPOSIT;
  380. 380     BANK.TELLER(SELECT_TELLER).REQUEST(ID, BANK.MAKE_DEPOSIT, BALANCE);
  381. 381  
  382. 382         -- The rest of the life of the CUSTOMER is spent in the
  383. 383         -- these steps within the following loop:
  384. 384         --    (1) delay a random amount of time from 0 to 5 seconds
  385. 385         --    (2) compute a random amount from -$50 to +$50
  386. 386         --    (3) if the random amount is negative, attempt to
  387. 387         --        withdraw that amount; if positive, deposit that
  388. 388         --        amount
  389. 389     loop
  390. 390         delay DURATION(5.0 * RANDOM.NUMBER);
  391. 391         AMOUNT := BANK.DOLLAR(100.0 * RANDOM.NUMBER - 50.0);
  392. 392         if AMOUNT < DOLLAR'(0.0) then
  393. 393         MY_TRANSACTION := BANK.MAKE_WITHDRAWAL;
  394. 394         AMOUNT := -AMOUNT;
  395. 395         else
  396. 396         MY_TRANSACTION := BANK.MAKE_DEPOSIT;
  397. 397         end if;
  398. 398         BANK.TELLER(SELECT_TELLER).REQUEST(ID, MY_TRANSACTION, AMOUNT);
  399. 399     end loop;
  400. 400  
  401. 401     end CUSTOMER;
  402. 402  
  403. 403 -- 
  404. 404 -- package body CUSTOMER_WORLD
  405. 405  
  406. 406     -- Add a new CUSTOMER to the linked list
  407. 407     procedure ADD is
  408. 408     begin
  409. 409  
  410. 410         -- If the list is empty, start a new list
  411. 411     if LAST_CUSTOMER = null then
  412. 412         FIRST_CUSTOMER := new CUSTOMER_LIST_ELEMENT;
  413. 413         LAST_CUSTOMER := FIRST_CUSTOMER;
  414. 414  
  415. 415         -- If the list is not empty, add an element onto it
  416. 416     else
  417. 417         LAST_CUSTOMER.NEXT := new CUSTOMER_LIST_ELEMENT;
  418. 418         LAST_CUSTOMER := LAST_CUSTOMER.NEXT;
  419. 419     end if;
  420. 420  
  421. 421         -- Start a new CUSTOMER task
  422. 422     LAST_CUSTOMER.THIS_CUSTOMER := new CUSTOMER;
  423. 423  
  424. 424     end ADD;
  425. 425  
  426. 426     -- Terminate all CUSTOMER tasks by moving thru the linked list
  427. 427     -- and explicitly terminating the tasks pointed to by the list
  428. 428     -- elements.
  429. 429     procedure TERMINATE_ALL is
  430. 430     CURRENT_CUSTOMER : CUSTOMER_LIST_ELEMENT_POINTER;
  431. 431     begin
  432. 432     CURRENT_CUSTOMER := FIRST_CUSTOMER;
  433. 433     while CURRENT_CUSTOMER /= null loop
  434. 434         abort CURRENT_CUSTOMER.THIS_CUSTOMER.all;
  435. 435         CURRENT_CUSTOMER := CURRENT_CUSTOMER.NEXT;
  436. 436     end loop;
  437. 437     end TERMINATE_ALL;
  438. 438  
  439. 439 end CUSTOMER_WORLD;
  440. 440  
  441. 441 -- 
  442. 442 with BANK;
  443. 443 with CUSTOMER_WORLD;
  444. 444 with CONSOLE;
  445. 445 procedure BD3 is                           -- BANK_DEMO_3
  446. 446 ------------------------------------------------------------------------
  447. 447 --| BEGIN PROLOGUE
  448. 448 --| DESCRIPTION            : Procedure BD3 (BANK DEMO 3) is a mainline
  449. 449 --|                        : which demonstrates the operation of the
  450. 450 --|                        : BANK.  Upon invocation, the console becomes
  451. 451 --|                        : a command processor for the bank manager.
  452. 452 --|                        : The bank manager can obtain the status of
  453. 453 --|                        : the bank (balances, number of transactions,
  454. 454 --|                        : and attempted overdraws of all customers
  455. 455 --|                        : and number of transactions processed by all
  456. 456 --|                        : tellers) in a single or continuous (group
  457. 457 --|                        : of 11 over about one minute) display.
  458. 458 --|                        : The user at the console can also cause new
  459. 459 --|                        : Customer tasks to be created and shut down
  460. 460 --|                        : the system.
  461. 461 --|                        :
  462. 462 --| REQUIREMENTS SUPPORTED : Bank Demonstration Program to show
  463. 463 --|                        : object-oriented design and tasking
  464. 464 --|                        : with Ada
  465. 465 --|                        :
  466. 466 --| LIMITATIONS            : None
  467. 467 --| AUTHOR(S)              : Richard Conn (RLC)
  468. 468 --| CHANGE LOG             : 1/16/89  RLC  Initial Design and Code
  469. 469 --| CHANGE LOG             : 2/25/89  RLC  Final Review Prior to Release
  470. 470 --| REMARKS                : None
  471. 471 --| PORTABILITY ISSUES     : Uses CONSOLE (TEXT_IO), so is very portable;
  472. 472 --|                        : no known portability problems.
  473. 473 --| END PROLOGUE
  474. 474 ------------------------------------------------------------------------
  475. 475  
  476. 476     -- Line input from the console
  477. 477     INPUT                               : CONSOLE.OUTSTRING;
  478. 478  
  479. 479     -- Number of continuous status reports displayed by the 'c'
  480. 480     -- command before control is returned to the console
  481. 481     NUMBER_OF_CONTINUOUS_STATUS_REPORTS : constant := 10;
  482. 482  
  483. 483 -- 
  484. 484 -- procedure BD3
  485. 485  
  486. 486 begin                                      -- mainline
  487. 487  
  488. 488     -- This is the beginning of the main loop.  In this loop,
  489. 489     -- a list of commands is printed on the console, the user
  490. 490     -- at the console (as CUSTOMER 0) enters one of these commands
  491. 491     -- followed by striking the RETURN key, and the command is
  492. 492     -- processed.
  493. 493     loop
  494. 494  
  495. 495         -- Command listing and prompt
  496. 496     CONSOLE.WRITE("Enter");
  497. 497     CONSOLE.WRITE(CONSOLE.NEW_LINE);
  498. 498     CONSOLE.WRITE("  b for bank status");
  499. 499     CONSOLE.WRITE(CONSOLE.NEW_LINE);
  500. 500     CONSOLE.WRITE("  c for continuous bank status");
  501. 501     CONSOLE.WRITE(CONSOLE.NEW_LINE);
  502. 502     CONSOLE.WRITE("  s for start next customer");
  503. 503     CONSOLE.WRITE(CONSOLE.NEW_LINE);
  504. 504     CONSOLE.WRITE("  x for exit: ");
  505. 505     CONSOLE.READ(INPUT);
  506. 506  
  507. 507         -- Interpretation and execution of input command
  508. 508     case INPUT(1) is
  509. 509         when 'b' | 'c' =>              -- Short or continuous bank status
  510. 510                                        -- report
  511. 511         BANK.PRINT_REPORT;
  512. 512         if INPUT(1) = 'c' then
  513. 513             for I in 1 .. NUMBER_OF_CONTINUOUS_STATUS_REPORTS loop
  514. 514             delay 5.0;
  515. 515             BANK.PRINT_REPORT;
  516. 516                     CONSOLE.WRITE(CONSOLE.NEW_LINE);
  517. 517             end loop;
  518. 518         end if;
  519. 519  
  520. 520         when 's' =>                    -- Start up a new CUSTOMER
  521. 521         CUSTOMER_WORLD.ADD;
  522. 522  
  523. 523         when 'x' =>                      -- Exit program
  524. 524         CUSTOMER_WORLD.TERMINATE_ALL;    -- Kill CUSTOMER tasks
  525. 525         BANK.STOP_WORK;                  -- Kill TELLER tasks
  526. 526         exit;                            -- Exit loop
  527. 527  
  528. 528         when ' ' =>                    -- Non-error on a null input line
  529. 529         null;
  530. 530  
  531. 531         when others =>                 -- Other commands are invalid
  532. 532         CONSOLE.WRITE("Invalid Command: ");
  533. 533         CONSOLE.WRITE(CONSOLE.TRIM(INPUT));
  534. 534         CONSOLE.WRITE(CONSOLE.NEW_LINE);
  535. 535  
  536. 536     end case;
  537. 537  
  538. 538     end loop;
  539. 539  
  540. 540 end BD3;
  541.