Class: RokuBuilder::Monitor

Inherits:
Util
  • Object
show all
Defined in:
lib/roku_builder/monitor.rb

Overview

Monitor development Logs

Instance Method Summary collapse

Methods inherited from Util

#initialize, #multipart_connection, options_parse, #simple_connection

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Instance Method Details

#initObject

Initialize port config



9
10
11
12
13
14
15
16
17
18
# File 'lib/roku_builder/monitor.rb', line 9

def init()
  @ports = {
    main: 8085,
    sg: 8089,
    task1: 8090,
    task2: 8091,
    task3: 8092,
    taskX: 8093,
  }
end

#monitor(type:) ⇒ Object

Monitor a development log on the Roku device

Parameters:

  • type (Symbol)

    The log type to monitor



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/roku_builder/monitor.rb', line 22

def monitor(type:)
  telnet_config = {
    'Host' => @roku_ip_address,
    'Port' => @ports[type]
  }
  waitfor_config = {
    'Match' => /./,
    'Timeout' => false
  }

  thread = Thread.new(telnet_config, waitfor_config) {|telnet,waitfor|
    @logger.info "Monitoring #{type} console(#{telnet['Port']}) on #{telnet['Host'] }"
    connection = Net::Telnet.new(telnet)
    Thread.current[:connection] = connection
    all_text = ""
    while true
      connection.waitfor(waitfor) do |txt|
        all_text = manage_text(all_text: all_text, txt: txt)
      end
    end
  }
  running = true
  while running
    begin
      @logger.unknown "Q to exit"
      command = gets.chomp
      case command
      when "q"
        thread.exit
        running = false
      when "stop"
        thread[:connection].puts("\C-c")
      else
        thread[:connection].puts(command)
      end
    rescue SystemExit, Interrupt
      thread[:connection].puts("\C-c")
    end
  end
end