Class: Lmkplz::Encasement
- Inherits:
-
Object
- Object
- Lmkplz::Encasement
- Defined in:
- lib/lmkplz/encasement.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add(dir) ⇒ Object
- #await ⇒ Object
- #free ⇒ Object
-
#initialize ⇒ Encasement
constructor
A new instance of Encasement.
- #malloc ⇒ Object
Constructor Details
#initialize ⇒ Encasement
Returns a new instance of Encasement.
3 4 5 6 7 8 9 |
# File 'lib/lmkplz/encasement.rb', line 3 def initialize @callback_mutex = Mutex.new @add_paths_mutex = Mutex.new @add_paths_queue = [] @gather_event_duration_ms = 200 @callbacks = Hash.new { -> {} } end |
Class Method Details
.define_settable_callback(name) ⇒ Object
11 12 13 14 15 |
# File 'lib/lmkplz/encasement.rb', line 11 def self.define_settable_callback(name) define_method("on_#{name}") do |&block| @callback_mutex.synchronize { @callbacks[name] = block } end end |
Instance Method Details
#active? ⇒ Boolean
64 65 66 |
# File 'lib/lmkplz/encasement.rb', line 64 def active? !!@kkttyl end |
#add(dir) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/lmkplz/encasement.rb', line 41 def add(dir) if active? Metal.kkttyl_add(kkttyl, dir) else @add_paths_mutex.synchronize do @add_paths_queue.push(dir) end end end |
#await ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lmkplz/encasement.rb', line 51 def await if !active? raise "Call #malloc before #await" end callbacks = @callback_mutex.synchronize do @callbacks.values_at(:success, :failure, :timeout, :end) end Metal.kkttyl_await(kkttyl, 40, *callbacks) end |
#free ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/lmkplz/encasement.rb', line 32 def free if !active? return end Metal.kkttyl_free(kkttyl) @kkttyl = nil end |
#malloc ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/lmkplz/encasement.rb', line 22 def malloc kkttyl @add_paths_mutex.synchronize do while @add_paths_queue.any? add(@add_paths_queue.pop) end end end |