Class: Librevox::Listener::Base

Inherits:
EventMachine::Protocols::HeaderAndContentProtocol
  • Object
show all
Defined in:
lib/librevox/listener/base.rb

Direct Known Subclasses

Inbound, Outbound

Defined Under Namespace

Classes: CommandDelegate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject Also known as: event

Returns the value of attribute response



50
51
52
# File 'lib/librevox/listener/base.rb', line 50

def response
  @response
end

Class Method Details

.event(event, &block) ⇒ Object



13
14
15
# File 'lib/librevox/listener/base.rb', line 13

def event event, &block
  hooks[event] << block
end

.hooksObject



9
10
11
# File 'lib/librevox/listener/base.rb', line 9

def hooks
  @hooks ||= Hash.new {|hash, key| hash[key] = []}
end

Instance Method Details

#apiObject

Exposes an instance of CommandDelegate, which includes Commands.

Examples:

api.status
api.fsctl :pause
api.uuid_park "592567a2-1be4-11df-a036-19bfdab2092f"

See Also:



40
41
42
# File 'lib/librevox/listener/base.rb', line 40

def api
  @command_delegate ||= CommandDelegate.new(self)
end

#command(msg, &block) ⇒ Object



44
45
46
47
48
# File 'lib/librevox/listener/base.rb', line 44

def command msg, &block
  send_data "#{msg}\n\n"

  @command_queue.push(block)
end

#handle_responseObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/librevox/listener/base.rb', line 62

def handle_response
  if response.api_response? && @command_queue.any?
    @command_queue.shift.call(response)
  end

  if response.event?
    on_event(response.dup)
    invoke_event_hooks
  end
end

#on_event(event) ⇒ Object

override



74
75
# File 'lib/librevox/listener/base.rb', line 74

def on_event event
end

#post_initObject



53
54
55
# File 'lib/librevox/listener/base.rb', line 53

def post_init
  @command_queue = []
end

#receive_request(header, content) ⇒ Object



57
58
59
60
# File 'lib/librevox/listener/base.rb', line 57

def receive_request header, content
  @response = Librevox::Response.new(header, content)
  handle_response
end