Class: OMF::OML::OmlEndpoint

Inherits:
Base::LObject
  • Object
show all
Defined in:
lib/omf_oml/endpoint.rb

Overview

This class parses an OML network stream and creates various OML mstreams which can be visualized. After creating the object, the @run@ method needs to be called to start processing the stream.

Instance Method Summary collapse

Constructor Details

#initialize(port = 5000, host = "0.0.0.0") ⇒ OmlEndpoint

Returns a new instance of OmlEndpoint.



31
32
33
34
35
36
37
# File 'lib/omf_oml/endpoint.rb', line 31

def initialize(port = 5000, host = "0.0.0.0")
  require 'socket'
  debug "OML client listening on #{port}"
  @serv = TCPServer.new(host, port)
  @running = false
  @on_new_stream_procs = {}
end

Instance Method Details

#on_new_stream(key = :_, &proc) ⇒ Object

Register a proc to be called when a new stream was discovered on this endpoint.



23
24
25
26
27
28
29
# File 'lib/omf_oml/endpoint.rb', line 23

def on_new_stream(key = :_, &proc)
  if proc
    @on_new_stream_procs[key] = proc
  else
    @on_new_stream_procs.delete key
  end
end

#report_new_stream(name, stream) ⇒ Object



39
40
41
42
43
# File 'lib/omf_oml/endpoint.rb', line 39

def report_new_stream(name, stream)
  @on_new_stream_procs.each_value do |proc|
    proc.call(name, stream)
  end
end

#run(in_thread = true) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/omf_oml/endpoint.rb', line 45

def run(in_thread = true)
  if in_thread
    Thread.new do
      _run
    end
  else
    _run
  end
end