Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit ed5417f531d147bccfedecc95327f97f2b9f30f6 doubleblind committed Sep 28, 2012
Showing with 2,173 additions and 0 deletions.
  1. +6 −0 README
  2. +93 −0 atm_system/application.e
  3. +193 −0 atm_system/atm.e
  4. +17 −0 atm_system/atm_card.e
  5. +20 −0 atm_system/atm_configuration.e
  6. +20 −0 atm_system/banking_system.ecf
  7. +36 −0 atm_system/card_reader.e
  8. +18 −0 atm_system/cash_dispenser.e
  9. +135 −0 atm_system/customer.e
  10. +41 −0 atm_system/log.e
  11. +300 −0 atm_system/message.e
  12. +20 −0 atm_system/receipt_printer.e
  13. +126 −0 atm_system/server.e
  14. +49 −0 atm_system/string_helper.e
  15. +72 −0 atm_system/touchscreen.e
  16. +7 −0 components/algorithm.e
  17. +7 −0 components/async_algorithm.e
  18. +7 −0 components/async_coordinator.e
  19. +7 −0 components/async_io.e
  20. +3 −0 components/component.e
  21. +18 −0 components/components.ecf
  22. +30 −0 components/components_test.e
  23. +7 −0 components/control.e
  24. +7 −0 components/coordinator.e
  25. +7 −0 components/entity.e
  26. +7 −0 components/io.e
  27. +24 −0 components/pacemaker.e
  28. +44 −0 components/periodic.e
  29. +39 −0 components/periodic_algorithm.e
  30. +39 −0 components/periodic_coordinator.e
  31. +40 −0 components/periodic_io.e
  32. +7 −0 components/state_dependent.e
  33. +30 −0 components/talker.e
  34. +41 −0 components/timer.e
  35. +42 −0 connectors/async_queue_conduit.e
  36. +38 −0 connectors/async_queue_receiver.e
  37. +37 −0 connectors/async_queue_sender.e
  38. +52 −0 connectors/buffer_conduit.e
  39. +38 −0 connectors/buffer_receiver.e
  40. +49 −0 connectors/buffer_sender.e
  41. +10 −0 connectors/conduit.e
  42. +46 −0 connectors/connector_test.e
  43. +18 −0 connectors/connectors.ecf
  44. +15 −0 connectors/message_receiver.e
  45. +15 −0 connectors/message_sender.e
  46. +57 −0 connectors/reply_queue_callback.e
  47. +51 −0 connectors/reply_queue_conduit.e
  48. +47 −0 connectors/reply_queue_receiver.e
  49. +60 −0 connectors/reply_queue_sender.e
  50. +37 −0 connectors/reply_receiver.e
  51. +44 −0 connectors/reply_sender.e
@@ -0,0 +1,6 @@
+This project consists of the SCOOP implementation of the connectors and
+components design patterns. These behavioral design patterns attempt to
+bridge the gap between high-level design and implementation of concurrent
+systems.
+
+A case study (ATM system) is also included to show the usage of the patterns.
@@ -0,0 +1,93 @@
+class
+ APPLICATION
+
+inherit
+ ARGUMENTS
+
+create
+ make
+
+feature {NONE} -- Initialization
+ atm_configurations: ARRAY [separate ATM_CONFIGURATION]
+
+ make
+ -- Run application.
+ do
+ initialize (10, 3)
+ end
+
+ initialize (no_of_customers: INTEGER; no_of_atms: INTEGER)
+ local
+ ratio: INTEGER
+ i, j: INTEGER
+ customer: separate CUSTOMER
+ atm: separate ATM
+ server: separate SERVER
+ reply_queue_conduit: separate REPLY_QUEUE_CONDUIT [MESSAGE]
+ reply_queue_callback: separate REPLY_QUEUE_CALLBACK [MESSAGE]
+ pension: separate CUSTOMER
+ do
+ -- Initialize server.
+ create reply_queue_conduit.make
+ create reply_queue_callback.make
+ create server.make (reply_queue_conduit, reply_queue_callback)
+ start_server (server, no_of_customers)
+
+ -- Initialize ATMs and customers.
+ create atm_configurations.make (1, no_of_atms)
+
+ from
+ i := 0
+ j := 0
+ until
+ i = no_of_atms - 1
+ loop
+ i := i + 1
+ create atm.make_with_id (reply_queue_conduit, reply_queue_callback, i)
+ start_atm (atm, i)
+ if ratio > 0 then
+ create customer.make
+ start_customers (customer, i, ratio, ratio)
+ j := j + ratio
+ end
+ end
+ i := i + 1
+ create atm.make_with_id (reply_queue_conduit, reply_queue_callback, i)
+ start_atm (atm, i)
+ if no_of_customers - j > 0 then
+ create customer.make
+ start_customers (customer, i, ratio, no_of_customers - j)
+ j := j + no_of_customers - j
+ end
+ end
+
+ start_server (a_server: separate SERVER; a_number_of_customers: INTEGER)
+ do
+ a_server.initialize (a_number_of_customers)
+ a_server.start
+ end
+
+ start_atm (a_atm: separate ATM; a_number: INTEGER)
+ do
+ atm_configurations.put (a_atm.configuration, a_number)
+ a_atm.start
+ end
+
+ start_customers (a_customer: separate CUSTOMER; a_atm_no: INTEGER; ratio: INTEGER; total: INTEGER)
+ local
+ i: INTEGER
+ do
+ from
+ i := 1
+ until
+ i > total
+ loop
+ a_customer.take_identity ((a_atm_no - 1) * ratio + i, (a_atm_no - 1) * ratio + i, (a_atm_no - 1) * ratio + i)
+ a_customer.retrieve_balance (atm_configurations[a_atm_no])
+ a_customer.withdraw (atm_configurations[a_atm_no], 500)
+ a_customer.transfer (atm_configurations[a_atm_no], 500, 0)
+ a_customer.retrieve_balance (atm_configurations[a_atm_no])
+ i := i + 1
+ end
+ end
+end
@@ -0,0 +1,193 @@
+class
+ ATM
+
+inherit
+ STATE_DEPENDENT
+
+ STRING_HELPER
+
+create
+ make_with_id
+
+feature
+ card_reader_receive_interface: BUFFER_RECEIVER [MESSAGE]
+ card_reader_send_interface: BUFFER_SENDER [MESSAGE]
+ server_send_interface: REPLY_QUEUE_SENDER [MESSAGE, MESSAGE]
+ touchscreen_send_interface: REPLY_SENDER [MESSAGE, MESSAGE]
+ receipt_printer_send_interface: BUFFER_SENDER [MESSAGE]
+ cash_dispenser_send_interface: BUFFER_SENDER [MESSAGE]
+-- log_send_interface: ASYNC_QUEUE_SENDER [separate STRING]
+
+feature
+ id: INTEGER
+
+ make_with_id (
+ a_server_send_conduit: separate REPLY_QUEUE_CONDUIT [MESSAGE];
+ a_server_reply_conduit: separate REPLY_QUEUE_CALLBACK [MESSAGE];
+ a_id: INTEGER
+ )
+ local
+ l_send_buffer_conduit: separate BUFFER_CONDUIT [MESSAGE]
+ l_reply_buffer_conduit: separate BUFFER_CONDUIT [MESSAGE]
+ l_receive_buffer_conduit: separate BUFFER_CONDUIT [MESSAGE]
+
+ l_touchscreen: separate TOUCHSCREEN
+ l_card_reader: separate CARD_READER
+ l_receipt_printer: separate RECEIPT_PRINTER
+ l_cash_dispenser: separate CASH_DISPENSER
+
+ l_log: separate LOG
+ l_async_queue_conduit: separate ASYNC_QUEUE_CONDUIT [separate STRING]
+ do
+ create l_receive_buffer_conduit
+ create l_send_buffer_conduit
+ create l_card_reader.make (l_receive_buffer_conduit, l_send_buffer_conduit)
+ create card_reader_receive_interface.make (l_receive_buffer_conduit)
+ create card_reader_send_interface.make (l_send_buffer_conduit)
+
+ create l_send_buffer_conduit
+ create l_reply_buffer_conduit
+ create l_touchscreen.make (l_send_buffer_conduit, l_reply_buffer_conduit)
+ create touchscreen_send_interface.make (l_send_buffer_conduit, l_reply_buffer_conduit)
+
+ create l_send_buffer_conduit
+ create l_receipt_printer.make (l_send_buffer_conduit)
+ create receipt_printer_send_interface.make (l_send_buffer_conduit)
+
+ create l_send_buffer_conduit
+ create l_cash_dispenser.make (l_send_buffer_conduit)
+ create cash_dispenser_send_interface.make (l_send_buffer_conduit)
+
+ create configuration.make (l_card_reader, l_touchscreen, l_receipt_printer, l_cash_dispenser)
+
+ create server_send_interface.make (a_server_send_conduit, a_server_reply_conduit)
+
+-- create l_async_queue_conduit.make
+-- create l_log.make_with_conduit (l_async_queue_conduit, 1000 * 1000)
+-- create log_send_interface.make (l_async_queue_conduit)
+-- start_log (l_log)
+
+ id := a_id
+ end
+
+ configuration: separate ATM_CONFIGURATION
+
+-- start_log (a_log: separate LOG)
+-- do
+-- a_log.start
+-- end
+
+feature
+ start
+ local
+ l_message: MESSAGE
+ l_card_number: INTEGER
+ l_pin: INTEGER
+ l_amount: INTEGER
+ l_destination_account_number: INTEGER
+ l_balance: INTEGER
+ do
+ from
+
+ until
+ False
+ loop
+ l_message := card_reader_receive_interface.receive
+ l_card_number := l_message.card_inserted_message.card_number
+
+ l_pin := touchscreen_send_interface.send (create {MESSAGE}.make_for_pin_retrieval).pin_report_message.pin
+ if is_pin_valid (l_card_number, l_pin) then
+-- log_send_interface.send (separate_str ("PIN valid"))
+
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_success_report)
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_command_retrieval)
+
+ if l_message.is_withdrawal_message then
+ l_amount := l_message.withdrawal_message.amount
+ server_send_interface.send (create {MESSAGE}.make_for_withdrawal (l_card_number, l_amount))
+ if server_send_interface.accept.report_message.has_succeeded then
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_success_report)
+ receipt_printer_send_interface.send (create {MESSAGE}.make_for_receipt_printing)
+ card_reader_send_interface.send (create {MESSAGE}.make_for_card_return)
+ cash_dispenser_send_interface.send (create {MESSAGE}.make_for_cash_dispensing (l_amount))
+ else
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_failure_report)
+ end
+ elseif l_message.is_transfer_message then
+ l_amount := l_message.transfer_message.amount
+ l_destination_account_number := l_message.transfer_message.destination_account_number
+ server_send_interface.send (create {MESSAGE}.make_for_transfer (l_card_number, l_amount, l_destination_account_number))
+ if server_send_interface.accept.report_message.has_succeeded then
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_success_report)
+ receipt_printer_send_interface.send (create {MESSAGE}.make_for_receipt_printing)
+ card_reader_send_interface.send (create {MESSAGE}.make_for_card_return)
+ else
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_failure_report)
+ end
+ elseif l_message.is_balance_retrieval_message then
+ server_send_interface.send (create {MESSAGE}.make_for_balance_retrieval (l_card_number))
+ l_balance := server_send_interface.accept.balance_report_message.balance
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_balance_report (l_balance))
+ receipt_printer_send_interface.send (create {MESSAGE}.make_for_receipt_printing)
+ card_reader_send_interface.send (create {MESSAGE}.make_for_card_return)
+ end
+ else
+-- log_send_interface.send (separate_str ("PIN invalid"))
+ l_message := touchscreen_send_interface.send (create {MESSAGE}.make_for_failure_report)
+ end
+ end
+ end
+
+feature
+ is_successful: BOOLEAN
+
+ withdraw (a_atm_card_number: INTEGER; a_pin: INTEGER; a_amount: INTEGER)
+ do
+ if is_pin_valid (a_atm_card_number, a_pin) then
+ server_send_interface.send (create {MESSAGE}.make_for_withdrawal (a_atm_card_number, a_amount))
+ if server_send_interface.accept.report_message.has_succeeded then
+ is_successful := True
+ else
+ is_successful := False
+ end
+ else
+ is_successful := False
+ end
+ end
+
+ transfer (a_atm_card_number: INTEGER; a_pin: INTEGER; a_amount: INTEGER; a_destination_account_number: INTEGER)
+ do
+ if is_pin_valid (a_atm_card_number, a_pin) then
+ server_send_interface.send (create {MESSAGE}.make_for_transfer (a_atm_card_number, a_amount, a_destination_account_number))
+ if server_send_interface.accept.report_message.has_succeeded then
+ is_successful := True
+ else
+ is_successful := False
+ end
+ else
+ is_successful := False
+ end
+ end
+
+ retrieve_balance (a_atm_card_number: INTEGER; a_pin: INTEGER)
+ do
+ if is_pin_valid (a_atm_card_number, a_pin) then
+ is_successful := True
+ server_send_interface.send (create {MESSAGE}.make_for_balance_retrieval (a_atm_card_number))
+ balance := server_send_interface.accept.balance_report_message.balance
+ else
+ is_successful := False
+ end
+ end
+
+ balance: INTEGER
+
+ is_pin_valid (a_atm_card_number: INTEGER; a_pin: INTEGER): BOOLEAN
+ do
+ server_send_interface.send (create {MESSAGE}.make_for_pin_validation (a_atm_card_number, a_pin))
+ Result := server_send_interface.accept.report_message.has_succeeded
+ end
+
+feature {NONE}
+
+end
@@ -0,0 +1,17 @@
+expanded class
+ ATM_CARD
+
+create
+ make,
+ default_create
+
+feature {NONE}
+ make (a_card_number: INTEGER)
+ do
+ card_number := a_card_number
+ end
+
+feature {CARD_READER, CUSTOMER}
+ card_number: INTEGER
+
+end
@@ -0,0 +1,20 @@
+class
+ ATM_CONFIGURATION
+
+create
+ make
+
+feature
+ make (a_card_reader: separate CARD_READER; a_touchscreen: separate TOUCHSCREEN; a_receipt_printer: separate RECEIPT_PRINTER; a_cash_dispenser: separate CASH_DISPENSER)
+ do
+ card_reader := a_card_reader
+ touchscreen := a_touchscreen
+ receipt_printer := a_receipt_printer
+ cash_dispenser := a_cash_dispenser
+ end
+
+ card_reader: separate CARD_READER
+ touchscreen: separate TOUCHSCREEN
+ receipt_printer: separate RECEIPT_PRINTER
+ cash_dispenser: separate CASH_DISPENSER
+end
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="atm_system" uuid="D4FC4D25-2960-40F5-9DC2-806D83AA32A8">
+ <target name="atm_system">
+ <root class="APPLICATION" feature="make"/>
+ <option warning="true" is_attached_by_default="false" syntax="transitional">
+ <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
+ </option>
+ <setting name="concurrency" value="scoop"/>
+ <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
+ <library name="components" location="..\components\components.ecf"/>
+ <library name="connectors" location="..\connectors\connectors.ecf"/>
+ <cluster name="banking_system" location=".\" recursive="true">
+ <file_rule>
+ <exclude>/EIFGENs$</exclude>
+ <exclude>/CVS$</exclude>
+ <exclude>/.svn$</exclude>
+ </file_rule>
+ </cluster>
+ </target>
+</system>
@@ -0,0 +1,36 @@
+class
+ CARD_READER
+
+inherit
+ ASYNC_IO
+
+create
+ make
+
+feature {NONE}
+ atm_send_interface: BUFFER_SENDER [MESSAGE]
+ atm_receive_interface: BUFFER_RECEIVER [MESSAGE]
+ card: ATM_CARD
+
+ make (a_send_conduit: separate BUFFER_CONDUIT [MESSAGE]; a_receive_conduit: separate BUFFER_CONDUIT [MESSAGE])
+ do
+ create atm_send_interface.make (a_send_conduit)
+ create atm_receive_interface.make (a_receive_conduit)
+ end
+
+feature
+ take_card (a_card: ATM_CARD)
+ do
+ card := a_card
+ atm_send_interface.send (create {MESSAGE}.make_for_card_inserted (a_card.card_number))
+ end
+
+ return_card: ATM_CARD
+ local
+ l_message: MESSAGE
+ do
+ l_message := atm_receive_interface.receive
+ Result := card
+ end
+
+end
Oops, something went wrong. Retry.

0 comments on commit ed5417f

Please sign in to comment.