Class: Elrpc::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/elrpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ Service

cmd = [“ruby”, “_call.rb”]



70
71
72
# File 'lib/elrpc.rb', line 70

def initialize(cmd)
  @cmd = cmd
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



66
67
68
# File 'lib/elrpc.rb', line 66

def client
  @client
end

#cmdObject (readonly)

Returns the value of attribute cmd.



66
67
68
# File 'lib/elrpc.rb', line 66

def cmd
  @cmd
end

#outputObject (readonly)

Returns the value of attribute output.



67
68
69
# File 'lib/elrpc.rb', line 67

def output
  @output
end

#portObject (readonly)

Returns the value of attribute port.



66
67
68
# File 'lib/elrpc.rb', line 66

def port
  @port
end

Instance Method Details

#_start_loggerObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/elrpc.rb', line 74

def _start_logger
  return Thread.start do
    stdout = @io3[1]
    stderr = @io3[2]
    loop do
      IO.select([stdout, stderr]).flatten.compact.each do |io|
        io.each do |line|
          next if line.nil? || line.empty?
          @logger.puts(line) if @logger
        end
      end
      break if stdout.eof? && stderr.eof?
    end
  end
end

#call_method(name, *args) ⇒ Object



112
113
114
# File 'lib/elrpc.rb', line 112

def call_method(name, *args)
  @client.call_method(name, *args)
end

#call_method_async(name, *args, &block) ⇒ Object



108
109
110
# File 'lib/elrpc.rb', line 108

def call_method_async(name, *args, &block)
  @client.call_method_async(name, *args, &block)
end

#def_method(name, argdoc = nil, docstring = nil, &block) ⇒ Object



104
105
106
# File 'lib/elrpc.rb', line 104

def def_method(name, argdoc=nil, docstring=nil, &block)
  @client.def_method(name, argdoc, docstring, &block)
end

#query_methodsObject



120
121
122
# File 'lib/elrpc.rb', line 120

def query_methods
  @client.query_methods
end

#query_methods_async(&block) ⇒ Object



116
117
118
# File 'lib/elrpc.rb', line 116

def query_methods_async(&block)
  @client.query_methods(&block)
end

#register_method(method) ⇒ Object



100
101
102
# File 'lib/elrpc.rb', line 100

def register_method(method)
  @client.register_method(method)
end

#startObject



90
91
92
93
94
95
96
97
98
# File 'lib/elrpc.rb', line 90

def start
  @io3 = Open3.popen3(@cmd) # stdin, stdout, stderr, wait_thr
  @port = @io3[2].readline.to_i
  @io3[0].close
  @output = nil
  @thread = _start_logger
  @client = Elrpc.start_client(@port)
  return self
end

#stopObject



124
125
126
127
128
# File 'lib/elrpc.rb', line 124

def stop
  @client.stop
  @io3[1].close
  @io3[2].close
end