Class: ProcessCommand::Signal::Receiver

Inherits:
BaseReceiver show all
Defined in:
lib/process_command/signal/receiver.rb

Constant Summary collapse

RECEIVER_QUEUE =
Queue.new

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from BaseReceiver

add_command_block, run_command_block

Class Attribute Details

.commandObject

Returns the value of attribute command.



9
10
11
# File 'lib/process_command/signal/receiver.rb', line 9

def command
  @command
end

Class Method Details

.initObject



12
13
14
15
# File 'lib/process_command/signal/receiver.rb', line 12

def init
  @command = 0
  super
end

.init_handlerObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/process_command/signal/receiver.rb', line 29

def init_handler
  while value = RECEIVER_QUEUE.pop
    command = Receiver.command
    case value
    when 0
      command <<= 1
    when 1
      command <<= 1
      command |= 1
    when :control
      run_command_block Command.i2s(command) if command
      command = 0
    else
      ProcessCommand.logger.error "illegal value #{value}, reset command 0"
      command = 0
    end
    self.command = command
  end
end

.init_listenerObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/process_command/signal/receiver.rb', line 17

def init_listener
  ::Signal.trap(Setting.bit0) do
    Thread.new{ RECEIVER_QUEUE << 0}
  end
  ::Signal.trap(Setting.bit1) do
    Thread.new{ RECEIVER_QUEUE << 1}
  end
  ::Signal.trap(Setting.control) do
    Thread.new{ RECEIVER_QUEUE << :control}
  end
end