czmq-ffi-gen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,182 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Please refer to the README for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # List of network interfaces available on system
10
+ # @note This class is 100% generated using zproject.
11
+ class Ziflist
12
+ # Raised when one tries to use an instance of {Ziflist} after
13
+ # the internal pointer to the native object has been nullified.
14
+ class DestroyedError < RuntimeError; end
15
+
16
+ # Boilerplate for self pointer, initializer, and finalizer
17
+ class << self
18
+ alias :__new :new
19
+ end
20
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
21
+ # it if necessary.
22
+ # @param ptr [::FFI::Pointer]
23
+ # @param finalize [Boolean]
24
+ def initialize(ptr, finalize = true)
25
+ @ptr = ptr
26
+ if @ptr.null?
27
+ @ptr = nil # Remove null pointers so we don't have to test for them.
28
+ elsif finalize
29
+ @finalizer = self.class.create_finalizer_for @ptr
30
+ ObjectSpace.define_finalizer self, @finalizer
31
+ end
32
+ end
33
+ # @param ptr [::FFI::Pointer]
34
+ # @return [Proc]
35
+ def self.create_finalizer_for(ptr)
36
+ Proc.new do
37
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
38
+ ptr_ptr.write_pointer ptr
39
+ ::CZMQ::FFI.ziflist_destroy ptr_ptr
40
+ end
41
+ end
42
+ # @return [Boolean]
43
+ def null?
44
+ !@ptr or @ptr.null?
45
+ end
46
+ # Return internal pointer
47
+ # @return [::FFI::Pointer]
48
+ def __ptr
49
+ raise DestroyedError unless @ptr
50
+ @ptr
51
+ end
52
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
53
+ alias_method :to_ptr, :__ptr
54
+ # Nullify internal pointer and return pointer pointer.
55
+ # @note This detaches the current instance from the native object
56
+ # and thus makes it unusable.
57
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
58
+ # pointing to the native object
59
+ def __ptr_give_ref
60
+ raise DestroyedError unless @ptr
61
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
+ ptr_ptr.write_pointer @ptr
63
+ ObjectSpace.undefine_finalizer self if @finalizer
64
+ @finalizer = nil
65
+ @ptr = nil
66
+ ptr_ptr
67
+ end
68
+
69
+ # Get a list of network interfaces currently defined on the system
70
+ # @return [CZMQ::Ziflist]
71
+ def self.new()
72
+ ptr = ::CZMQ::FFI.ziflist_new()
73
+ __new ptr
74
+ end
75
+
76
+ # Destroy a ziflist instance
77
+ #
78
+ # @return [void]
79
+ def destroy()
80
+ return unless @ptr
81
+ self_p = __ptr_give_ref
82
+ result = ::CZMQ::FFI.ziflist_destroy(self_p)
83
+ result
84
+ end
85
+
86
+ # Reload network interfaces from system
87
+ #
88
+ # @return [void]
89
+ def reload()
90
+ raise DestroyedError unless @ptr
91
+ self_p = @ptr
92
+ result = ::CZMQ::FFI.ziflist_reload(self_p)
93
+ result
94
+ end
95
+
96
+ # Return the number of network interfaces on system
97
+ #
98
+ # @return [Integer]
99
+ def size()
100
+ raise DestroyedError unless @ptr
101
+ self_p = @ptr
102
+ result = ::CZMQ::FFI.ziflist_size(self_p)
103
+ result
104
+ end
105
+
106
+ # Get first network interface, return NULL if there are none
107
+ #
108
+ # @return [String]
109
+ def first()
110
+ raise DestroyedError unless @ptr
111
+ self_p = @ptr
112
+ result = ::CZMQ::FFI.ziflist_first(self_p)
113
+ result
114
+ end
115
+
116
+ # Get next network interface, return NULL if we hit the last one
117
+ #
118
+ # @return [String]
119
+ def next()
120
+ raise DestroyedError unless @ptr
121
+ self_p = @ptr
122
+ result = ::CZMQ::FFI.ziflist_next(self_p)
123
+ result
124
+ end
125
+
126
+ # Return the current interface IP address as a printable string
127
+ #
128
+ # @return [String]
129
+ def address()
130
+ raise DestroyedError unless @ptr
131
+ self_p = @ptr
132
+ result = ::CZMQ::FFI.ziflist_address(self_p)
133
+ result
134
+ end
135
+
136
+ # Return the current interface broadcast address as a printable string
137
+ #
138
+ # @return [String]
139
+ def broadcast()
140
+ raise DestroyedError unless @ptr
141
+ self_p = @ptr
142
+ result = ::CZMQ::FFI.ziflist_broadcast(self_p)
143
+ result
144
+ end
145
+
146
+ # Return the current interface network mask as a printable string
147
+ #
148
+ # @return [String]
149
+ def netmask()
150
+ raise DestroyedError unless @ptr
151
+ self_p = @ptr
152
+ result = ::CZMQ::FFI.ziflist_netmask(self_p)
153
+ result
154
+ end
155
+
156
+ # Return the list of interfaces.
157
+ #
158
+ # @return [void]
159
+ def print()
160
+ raise DestroyedError unless @ptr
161
+ self_p = @ptr
162
+ result = ::CZMQ::FFI.ziflist_print(self_p)
163
+ result
164
+ end
165
+
166
+ # Self test of this class.
167
+ #
168
+ # @param verbose [Boolean]
169
+ # @return [void]
170
+ def self.test(verbose)
171
+ verbose = !(0==verbose||!verbose) # boolean
172
+ result = ::CZMQ::FFI.ziflist_test(verbose)
173
+ result
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ ################################################################################
180
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
181
+ # Please refer to the README for information about making permanent changes. #
182
+ ################################################################################
@@ -0,0 +1,355 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Please refer to the README for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # simple generic list container
10
+ # @note This class is 100% generated using zproject.
11
+ class Zlist
12
+ # Raised when one tries to use an instance of {Zlist} after
13
+ # the internal pointer to the native object has been nullified.
14
+ class DestroyedError < RuntimeError; end
15
+
16
+ # Boilerplate for self pointer, initializer, and finalizer
17
+ class << self
18
+ alias :__new :new
19
+ end
20
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
21
+ # it if necessary.
22
+ # @param ptr [::FFI::Pointer]
23
+ # @param finalize [Boolean]
24
+ def initialize(ptr, finalize = true)
25
+ @ptr = ptr
26
+ if @ptr.null?
27
+ @ptr = nil # Remove null pointers so we don't have to test for them.
28
+ elsif finalize
29
+ @finalizer = self.class.create_finalizer_for @ptr
30
+ ObjectSpace.define_finalizer self, @finalizer
31
+ end
32
+ end
33
+ # @param ptr [::FFI::Pointer]
34
+ # @return [Proc]
35
+ def self.create_finalizer_for(ptr)
36
+ Proc.new do
37
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
38
+ ptr_ptr.write_pointer ptr
39
+ ::CZMQ::FFI.zlist_destroy ptr_ptr
40
+ end
41
+ end
42
+ # @return [Boolean]
43
+ def null?
44
+ !@ptr or @ptr.null?
45
+ end
46
+ # Return internal pointer
47
+ # @return [::FFI::Pointer]
48
+ def __ptr
49
+ raise DestroyedError unless @ptr
50
+ @ptr
51
+ end
52
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
53
+ alias_method :to_ptr, :__ptr
54
+ # Nullify internal pointer and return pointer pointer.
55
+ # @note This detaches the current instance from the native object
56
+ # and thus makes it unusable.
57
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
58
+ # pointing to the native object
59
+ def __ptr_give_ref
60
+ raise DestroyedError unless @ptr
61
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
+ ptr_ptr.write_pointer @ptr
63
+ ObjectSpace.undefine_finalizer self if @finalizer
64
+ @finalizer = nil
65
+ @ptr = nil
66
+ ptr_ptr
67
+ end
68
+
69
+ # Create a new callback of the following type:
70
+ # Comparison function e.g. for sorting and removing.
71
+ # typedef int (zlist_compare_fn) (
72
+ # void *item1, void *item2);
73
+ #
74
+ # @note WARNING: If your Ruby code doesn't retain a reference to the
75
+ # FFI::Function object after passing it to a C function call,
76
+ # it may be garbage collected while C still holds the pointer,
77
+ # potentially resulting in a segmentation fault.
78
+ def self.compare_fn
79
+ ::FFI::Function.new :int, [:pointer, :pointer], blocking: true do |item1, item2|
80
+ result = yield item1, item2
81
+ result = Integer(result)
82
+ result
83
+ end
84
+ end
85
+
86
+ # Create a new callback of the following type:
87
+ # Callback function for zlist_freefn method
88
+ # typedef void (zlist_free_fn) (
89
+ # void *data);
90
+ #
91
+ # @note WARNING: If your Ruby code doesn't retain a reference to the
92
+ # FFI::Function object after passing it to a C function call,
93
+ # it may be garbage collected while C still holds the pointer,
94
+ # potentially resulting in a segmentation fault.
95
+ def self.free_fn
96
+ ::FFI::Function.new :void, [:pointer], blocking: true do |data|
97
+ result = yield data
98
+ result
99
+ end
100
+ end
101
+
102
+ # Create a new list container
103
+ # @return [CZMQ::Zlist]
104
+ def self.new()
105
+ ptr = ::CZMQ::FFI.zlist_new()
106
+ __new ptr
107
+ end
108
+
109
+ # Destroy a list container
110
+ #
111
+ # @return [void]
112
+ def destroy()
113
+ return unless @ptr
114
+ self_p = __ptr_give_ref
115
+ result = ::CZMQ::FFI.zlist_destroy(self_p)
116
+ result
117
+ end
118
+
119
+ # Return the item at the head of list. If the list is empty, returns NULL.
120
+ # Leaves cursor pointing at the head item, or NULL if the list is empty.
121
+ #
122
+ # @return [::FFI::Pointer]
123
+ def first()
124
+ raise DestroyedError unless @ptr
125
+ self_p = @ptr
126
+ result = ::CZMQ::FFI.zlist_first(self_p)
127
+ result
128
+ end
129
+
130
+ # Return the next item. If the list is empty, returns NULL. To move to
131
+ # the start of the list call zlist_first (). Advances the cursor.
132
+ #
133
+ # @return [::FFI::Pointer]
134
+ def next()
135
+ raise DestroyedError unless @ptr
136
+ self_p = @ptr
137
+ result = ::CZMQ::FFI.zlist_next(self_p)
138
+ result
139
+ end
140
+
141
+ # Return the item at the tail of list. If the list is empty, returns NULL.
142
+ # Leaves cursor pointing at the tail item, or NULL if the list is empty.
143
+ #
144
+ # @return [::FFI::Pointer]
145
+ def last()
146
+ raise DestroyedError unless @ptr
147
+ self_p = @ptr
148
+ result = ::CZMQ::FFI.zlist_last(self_p)
149
+ result
150
+ end
151
+
152
+ # Return first item in the list, or null, leaves the cursor
153
+ #
154
+ # @return [::FFI::Pointer]
155
+ def head()
156
+ raise DestroyedError unless @ptr
157
+ self_p = @ptr
158
+ result = ::CZMQ::FFI.zlist_head(self_p)
159
+ result
160
+ end
161
+
162
+ # Return last item in the list, or null, leaves the cursor
163
+ #
164
+ # @return [::FFI::Pointer]
165
+ def tail()
166
+ raise DestroyedError unless @ptr
167
+ self_p = @ptr
168
+ result = ::CZMQ::FFI.zlist_tail(self_p)
169
+ result
170
+ end
171
+
172
+ # Return the current item of list. If the list is empty, returns NULL.
173
+ # Leaves cursor pointing at the current item, or NULL if the list is empty.
174
+ #
175
+ # @return [::FFI::Pointer]
176
+ def item()
177
+ raise DestroyedError unless @ptr
178
+ self_p = @ptr
179
+ result = ::CZMQ::FFI.zlist_item(self_p)
180
+ result
181
+ end
182
+
183
+ # Append an item to the end of the list, return 0 if OK or -1 if this
184
+ # failed for some reason (out of memory). Note that if a duplicator has
185
+ # been set, this method will also duplicate the item.
186
+ #
187
+ # @param item [::FFI::Pointer, #to_ptr]
188
+ # @return [Integer]
189
+ def append(item)
190
+ raise DestroyedError unless @ptr
191
+ self_p = @ptr
192
+ result = ::CZMQ::FFI.zlist_append(self_p, item)
193
+ result
194
+ end
195
+
196
+ # Push an item to the start of the list, return 0 if OK or -1 if this
197
+ # failed for some reason (out of memory). Note that if a duplicator has
198
+ # been set, this method will also duplicate the item.
199
+ #
200
+ # @param item [::FFI::Pointer, #to_ptr]
201
+ # @return [Integer]
202
+ def push(item)
203
+ raise DestroyedError unless @ptr
204
+ self_p = @ptr
205
+ result = ::CZMQ::FFI.zlist_push(self_p, item)
206
+ result
207
+ end
208
+
209
+ # Pop the item off the start of the list, if any
210
+ #
211
+ # @return [::FFI::Pointer]
212
+ def pop()
213
+ raise DestroyedError unless @ptr
214
+ self_p = @ptr
215
+ result = ::CZMQ::FFI.zlist_pop(self_p)
216
+ result
217
+ end
218
+
219
+ # Checks if an item already is present. Uses compare method to determine if
220
+ # items are equal. If the compare method is NULL the check will only compare
221
+ # pointers. Returns true if item is present else false.
222
+ #
223
+ # @param item [::FFI::Pointer, #to_ptr]
224
+ # @return [Boolean]
225
+ def exists(item)
226
+ raise DestroyedError unless @ptr
227
+ self_p = @ptr
228
+ result = ::CZMQ::FFI.zlist_exists(self_p, item)
229
+ result
230
+ end
231
+
232
+ # Remove the specified item from the list if present
233
+ #
234
+ # @param item [::FFI::Pointer, #to_ptr]
235
+ # @return [void]
236
+ def remove(item)
237
+ raise DestroyedError unless @ptr
238
+ self_p = @ptr
239
+ result = ::CZMQ::FFI.zlist_remove(self_p, item)
240
+ result
241
+ end
242
+
243
+ # Make a copy of list. If the list has autofree set, the copied list will
244
+ # duplicate all items, which must be strings. Otherwise, the list will hold
245
+ # pointers back to the items in the original list. If list is null, returns
246
+ # NULL.
247
+ #
248
+ # @return [Zlist]
249
+ def dup()
250
+ raise DestroyedError unless @ptr
251
+ self_p = @ptr
252
+ result = ::CZMQ::FFI.zlist_dup(self_p)
253
+ result = Zlist.__new result, true
254
+ result
255
+ end
256
+
257
+ # Purge all items from list
258
+ #
259
+ # @return [void]
260
+ def purge()
261
+ raise DestroyedError unless @ptr
262
+ self_p = @ptr
263
+ result = ::CZMQ::FFI.zlist_purge(self_p)
264
+ result
265
+ end
266
+
267
+ # Return number of items in the list
268
+ #
269
+ # @return [Integer]
270
+ def size()
271
+ raise DestroyedError unless @ptr
272
+ self_p = @ptr
273
+ result = ::CZMQ::FFI.zlist_size(self_p)
274
+ result
275
+ end
276
+
277
+ # Sort the list by ascending key value using a straight ASCII comparison.
278
+ # The sort is not stable, so may reorder items with the same keys.
279
+ #
280
+ # @param compare [::FFI::Pointer, #to_ptr]
281
+ # @return [void]
282
+ def sort(compare)
283
+ raise DestroyedError unless @ptr
284
+ self_p = @ptr
285
+ result = ::CZMQ::FFI.zlist_sort(self_p, compare)
286
+ result
287
+ end
288
+
289
+ # Set list for automatic item destruction; item values MUST be strings.
290
+ # By default a list item refers to a value held elsewhere. When you set
291
+ # this, each time you append or push a list item, zlist will take a copy
292
+ # of the string value. Then, when you destroy the list, it will free all
293
+ # item values automatically. If you use any other technique to allocate
294
+ # list values, you must free them explicitly before destroying the list.
295
+ # The usual technique is to pop list items and destroy them, until the
296
+ # list is empty.
297
+ #
298
+ # @return [void]
299
+ def autofree()
300
+ raise DestroyedError unless @ptr
301
+ self_p = @ptr
302
+ result = ::CZMQ::FFI.zlist_autofree(self_p)
303
+ result
304
+ end
305
+
306
+ # Sets a compare function for this list. The function compares two items.
307
+ # It returns an integer less than, equal to, or greater than zero if the
308
+ # first item is found, respectively, to be less than, to match, or be
309
+ # greater than the second item.
310
+ # This function is used for sorting, removal and exists checking.
311
+ #
312
+ # @param fn [::FFI::Pointer, #to_ptr]
313
+ # @return [void]
314
+ def comparefn(fn)
315
+ raise DestroyedError unless @ptr
316
+ self_p = @ptr
317
+ result = ::CZMQ::FFI.zlist_comparefn(self_p, fn)
318
+ result
319
+ end
320
+
321
+ # Set a free function for the specified list item. When the item is
322
+ # destroyed, the free function, if any, is called on that item.
323
+ # Use this when list items are dynamically allocated, to ensure that
324
+ # you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
325
+ # Returns the item, or NULL if there is no such item.
326
+ #
327
+ # @param item [::FFI::Pointer, #to_ptr]
328
+ # @param fn [::FFI::Pointer, #to_ptr]
329
+ # @param at_tail [Boolean]
330
+ # @return [::FFI::Pointer]
331
+ def freefn(item, fn, at_tail)
332
+ raise DestroyedError unless @ptr
333
+ self_p = @ptr
334
+ at_tail = !(0==at_tail||!at_tail) # boolean
335
+ result = ::CZMQ::FFI.zlist_freefn(self_p, item, fn, at_tail)
336
+ result
337
+ end
338
+
339
+ # Self test of this class.
340
+ #
341
+ # @param verbose [Boolean]
342
+ # @return [void]
343
+ def self.test(verbose)
344
+ verbose = !(0==verbose||!verbose) # boolean
345
+ result = ::CZMQ::FFI.zlist_test(verbose)
346
+ result
347
+ end
348
+ end
349
+ end
350
+ end
351
+
352
+ ################################################################################
353
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
354
+ # Please refer to the README for information about making permanent changes. #
355
+ ################################################################################