Class: Equity::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/equity/controller.rb,
lib/equity/controller/key.rb

Defined Under Namespace

Modules: Alarm Classes: Key

Instance Method Summary collapse

Constructor Details

#initialize(host, port, key = Key.new) ⇒ Controller

Returns a new instance of Controller.



9
10
11
12
13
14
# File 'lib/equity/controller.rb', line 9

def initialize(host, port, key = Key.new)
  @host = host.dup
  @port = port.to_i
  @socket = UDPSocket.new
  @key = key
end

Instance Method Details

#node_statusObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/equity/controller.rb', line 16

def node_status
  reply = send(Manager::CMD_NODE_STATUS)
  return nil unless reply
  
  nodes = []
  count = reply.slice!(0, 1)[0]
  count.times do
    length, connected, counter, port = reply.slice!(0, 9).unpack('nCNn')
    address = reply.slice!(0, length - 9)
    node = Node::Static.new(address, port)
    node.connected = (connected != 0)
    node.counter = counter
    nodes << node
  end
  nodes
end

#shutdownObject



33
34
35
36
# File 'lib/equity/controller.rb', line 33

def shutdown
  reply = send(Manager::CMD_SHUTDOWN)
  !!reply
end

#waitdownObject



38
39
40
41
# File 'lib/equity/controller.rb', line 38

def waitdown
  reply = send(Manager::CMD_WAITDOWN)
  !!reply
end