Class: CZMQ::FFI::Zconfig

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

Overview

Note:

This class is 100% generated using zproject.

work with config files written in rfc.zeromq.org/spec:4/ZPL.

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zconfig

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/zconfig.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/zconfig.rb', line 18

alias :__new :new

.chunk_load(chunk) ⇒ Zconfig

Load a config tree from a memory chunk

Parameters:

Returns:



355
356
357
358
359
360
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 355

def self.chunk_load(chunk)
  chunk = chunk.__ptr if chunk
  result = ::CZMQ::FFI.zconfig_chunk_load(chunk)
  result = Zconfig.__new result, false
  result
end

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


35
36
37
38
39
40
41
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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.zconfig_destroy ptr_ptr
  end
end

.fctObject

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:

typedef int (zconfig_fct) (
    zconfig_t *self, void *arg, int level);


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

def self.fct
  ::FFI::Function.new :int, [:pointer, :pointer, :int], blocking: true do |self_, arg, level|
    self_ = Zconfig.__new self_, false
    result = yield self_, arg, level
    result = Integer(result)
    result
  end
end

.load(filename) ⇒ CZMQ::Zconfig

Load a config tree from a specified ZPL text file; returns a zconfig_t reference for the root, if the file exists and is readable. Returns NULL if the file does not exist.

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (CZMQ::Zconfig)


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

def self.load(filename)
  ptr = ::CZMQ::FFI.zconfig_load(filename)
  __new ptr
end

.loadf(format, *args) ⇒ CZMQ::Zconfig

Equivalent to zconfig_load, taking a format string instead of a fixed filename.

Parameters:

  • format (String, #to_s, nil)
  • args (Array<Object>)

Returns:

  • (CZMQ::Zconfig)


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

def self.loadf(format, *args)
  ptr = ::CZMQ::FFI.zconfig_loadf(format, *args)
  __new ptr
end

.new(name, parent) ⇒ CZMQ::Zconfig

Create new config item

Parameters:

Returns:

  • (CZMQ::Zconfig)


98
99
100
101
102
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 98

def self.new(name, parent)
  parent = parent.__ptr if parent
  ptr = ::CZMQ::FFI.zconfig_new(name, parent)
  __new ptr
end

.reload(self_p) ⇒ Integer

Reload config tree from same file that it was previously loaded from. Returns 0 if OK, -1 if there was an error (and then does not change existing data).

Parameters:

Returns:

  • (Integer)


345
346
347
348
349
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 345

def self.reload(self_p)
  self_p = self_p.__ptr_give_ref
  result = ::CZMQ::FFI.zconfig_reload(self_p)
  result
end

.remove(self_p) ⇒ void

This method returns an undefined value.

Destroy node and subtree (all children)

Parameters:



419
420
421
422
423
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 419

def self.remove(self_p)
  self_p = self_p.__ptr_give_ref
  result = ::CZMQ::FFI.zconfig_remove(self_p)
  result
end

.str_load(string) ⇒ Zconfig

Load a config tree from a null-terminated string

Parameters:

  • string (String, #to_s, nil)

Returns:



377
378
379
380
381
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 377

def self.str_load(string)
  result = ::CZMQ::FFI.zconfig_str_load(string)
  result = Zconfig.__new result, true
  result
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class

Parameters:

  • verbose (Boolean)


450
451
452
453
454
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 450

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

Instance Method Details

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

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



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

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:



59
60
61
62
63
64
65
66
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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

#__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.



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

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#at_depth(level) ⇒ Zconfig

Locate the last config item at a specified depth

Parameters:

  • level (Integer, #to_int, #to_i)

Returns:

Raises:



257
258
259
260
261
262
263
264
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 257

def at_depth(level)
  raise DestroyedError unless @ptr
  self_p = @ptr
  level = Integer(level)
  result = ::CZMQ::FFI.zconfig_at_depth(self_p, level)
  result = Zconfig.__new result, false
  result
end

#childZconfig

Find our first child, if any

Returns:

Raises:



222
223
224
225
226
227
228
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 222

def child()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_child(self_p)
  result = Zconfig.__new result, false
  result
end

#chunk_saveZchunk

Save a config tree to a new memory chunk

Returns:

Raises:



365
366
367
368
369
370
371
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 365

def chunk_save()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_chunk_save(self_p)
  result = Zchunk.__new result, false
  result
end

#commentsZlist

Return comments of config item, as zlist.

Returns:

Raises:



296
297
298
299
300
301
302
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 296

def comments()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_comments(self_p)
  result = Zlist.__new result, false
  result
end

#destroyvoid

This method returns an undefined value.

Destroy a config item and all its children



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

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

#execute(handler, arg) ⇒ Integer

Execute a callback for each config item in the tree; returns zero if successful, else -1.

Parameters:

  • handler (::FFI::Pointer, #to_ptr)
  • arg (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



272
273
274
275
276
277
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 272

def execute(handler, arg)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_execute(self_p, handler, arg)
  result
end

#filenameString

Report filename used during zconfig_load, or NULL if none

Returns:

  • (String)

Raises:



332
333
334
335
336
337
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 332

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

#fprint(file) ⇒ void

This method returns an undefined value.

Print the config file to open stream

Parameters:

  • file (::FFI::Pointer, #to_ptr)

Raises:



429
430
431
432
433
434
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 429

def fprint(file)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_fprint(self_p, file)
  result
end

#get(path, default_value) ⇒ ::FFI::Pointer

Get value for config item into a string value; leading slash is optional and ignored.

Parameters:

  • path (String, #to_s, nil)
  • default_value (String, #to_s, nil)

Returns:

  • (::FFI::Pointer)

Raises:



186
187
188
189
190
191
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 186

def get(path, default_value)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_get(self_p, path, default_value)
  result
end

#has_changedBoolean

Return true if a configuration tree was loaded from a file and that file has changed in since the tree was loaded.

Returns:

  • (Boolean)

Raises:



398
399
400
401
402
403
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 398

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

#locate(path) ⇒ Zconfig

Find a config item along a path; leading slash is optional and ignored.

Parameters:

  • path (String, #to_s, nil)

Returns:

Raises:



245
246
247
248
249
250
251
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 245

def locate(path)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_locate(self_p, path)
  result = Zconfig.__new result, false
  result
end

#name::FFI::Pointer

Return name of config item

Returns:

  • (::FFI::Pointer)

Raises:



137
138
139
140
141
142
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 137

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

#nextZconfig

Find our first sibling, if any

Returns:

Raises:



233
234
235
236
237
238
239
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 233

def next()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_next(self_p)
  result = Zconfig.__new result, false
  result
end

#null?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 43

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

This method returns an undefined value.

Print properties of object

Raises:



439
440
441
442
443
444
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 439

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

#put(path, value) ⇒ void

This method returns an undefined value.

Insert or update configuration key with value

Parameters:

  • path (String, #to_s, nil)
  • value (String, #to_s, nil)

Raises:



159
160
161
162
163
164
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 159

def put(path, value)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_put(self_p, path, value)
  result
end

#putf(path, format, *args) ⇒ void

This method returns an undefined value.

Equivalent to zconfig_put, accepting a format specifier and variable argument list, instead of a single string value.

Parameters:

Raises:



173
174
175
176
177
178
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 173

def putf(path, format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_putf(self_p, path, format, *args)
  result
end

#remove_subtreevoid

This method returns an undefined value.

Destroy subtree (all children)

Raises:



408
409
410
411
412
413
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 408

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

#save(filename) ⇒ Integer

Save a config tree to a specified ZPL text file, where a filename “-” means dump to standard output.

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



309
310
311
312
313
314
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 309

def save(filename)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_save(self_p, filename)
  result
end

#savef(format, *args) ⇒ Integer

Equivalent to zconfig_save, taking a format string instead of a fixed filename.

Parameters:

Returns:

  • (Integer)

Raises:



322
323
324
325
326
327
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 322

def savef(format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_savef(self_p, format, *args)
  result
end

#set_comment(format, *args) ⇒ void

This method returns an undefined value.

Add comment to config item before saving to disk. You can add as many comment lines as you like. If you use a null format, all comments are deleted.

Parameters:

Raises:



286
287
288
289
290
291
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 286

def set_comment(format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_set_comment(self_p, format, *args)
  result
end

#set_name(name) ⇒ void

This method returns an undefined value.

Set config item name, name may be NULL

Parameters:

  • name (String, #to_s, nil)

Raises:



197
198
199
200
201
202
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 197

def set_name(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_set_name(self_p, name)
  result
end

#set_value(format, *args) ⇒ void

This method returns an undefined value.

Set new value for config item. The new value may be a string, a printf format, or NULL. Note that if string may possibly contain ‘%’, or if it comes from an insecure source, you must use ‘%s’ as the format, followed by the string.

Parameters:

Raises:



212
213
214
215
216
217
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 212

def set_value(format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_set_value(self_p, format, *args)
  result
end

#str_save::FFI::AutoPointer

Save a config tree to a new null terminated string

Returns:

  • (::FFI::AutoPointer)

Raises:



386
387
388
389
390
391
392
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 386

def str_save()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_str_save(self_p)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

#value::FFI::Pointer

Return value of config item

Returns:

  • (::FFI::Pointer)

Raises:



147
148
149
150
151
152
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 147

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