Permalink
Browse files

so much to do...

  • Loading branch information...
1 parent ab91495 commit 68e777c460a2e63e2966f93e5ca16c1162418ea7 @metadave committed Mar 15, 2009
Showing with 250 additions and 69 deletions.
  1. +54 −14 mm/mm.rb
  2. +101 −19 mm/ops.rb
  3. +95 −36 mmgui/gui.rb
View
@@ -62,11 +62,14 @@ def create(opname,title="none")
end
def run
+ begin
+ @ops.values.each do |op|
+ op.starting
+ end
+ rescue StandardError => boom
+ puts "Error starting network: #{boom}"
+ end
- @ops.values.each do |op|
- op.starting
- end
-
@stophack = 0
running = true
while running
@@ -82,9 +85,13 @@ def run
end
end
- @ops.values.each do |op|
- op.stopping
- end
+ begin
+ @ops.values.each do |op|
+ op.stopping
+ end
+ rescue StandardError => boom
+ puts "Error starting network: #{boom}"
+ end
end
def steponceinit
@@ -147,6 +154,7 @@ class IOs
attr_accessor :outputs
attr_accessor :configs
+
def initialize
@inputs = {}
@outputs = {}
@@ -205,10 +213,12 @@ class Op
attr_accessor :packets
attr_accessor :title
attr_accessor :network
- attr_accessor :opid
+ attr_reader :opid
+ attr_reader :errors
- def initialize
+ def initialize
ios = @@configs[self.class]
+ ios.outputs["errors"]=1
@opid = @@opidcounter
@@opidcounter += 1
@@ -229,9 +239,14 @@ def initialize
end
def getopname
+ # probably a method in Class that i haven't found or looked for yet
self.class.name[4..-1]
end
+ def getopid
+ "#{getopname}:#{@opid}"
+ end
+
def acceptsnil?
false
end
@@ -246,23 +261,34 @@ def Op.getopnames
# i don't think i need the static methods anymore since
# i'm not accessing from java
- def definedconfigs
+ def allconfigs
@@configs[self.class].configs
end
-
- def Op.getOpInputs(opname)
- @@configs[opname].inputs.keys
+ #todo: rename + cleanup
+ def Op.getOpInputs(opname)
+ @@configs[opname].inputs.keys
+ end
+
+ def alloutputs
+ @@configs[self.class].outputs.keys
end
+ def allinputs
+ @@configs[self.class].inputs.keys
+ end
+
+ #todo: rename + cleanup
def Op.getOpOutputs(opname)
@@configs[opname].outputs.keys
end
+ #todo: rename + cleanup
def Op.getOpConfigs(opname)
@@configs[opname].configs.keys
end
+ #todo: rename + cleanup
def Op.getOpConfigDefaultValueAndType(opname,attname)
v = instance_eval(opname.to_s + ".new()." + attname.to_s)
return [v,v.class.name]
@@ -286,6 +312,7 @@ def Op.input(name,proc)
ios = @@configs[self]
ios.inputs[name]=proc
end
+
# used to define an output in the class definition
def Op.output(name)
@@ -314,7 +341,15 @@ def Op.config(name)
def processpacket
packet = @packets.shift
if packet != nil or (packet== nil and acceptsnil?)
- self.send(packet.destinput, packet.value)
+ begin
+ self.send(packet.destinput, packet.value)
+ rescue StandardError => boom
+ puts "#{boom}"
+ puts "Invalid packet: [#{packet}]"
+ errors.out(boom)
+ end
+
+
receivedpacket(packet)
end
end
@@ -339,6 +374,11 @@ def stopping
#override me if you like
def setupio
end
+
+ #override me if you like
+ def errorhandler(value)
+ puts "Error: #{value}"
+ end
end
View
@@ -16,7 +16,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-require "DBI"
+require 'rubygems'
+gem 'dbi'
+require 'dbi'
+
+
module MM
###############################################################################
#
@@ -46,6 +50,27 @@ def echo(value)
end
end
+class DummyTable < Op
+ input :dummyin, :din
+ output :dummyout
+
+ def starting
+ data = []
+ 1.upto(10) do |i|
+ row = []
+ 1.upto(10) do |j|
+ row << j
+ end
+ data << row
+ end
+
+ @dummyout.out(data)
+ end
+
+ def din
+ end
+end
+
class Print < Op
input :printin, :print
output :printout
@@ -224,47 +249,97 @@ def mod(value)
class Each < Op
input :eachin, :doeach
output :eachout
-
+ output :eof
+
def doeach(value)
puts "EACH: #{value}"
+
value.to_a.each do |item|
eachout.out(item)
end
+ eof.out("eof")
end
end
-# probably not going to use this
-class PipeOut < Op
- input :datain, :dodatain
+
+class EachPair < Op
+ input :eachin, :doeach
+ output :eachout
+ output :eof
+
+ def doeach(value)
+ puts "EACH: #{value}"
+
+ value.each_pair do |k,v|
+ eachout.out(item)
+ end
+ eof.out("eof")
+ end
+end
+
+class Buffer < Op
+ input :bufferin, :doin
+ input :trigger, :dotrigger
+ output :bufferout
+
+ def initialize
+ super
+ @buf = Array.new
+ end
- def starting
- @network.pipesout[self.opid] = Array.new()
+ def doin(value)
+ @buf << value
end
- def dodatain(value)
- @network.pipesout[self.opid] << value
+ def dotrigger(value)
+ bufferout.out(@buf.clone)
+ @buf.clear
end
+
end
+
+# probably not going to use this
+# class PipeOut < Op
+# input :datain, :dodatain
+
+# def starting
+# @network.pipesout[self.opid] = Array.new()
+# end
+
+# def dodatain(value)
+# @network.pipesout[self.opid] << value
+# end
+# end
+
+
+
# need to spit out db metadata also!
+# should probably pass around the db connection?
+# need a way to manage resources (open + close things like files, db connections etc)
class DBQuery < Op
input :sql, :runsql
- output :queryout
+ output :rowout
+
+ output :metadataout
+ output :rowcountout
+ output :colcountout #redundant
+ output :columnnames
+ output :eof
+
config :username
config :password
config :connstr
-
+
def initialize
super
- @username=""
+ @username="root"
@password=""
- @connstr="DBI:OCI8:sid"
+ @connstr="DBI:Mysql:ub"
end
def starting
puts "DB connect"
- puts "username = [#{@username}"
- puts "password = [#{@password}"
puts "connstr = [#{@connstr}"
@dbh=DBI.connect(@connstr,@username,@password)
end
@@ -275,11 +350,18 @@ def stopping
end
def runsql(value)
- results = @dbh.select_all(value)
- queryout.out(results)
+ results = @dbh.execute(value)
+ rowcount = 0
+ results.each do |row|
+ rowout.out(row)
+ rowcount += 1
+ end
+ rowcountout.out(rowcount)
+ colcountout.out(results.column_names.size)
+ metadataout.out(results.column_info)
+ columnnames.out(results.column_names)
+ eof.out("eof")
end
-
-
end
Oops, something went wrong.

0 comments on commit 68e777c

Please sign in to comment.