Class: Punchblock::Translator::Asterisk::Component::Component

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/punchblock/translator/asterisk/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_node, call = nil) ⇒ Component

Returns a new instance of Component.



17
18
19
20
21
22
# File 'lib/punchblock/translator/asterisk/component.rb', line 17

def initialize(component_node, call = nil)
  @component_node, @call = component_node, call
  @id = UUIDTools::UUID.random_create.to_s
  setup
  pb_logger.debug "Starting up..."
end

Instance Attribute Details

#callObject (readonly)

Returns the value of attribute call.



14
15
16
# File 'lib/punchblock/translator/asterisk/component.rb', line 14

def call
  @call
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/punchblock/translator/asterisk/component.rb', line 14

def id
  @id
end

#internalObject

Returns the value of attribute internal.



15
16
17
# File 'lib/punchblock/translator/asterisk/component.rb', line 15

def internal
  @internal
end

Instance Method Details

#call_idObject



54
55
56
# File 'lib/punchblock/translator/asterisk/component.rb', line 54

def call_id
  call.id if call
end

#execute_command(command) ⇒ Object



27
28
29
# File 'lib/punchblock/translator/asterisk/component.rb', line 27

def execute_command(command)
  command.response = ProtocolError.new 'command-not-acceptable', "Did not understand command for component #{id}", call_id, id
end

#logger_idObject



50
51
52
# File 'lib/punchblock/translator/asterisk/component.rb', line 50

def logger_id
  "#{self.class}: #{call ? "Call ID: #{call.id}, Component ID: #{id}" : id}"
end

#send_complete_event(reason) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/punchblock/translator/asterisk/component.rb', line 31

def send_complete_event(reason)
  event = Punchblock::Event::Complete.new.tap do |c|
    c.reason = reason
  end
  send_event event
  current_actor.terminate!
end

#send_event(event) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/punchblock/translator/asterisk/component.rb', line 39

def send_event(event)
  event.component_id  = id
  event.call_id       = call_id
  pb_logger.debug "Sending event #{event}"
  if internal
    @component_node.add_event event
  else
    translator.connection.handle_event event
  end
end

#setupObject



24
25
# File 'lib/punchblock/translator/asterisk/component.rb', line 24

def setup
end