class CZMQ::FFI::Ztimerset
timer set @note This class is 100% generated using zproject.
Public Class Methods
@param ptr [::FFI::Pointer] @return [Proc]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 35 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.ztimerset_destroy ptr_ptr end end
Create a new callback of the following type: Callback function for timer event.
typedef void (ztimerset_fn) ( int timer_id, void *arg);
@note WARNING: If your Ruby code doesn't retain a reference to the
FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 85 def self.fn ::FFI::Function.new :void, [:int, :pointer], blocking: true do |timer_id, arg| result = yield timer_id, arg result end end
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end
Create new timer set. @return [CZMQ::Ztimerset]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 94 def self.new() ptr = ::CZMQ::FFI.ztimerset_new() __new ptr end
Self test of this class.
@param verbose [Boolean] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 191 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.ztimerset_test(verbose) result end
Public Instance Methods
Return internal pointer @return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 48 def __ptr raise DestroyedError unless @ptr @ptr end
Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object
and thus makes it unusable.
@return [::FFI::MemoryPointer] the pointer pointing to a pointer
pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 59 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end
Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native
object will be freed by other means.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 71 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end
Add a timer to the set. Returns timer id if OK, -1 on failure.
@param interval [Integer, to_int, to_i] @param handler [::FFI::Pointer, to_ptr
] @param arg [::FFI::Pointer, to_ptr
] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 115 def add(interval, handler, arg) raise DestroyedError unless @ptr self_p = @ptr interval = Integer(interval) result = ::CZMQ::FFI.ztimerset_add(self_p, interval, handler, arg) result end
Cancel a timer. Returns 0 if OK, -1 on failure.
@param timer_id [Integer, to_int, to_i] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 127 def cancel(timer_id) raise DestroyedError unless @ptr self_p = @ptr timer_id = Integer(timer_id) result = ::CZMQ::FFI.ztimerset_cancel(self_p, timer_id) result end
Destroy a timer set
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 102 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.ztimerset_destroy(self_p) result end
Invoke callback function of all timers which their interval has elapsed. Should be call after zpoller wait method. Returns 0 if OK, -1 on failure.
@return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 180 def execute() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztimerset_execute(self_p) result end
@return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 43 def null? !@ptr or @ptr.null? end
Reset timer to start interval counting from current time. Returns 0 if OK, -1 on failure. This method is slow, canceling the timer and adding a new one yield better performance.
@param timer_id [Integer, to_int, to_i] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 155 def reset(timer_id) raise DestroyedError unless @ptr self_p = @ptr timer_id = Integer(timer_id) result = ::CZMQ::FFI.ztimerset_reset(self_p, timer_id) result end
Set timer interval. Returns 0 if OK, -1 on failure. This method is slow, canceling the timer and adding a new one yield better performance.
@param timer_id [Integer, to_int, to_i] @param interval [Integer, to_int, to_i] @return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 141 def set_interval(timer_id, interval) raise DestroyedError unless @ptr self_p = @ptr timer_id = Integer(timer_id) interval = Integer(interval) result = ::CZMQ::FFI.ztimerset_set_interval(self_p, timer_id, interval) result end
Return the time until the next interval. Should be used as timeout parameter for the zpoller wait method. The timeout is in msec.
@return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb, line 168 def timeout() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.ztimerset_timeout(self_p) result end