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

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

Direct Known Subclasses

Asterisk::AGICommand, Asterisk::AMIAction, Input, Output

Constant Summary

OptionError =
Class.new Punchblock::Error

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Component) initialize(component_node, call = nil)

A new instance of Component



22
23
24
25
26
27
# File 'lib/punchblock/translator/asterisk/component.rb', line 22

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

- (Object) call (readonly)

Returns the value of attribute call



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

def call
  @call
end

- (Object) id (readonly)

Returns the value of attribute id



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

def id
  @id
end

- (Object) internal

Returns the value of attribute internal



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

def internal
  @internal
end

Instance Method Details

- (Object) call_id



59
60
61
# File 'lib/punchblock/translator/asterisk/component.rb', line 59

def call_id
  call.id if call
end

- (Object) execute_command(command)



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

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

- (Object) logger_id



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

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

- (Object) send_complete_event(reason)



36
37
38
39
40
41
42
# File 'lib/punchblock/translator/asterisk/component.rb', line 36

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

- (Object) send_event(event)



44
45
46
47
48
49
50
51
52
53
# File 'lib/punchblock/translator/asterisk/component.rb', line 44

def send_event(event)
  event.component_id    = id
  event.target_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

- (Object) setup



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

def setup
end