Class: ActiveVlc::LibVlc::EventManager

Inherits:
Object
  • Object
show all
Defined in:
lib/activevlc/libvlc/event_manager.rb

Constant Summary collapse

EventType =
Api::EventType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ EventManager

Returns a new instance of EventManager.



12
13
14
15
16
17
18
# File 'lib/activevlc/libvlc/event_manager.rb', line 12

def initialize(ptr)
  @ptr = ptr
  @callbacks = {}
  @events_received = 0

  @event_handler = Proc.new { |event, void| _event(event, void) }
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



10
11
12
# File 'lib/activevlc/libvlc/event_manager.rb', line 10

def callbacks
  @callbacks
end

#events_receivedObject (readonly)

Returns the value of attribute events_received.



10
11
12
# File 'lib/activevlc/libvlc/event_manager.rb', line 10

def events_received
  @events_received
end

Instance Method Details

#on(types, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/activevlc/libvlc/event_manager.rb', line 20

def on(types, &block)
  event_is_valid = true
  types = [types] unless types.is_a? Array
  # Get the enum value if we gat a Symbol or String

  types.each do |type|
    if type.is_a?(String) or type.is_a?(Symbol)
      type = EventType[type.to_sym]
    end

    # If this is the first callback for this type, register the :event_handler
    # using vlc's API and create the proc array for that 'type'.
    unless @callbacks[type]
      event_is_valid = Api.libvlc_event_attach(@ptr, type, @event_handler, nil) == 0
      @callbacks[type] = Array.new if event_is_valid
    end
    @callbacks[type].push block if event_is_valid
  end
end