Class: OsCtld::Console::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/console/container.rb

Overview

Instance per container, each holding a list of opened ttys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ct) ⇒ Container

Returns a new instance of Container



8
9
10
11
12
# File 'lib/osctld/console/container.rb', line 8

def initialize(ct)
  @ct = ct
  @ttys = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#ctObject (readonly)

Returns the value of attribute ct



6
7
8
# File 'lib/osctld/console/container.rb', line 6

def ct
  @ct
end

Instance Method Details

#add_client(tty_n, io) ⇒ Object



14
15
16
# File 'lib/osctld/console/container.rb', line 14

def add_client(tty_n, io)
  tty(tty_n).add_client(io)
end

#close_allObject



36
37
38
39
40
# File 'lib/osctld/console/container.rb', line 36

def close_all
  @mutex.synchronize do
    @ttys.each { |_n, tty| tty.close }
  end
end

#connect_tty0(pid, socket) ⇒ Object



18
19
20
# File 'lib/osctld/console/container.rb', line 18

def connect_tty0(pid, socket)
  tty(0).connect(pid, socket)
end

#syncObject (protected)



43
44
45
# File 'lib/osctld/console/container.rb', line 43

def sync
  @mutex.synchronize { yield }
end

#tty(n) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/osctld/console/container.rb', line 22

def tty(n)
  @mutex.synchronize do
    if !@ttys.has_key?(n)
      klass = n == 0 ? Console::Console : Console::TTY
      @ttys[n] = tty = klass.new(ct, n)
      tty.start
      tty

    else
      @ttys[n]
    end
  end
end