Skip to content

Commit

Permalink
Through end of p. 179
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Jan 5, 2010
1 parent 7bd0599 commit a5239a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
29 changes: 13 additions & 16 deletions src/15-ui/app/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ module App # TODO: at some point, this really ought to surround all app code.
end

class Main
ARG_HOSTNAME = 0
ARG_USERNAME = 1
ARG_PASSWORD = 2
ARG_ITEM_ID = 3

AUCTION_RESOURCE = "Auction"
ITEM_ID_AS_LOGIN = "auction-%s"
AUCTION_ID_FORMAT = "#{ITEM_ID_AS_LOGIN}@%s/#{AUCTION_RESOURCE}"

def self.main(*args)
def self.main(hostname, username, password, *item_ids)
item_id = item_ids[0]
App::Log.info("App initializing")
connection = connection(hostname, username, password)

main = new
main.join_auction(connection(args[ARG_HOSTNAME], args[ARG_USERNAME], args[ARG_PASSWORD]),
args[ARG_ITEM_ID]);
ui = main.start_user_interface
disconnect_when_ui_closes(connection, ui)

item_ids.each do | item_id |
main.join_auction(connection, item_id);
end
end

def self.connection(hostname, username, password)
Expand All @@ -34,10 +36,6 @@ def self.connection(hostname, username, password)
connection
end

def initialize
start_user_interface
end

def start_user_interface
App::Log.info(me("starting user interface"))
SwingUtilities.invoke_and_wait do
Expand All @@ -46,11 +44,10 @@ def start_user_interface
@snipers = SnipersTableModel.new
@ui = MainWindow.new(@snipers)
end
@ui
end

def join_auction(connection, item_id)
disconnect_when_ui_closes(connection)

chat = connection.chat_manager.create_chat(auction_id(item_id, connection),
nil)
auction = XMPPAuction.new(chat)
Expand All @@ -67,8 +64,8 @@ def auction_id(item_id, connection)
sprintf(AUCTION_ID_FORMAT, item_id, connection.service_name)
end

def disconnect_when_ui_closes(connection)
@ui.on_window_closed do
def self.disconnect_when_ui_closes(connection, ui)
ui.on_window_closed do
connection.disconnect
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/15-ui/features/step_definitions/setup_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
end

When /^the sniper has started bidding in that auction$/ do
start_bidding_in_auctions([@auctions.last_used])
start_bidding_in_auctions(@auctions)
start_driver
end

Given /^the sniper has joined auctions for items (\d+) and (\d+)$/ do | first_item, second_item |
start_auctions_for_items(["item-"+first_item,
"item-"+second_item])
start_bidding_in_auctions(@auctions.all)
When /^the sniper has joined auctions for items (\d+) and (\d+)$/ do | first_item, second_item |
start_auctions_for_items(["item-"+first_item, "item-"+second_item])
start_bidding_in_auctions(@auctions)
start_driver
end

def start_auctions_for_items(items)
Expand Down
4 changes: 2 additions & 2 deletions src/15-ui/features/support/application-runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

class ApplicationRunner
def start_bidding_in(auctions)
auction = auctions[0]
thread = Thread.new do
begin
Main.main(XMPP_HOSTNAME, SNIPER_ID, SNIPER_PASSWORD, auction.item_id)
ids = auctions.collect { | auction | auction.item_id }
Main.main(XMPP_HOSTNAME, SNIPER_ID, SNIPER_PASSWORD, *ids)
rescue Exception => ex
puts "======== #{ex.message}"
puts ex.backtrace
Expand Down

0 comments on commit a5239a9

Please sign in to comment.