/[freeride]/freeride/test/databus.rb
ViewVC logotype

Diff of /freeride/test/databus.rb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by ljulliar, Fri Jan 25 17:58:49 2002 UTC revision 1.2 by richkilmer, Thu Jan 31 09:19:12 2002 UTC
# Line 1  Line 1 
1  require 'freeride/databus'  require 'freeride/databus'
2    
3  class SubscriptionTest  class SubscriptionTest
4   def databus_notify(message, slot)   def databus_notify(event, slot)
5     puts "Tester Class got #{slot.data}"     puts "Tester Class got #{slot.data}"
6   end   end
7  end  end
8    
9  # test data  # test data
10  databus = FreeRIDE::DataBus.new  databus = FreeRIDE::DataBus.new
11  databus["/"].subscribe {|message, slot| puts "data to #{slot.path}"}  databus["/"].subscribe {|event, slot| puts "data to #{slot.path}"}
12  st = SubscriptionTest.new  st = SubscriptionTest.new
13  databus["/foo/bar"].subscribe(st)  databus["/foo/bar"].subscribe(st)
14  id = databus["/foo/bar"].subscribe {|message, slot| puts "Block got #{slot.data} message #{message.to_s}" }  id = databus["/foo/bar"].subscribe {|event, slot| puts "Block got #{slot.data} event #{event.to_s}" }
15  databus["/foo/bar"].data = "data :-)" #=> publishes data  databus["/foo/bar"].data = "data :-)" #=> publishes data
16  databus["/foo/bar"].unsubscribe(id)  databus["/foo/bar"].unsubscribe(id)
17  databus["/foo/bar"].unsubscribe(st)  databus["/foo/bar"].unsubscribe(st)
# Line 24  end Line 24  end
24    
25  #test queue  #test queue
26  databus["/foo/bar/queue"].queue  databus["/foo/bar/queue"].queue
27  databus["/foo/bar/queue"].subscribe {|message, slot| puts "Message: #{message.to_s}"}  databus["/foo/bar/queue"].subscribe {|event, slot| puts "event: #{event.to_s}"}
28  databus["/foo/bar/queue"].join "first"  databus["/foo/bar/queue"].join "first"
29  databus["/foo/bar/queue"] << "second"  databus["/foo/bar/queue"] << "second"
30  puts databus["/foo/bar/queue"].leave  puts databus["/foo/bar/queue"].leave
# Line 36  end Line 36  end
36    
37  #test stack  #test stack
38  databus["/foo/bar/stack"].stack  databus["/foo/bar/stack"].stack
39  databus["/foo/bar/stack"].subscribe do |message, slot|  databus["/foo/bar/stack"].subscribe do |event, slot|
40   puts "Got notification in stack #{message.to_s}"   puts "Got notification in stack #{event.to_s}"
41   if message == :notify_stack_push   if event == :notify_stack_push
42     puts "Pop inside of subscriber: #{slot.pop}"     puts "Pop inside of subscriber: #{slot.pop}"
43   end   end
44  end  end
# Line 57  end Line 57  end
57  #test proc  #test proc
58  databus["/foo/bar/proc"].set_proc {|p1, p2| puts "Got #{p1} and #{p2}"}  databus["/foo/bar/proc"].set_proc {|p1, p2| puts "Got #{p1} and #{p2}"}
59  databus["/foo/bar/proc"].validate_with("Must have two args") {|args| args.size==2}  databus["/foo/bar/proc"].validate_with("Must have two args") {|args| args.size==2}
60  databus["/foo/bar/proc"].subscribe {|message, slot| puts "Message: #{message.to_s}"}  databus["/foo/bar/proc"].subscribe {|event, slot| puts "event: #{event.to_s}"}
61  databus["/foo/bar/proc"].call("one", "two")  databus["/foo/bar/proc"].call("one", "two")
62  begin  begin
63   databus["/foo/bar/proc"].call("one", "two", "three")   databus["/foo/bar/proc"].call("one", "two", "three")

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26