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.



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

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

Instance Attribute Details

#ctObject (readonly)

Returns the value of attribute ct.



4
5
6
# File 'lib/osctld/console/container.rb', line 4

def ct
  @ct
end

Instance Method Details

#add_client(tty_n, io) ⇒ Object



12
13
14
# File 'lib/osctld/console/container.rb', line 12

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

#close_allObject



34
35
36
37
38
# File 'lib/osctld/console/container.rb', line 34

def close_all
  @mutex.synchronize do
    @ttys.each_value(&:close)
  end
end

#connect_tty0(pid, socket) ⇒ Object



16
17
18
# File 'lib/osctld/console/container.rb', line 16

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

#syncObject (protected)



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

def sync(&)
  @mutex.synchronize(&)
end

#tty(n) ⇒ Object



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

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

    end
  end
end