Class: CZMQ::FFI::Ztimerset

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb

Overview

Note:

This class is 100% generated using zproject.

timer set

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Ztimerset

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


24
25
26
27
28
29
30
31
32
# 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

Class Method Details

.__newObject



18
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 18

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


35
36
37
38
39
40
41
42
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 35

def self.create_finalizer_for(ptr)
  ptr_ptr = ::FFI::MemoryPointer.new :pointer

  Proc.new do
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.ztimerset_destroy ptr_ptr
  end
end

.fnObject

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.

Create a new callback of the following type: Callback function for timer event.

typedef void (ztimerset_fn) (
    int timer_id, void *arg);


86
87
88
89
90
91
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 86

def self.fn
  ::FFI::Function.new :void, [:int, :pointer], blocking: true do |timer_id, arg|
    result = yield timer_id, arg
    result
  end
end

.newCZMQ::Ztimerset

Create new timer set.

Returns:

  • (CZMQ::Ztimerset)


95
96
97
98
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 95

def self.new()
  ptr = ::CZMQ::FFI.ztimerset_new()
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


192
193
194
195
196
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 192

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.ztimerset_test(verbose)
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



49
50
51
52
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 49

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



60
61
62
63
64
65
66
67
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 60

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

#__undef_finalizervoid

Note:

Only use this if you need to and can guarantee that the native object will be freed by other means.

This method returns an undefined value.

Undefines the finalizer for this object.



72
73
74
75
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 72

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#add(interval, handler, arg) ⇒ Integer

Add a timer to the set. Returns timer id if OK, -1 on failure.

Parameters:

  • interval (Integer, #to_int, #to_i)
  • handler (::FFI::Pointer, #to_ptr)
  • arg (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



116
117
118
119
120
121
122
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 116

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(timer_id) ⇒ Integer

Cancel a timer. Returns 0 if OK, -1 on failure.

Parameters:

  • timer_id (Integer, #to_int, #to_i)

Returns:

  • (Integer)

Raises:



128
129
130
131
132
133
134
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 128

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

#destroyvoid

This method returns an undefined value.

Destroy a timer set



103
104
105
106
107
108
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 103

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.ztimerset_destroy(self_p)
  result
end

#executeInteger

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.

Returns:

  • (Integer)

Raises:



181
182
183
184
185
186
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 181

def execute()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.ztimerset_execute(self_p)
  result
end

#null?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 44

def null?
  !@ptr or @ptr.null?
end

#reset(timer_id) ⇒ Integer

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.

Parameters:

  • timer_id (Integer, #to_int, #to_i)

Returns:

  • (Integer)

Raises:



156
157
158
159
160
161
162
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 156

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_interval(timer_id, interval) ⇒ Integer

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.

Parameters:

  • timer_id (Integer, #to_int, #to_i)
  • interval (Integer, #to_int, #to_i)

Returns:

  • (Integer)

Raises:



142
143
144
145
146
147
148
149
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 142

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

#timeoutInteger

Return the time until the next interval. Should be used as timeout parameter for the zpoller wait method. The timeout is in msec.

Returns:

  • (Integer)

Raises:



169
170
171
172
173
174
# File 'lib/czmq-ffi-gen/czmq/ffi/ztimerset.rb', line 169

def timeout()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.ztimerset_timeout(self_p)
  result
end