Module: Libuv::Listener::ClassMethods
- Defined in:
- lib/libuv/mixins/listener.rb
Instance Attribute Summary collapse
-
#callback_funcs ⇒ Object
readonly
Provide accessor methods to the class level instance variables.
-
#callback_lock ⇒ Object
readonly
Provide accessor methods to the class level instance variables.
-
#callback_lookup ⇒ Object
readonly
Provide accessor methods to the class level instance variables.
Instance Method Summary collapse
-
#default_lookup(req, *args) ⇒ Object
This function is used to work out the instance the callback is for.
- #define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) ⇒ Object
- #dispatch_callback(func_name, lookup, args) ⇒ Object
-
#inherited(subclass) ⇒ Object
Much like include to support inheritance properly We keep existing callbacks and inherit the lookup (as this will never clash).
Instance Attribute Details
#callback_funcs ⇒ Object (readonly)
Provide accessor methods to the class level instance variables
35 36 37 |
# File 'lib/libuv/mixins/listener.rb', line 35 def callback_funcs @callback_funcs end |
#callback_lock ⇒ Object (readonly)
Provide accessor methods to the class level instance variables
35 36 37 |
# File 'lib/libuv/mixins/listener.rb', line 35 def callback_lock @callback_lock end |
#callback_lookup ⇒ Object (readonly)
Provide accessor methods to the class level instance variables
35 36 37 |
# File 'lib/libuv/mixins/listener.rb', line 35 def callback_lookup @callback_lookup end |
Instance Method Details
#default_lookup(req, *args) ⇒ Object
This function is used to work out the instance the callback is for
39 40 41 |
# File 'lib/libuv/mixins/listener.rb', line 39 def default_lookup(req, *args) req.address end |
#define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) ⇒ Object
19 20 21 22 23 |
# File 'lib/libuv/mixins/listener.rb', line 19 def define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup) @callback_funcs[function] = ::FFI::Function.new(ret_val, params) do |*args| dispatch_callback(function, lookup, args) end end |
#dispatch_callback(func_name, lookup, args) ⇒ Object
13 14 15 16 17 |
# File 'lib/libuv/mixins/listener.rb', line 13 def dispatch_callback(func_name, lookup, args) instance_id = __send__(lookup, *args) inst = @callback_lookup[instance_id] inst.__send__(func_name, *args) end |
#inherited(subclass) ⇒ Object
Much like include to support inheritance properly We keep existing callbacks and inherit the lookup (as this will never clash)
27 28 29 30 31 |
# File 'lib/libuv/mixins/listener.rb', line 27 def inherited(subclass) subclass.instance_variable_set(:@callback_funcs, {}.merge(@callback_funcs)) subclass.instance_variable_set(:@callback_lookup, @callback_lookup) subclass.instance_variable_set(:@callback_lock, @callback_lock) end |