Class: CZMQ::FFI::Zclock

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

Overview

Note:

This class is 100% generated using zproject.

millisecond clocks and delays

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zclock

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/zclock.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

.create_finalizer_for(ptr) ⇒ Proc

Returns:

  • (Proc)


34
35
36
37
38
39
40
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 34

def self.create_finalizer_for(ptr)
  Proc.new do
    "WARNING: "\
    "Objects of type #{self} cannot be destroyed implicitly. "\
    "Please call the correct destroy method with the relevant arguments."
  end
end

.mono::FFI::Pointer

Return current monotonic clock in milliseconds. Use this when you compute time offsets. The monotonic clock is not affected by system changes and so will never be reset backwards, unlike a system clock.

Returns:

  • (::FFI::Pointer)


100
101
102
103
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 100

def self.mono()
  result = ::CZMQ::FFI.zclock_mono()
  result
end

.sleep(msecs) ⇒ void

This method returns an undefined value.

Sleep for a number of milliseconds

Parameters:

  • msecs (Integer, #to_int, #to_i)


79
80
81
82
83
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 79

def self.sleep(msecs)
  msecs = Integer(msecs)
  result = ::CZMQ::FFI.zclock_sleep(msecs)
  result
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


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

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

.time::FFI::Pointer

Return current system clock as milliseconds. Note that this clock can jump backwards (if the system clock is changed) so is unsafe to use for timers and time offsets. Use zclock_mono for that instead.

Returns:

  • (::FFI::Pointer)


90
91
92
93
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 90

def self.time()
  result = ::CZMQ::FFI.zclock_time()
  result
end

.timestr::FFI::AutoPointer

Return formatted date/time as fresh string. Free using zstr_free().

Returns:

  • (::FFI::AutoPointer)


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

def self.timestr()
  result = ::CZMQ::FFI.zclock_timestr()
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

.usecs::FFI::Pointer

Return current monotonic clock in microseconds. Use this when you compute time offsets. The monotonic clock is not affected by system changes and so will never be reset backwards, unlike a system clock.

Returns:

  • (::FFI::Pointer)


110
111
112
113
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 110

def self.usecs()
  result = ::CZMQ::FFI.zclock_usecs()
  result
end

Instance Method Details

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

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



47
48
49
50
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 47

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:



58
59
60
61
62
63
64
65
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 58

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.



70
71
72
73
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 70

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#null?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/czmq-ffi-gen/czmq/ffi/zclock.rb', line 42

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