Class: Roby::CLI::Display

Inherits:
Thor
  • Object
show all
Defined in:
lib/roby/cli/display.rb

Constant Summary collapse

Server =
Roby::DRoby::Logfile::Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



109
110
111
# File 'lib/roby/cli/display.rb', line 109

def config_path
  @config_path
end

Instance Method Details

#backward(*path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roby/cli/display.rb', line 26

def backward(*path)
    host, port = "localhost", Server::DEFAULT_PORT
    if remote_addr = options[:client] || options[:host]
        if options[:host]
            Roby.warn_deprecated "--host is deprecated, use 'roby-display client' instead, run roby-display help for more information"
        else
            Roby.warn_deprecated "roby-display --client=HOST is now roby-display client HOST, run roby-display help for more information"
        end
        if vagrant_host = options[:vagrant]
            _, port = remote_addr.split(":")
            remote_addr = "vagrant:#{vagrant_host}:#{port}"
        end
        client(remote_addr)
    elsif bind_port = options[:server]
        Roby.warn_deprecated "roby-display --server PATH is now roby-display server PATH, run roby-display help for more information"
        server(*path, port: bind_port)
    else
        file(*path)
    end
end

#client(remote_addr) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/roby/cli/display.rb', line 59

def client(remote_addr)
    apply_common_options

    host, port = resolve_remote_host(remote_addr)
    with_display do |app, display|
        display.connect(host, port: port)
    end
end

#file(path, index_path: nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/roby/cli/display.rb', line 49

def file(path, index_path: nil)
    apply_common_options

    with_display do |app, display|
        display.open(path, index_path: index_path)
    end
end

#server(path, port: options[:port]) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/roby/cli/display.rb', line 77

def server(path, port: options[:port])
    # NOTE: the 'port' argument is here so that it can be overriden
    # in {#backward}
    apply_common_options

    if (server_fd = options[:fd])
        server_io = TCPServer.for_fd(server_fd)
    else
        server_io =
            begin
                TCPServer.new(port)
            # Workaround for https://bugs.ruby-lang.org/issues/10203
            rescue TypeError
                raise Errno::EADDRINUSE,
                      "Address already in use - bind(2) for "\
                      "\"0.0.0.0\" port #{port}"
            end
    end

    server = Roby::DRoby::Logfile::Server.new(
        path, options[:sampling], server_io
    )
    port = server_io.local_address.ip_port
    Server.info "Roby log server listening on port #{port}, "\
                "sampling period=#{options[:sampling]}"
    Server.info "watching #{path}"
    server.exec
ensure
    server&.close
    server_io&.close
end