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:



369
370
371
372
373
374
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 369

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
42
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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.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);


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

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)


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

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)


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

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)


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

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)


359
360
361
362
363
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 359

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:



433
434
435
436
437
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 433

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:



391
392
393
394
395
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 391

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)


464
465
466
467
468
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 464

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:



49
50
51
52
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.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/zconfig.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/zconfig.rb', line 72

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:



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

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:



236
237
238
239
240
241
242
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 236

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:



379
380
381
382
383
384
385
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 379

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:



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

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



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

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

#dupZconfig

Create copy of zconfig, caller MUST free the value Create copy of config, as new zconfig object. Returns a fresh zconfig_t object. If config is null, or memory was exhausted, returns null.

Returns:

Raises:



140
141
142
143
144
145
146
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 140

def dup()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zconfig_dup(self_p)
  result = Zconfig.__new result, true
  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:



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

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:



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

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:



443
444
445
446
447
448
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 443

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:



200
201
202
203
204
205
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 200

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:



412
413
414
415
416
417
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 412

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:



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

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:



151
152
153
154
155
156
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 151

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:



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

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)


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

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

This method returns an undefined value.

Print properties of object

Raises:



453
454
455
456
457
458
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 453

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:



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

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:



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

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:



422
423
424
425
426
427
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 422

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:



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

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:



336
337
338
339
340
341
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 336

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:



300
301
302
303
304
305
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 300

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:



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

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:



226
227
228
229
230
231
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 226

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:



400
401
402
403
404
405
406
# File 'lib/czmq-ffi-gen/czmq/ffi/zconfig.rb', line 400

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:



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

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