Class: RIO::Piper::Base

Inherits:
Object show all
Defined in:
lib/rio/piper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r1, r2, *args) ⇒ Base

Returns a new instance of Base.



41
42
43
44
45
46
47
48
# File 'lib/rio/piper.rb', line 41

def initialize(r1,r2,*args)
  @rios = []
  add_arg(r1)
  add_arg(r2)
  args.each { |r|
    add_arg(r)
  }
end

Instance Attribute Details

#riosObject (readonly)

Returns the value of attribute rios.



40
41
42
# File 'lib/rio/piper.rb', line 40

def rios
  @rios
end

Instance Method Details

#add_arg(arg) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rio/piper.rb', line 49

def add_arg(arg)
  case arg
  when Base
    @rios += arg.rios
  when Rio
    case arg.scheme
    when 'cmdpipe'
      arg_piper = arg.rl.piper
      @rios += arg_piper.rios
    else
      @rios << arg
    end
  else
    raise ArgumentError,"Argument (#{arg}) is a #{arg.class}, should be a Rio or a Piper"
  end
end

#has_output_dest?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
# File 'lib/rio/piper.rb', line 69

def has_output_dest?
  case @rios[-1].scheme
  when 'cmdio' then false
  else true
  end
end

#initialize_copy(*args) ⇒ Object



65
66
67
68
# File 'lib/rio/piper.rb', line 65

def initialize_copy(*args)
  super
  @rios = @rios.map{ |r| r.clone }
end

#new_with(*args) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/rio/piper.rb', line 75

def new_with(*args)
  cp = self.clone
  args.each { |r|
    cp.push(r)
  }
  cp
end

#push(r) ⇒ Object



82
83
84
# File 'lib/rio/piper.rb', line 82

def push(r)
  @rios << r
end

#rdObject



90
# File 'lib/rio/piper.rb', line 90

def rd() @rios[-1] end

#runObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rio/piper.rb', line 93

def run
  #dups = @rios.map { |r| r.clone }
  dups = @rios
  (1...dups.size-1).each { |i| dups[i].w! }
  (1...dups.size).each { |i|
    #p "#{dups[i-1].cx.inspect} > #{dups[i].cx.inspect}"
    dups[i-1] > dups[i]
    #p dups[i-1].closed?
  }
  dups.each { |r| r.close.softreset }
  dups[-1]
end

#run_to(r) ⇒ Object



85
86
87
88
89
# File 'lib/rio/piper.rb', line 85

def run_to(r)
  @rios << r
  run
  self
end

#runethObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rio/piper.rb', line 106

def runeth
  dups = @rios.map { |r| r.clone }

  (1...dups.size-1).each { |i| dups[i].w! }
  
  threads = []
  (1...dups.size).each { |i|
    threads << Thread.new(dups[i-1],dups[i]) { |src,dst|
      src > dst
    } 
  }
  threads.each { |aThread| aThread.join }
end

#wrObject



91
# File 'lib/rio/piper.rb', line 91

def wr() @rios[0] end