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
+ # work with directory patches
10
+ # @note This class is 100% generated using zproject.
11
+ class ZdirPatch
12
+ # Raised when one tries to use an instance of {ZdirPatch} 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.zdir_patch_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 new patch
70
+ # @param path [String, #to_str, #to_s]
71
+ # @param file [Zfile, #__ptr]
72
+ # @param op [Symbol]
73
+ # @param alias_ [String, #to_str, #to_s]
74
+ # @return [CZMQ::ZdirPatch]
75
+ def self.new(path, file, op, alias_)
76
+ path = String(path)
77
+ file = file.__ptr if file
78
+ alias_ = String(alias_)
79
+ ptr = ::CZMQ::FFI.zdir_patch_new(path, file, op, alias_)
80
+ __new ptr
81
+ end
82
+
83
+ # Destroy a patch
84
+ #
85
+ # @return [void]
86
+ def destroy()
87
+ return unless @ptr
88
+ self_p = __ptr_give_ref
89
+ result = ::CZMQ::FFI.zdir_patch_destroy(self_p)
90
+ result
91
+ end
92
+
93
+ # Create copy of a patch. If the patch is null, or memory was exhausted,
94
+ # returns null.
95
+ #
96
+ # @return [ZdirPatch]
97
+ def dup()
98
+ raise DestroyedError unless @ptr
99
+ self_p = @ptr
100
+ result = ::CZMQ::FFI.zdir_patch_dup(self_p)
101
+ result = ZdirPatch.__new result, true
102
+ result
103
+ end
104
+
105
+ # Return patch file directory path
106
+ #
107
+ # @return [String]
108
+ def path()
109
+ raise DestroyedError unless @ptr
110
+ self_p = @ptr
111
+ result = ::CZMQ::FFI.zdir_patch_path(self_p)
112
+ result
113
+ end
114
+
115
+ # Return patch file item
116
+ #
117
+ # @return [Zfile]
118
+ def file()
119
+ raise DestroyedError unless @ptr
120
+ self_p = @ptr
121
+ result = ::CZMQ::FFI.zdir_patch_file(self_p)
122
+ result = Zfile.__new result, false
123
+ result
124
+ end
125
+
126
+ # Return operation
127
+ #
128
+ # @return [Symbol]
129
+ def op()
130
+ raise DestroyedError unless @ptr
131
+ self_p = @ptr
132
+ result = ::CZMQ::FFI.zdir_patch_op(self_p)
133
+ result
134
+ end
135
+
136
+ # Return patch virtual file path
137
+ #
138
+ # @return [String]
139
+ def vpath()
140
+ raise DestroyedError unless @ptr
141
+ self_p = @ptr
142
+ result = ::CZMQ::FFI.zdir_patch_vpath(self_p)
143
+ result
144
+ end
145
+
146
+ # Calculate hash digest for file (create only)
147
+ #
148
+ # @return [void]
149
+ def digest_set()
150
+ raise DestroyedError unless @ptr
151
+ self_p = @ptr
152
+ result = ::CZMQ::FFI.zdir_patch_digest_set(self_p)
153
+ result
154
+ end
155
+
156
+ # Return hash digest for patch file
157
+ #
158
+ # @return [String]
159
+ def digest()
160
+ raise DestroyedError unless @ptr
161
+ self_p = @ptr
162
+ result = ::CZMQ::FFI.zdir_patch_digest(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.zdir_patch_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,347 @@
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
+ # helper functions for working with files.
10
+ # @note This class is 100% generated using zproject.
11
+ class Zfile
12
+ # Raised when one tries to use an instance of {Zfile} 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.zfile_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
+ # If file exists, populates properties. CZMQ supports portable symbolic
70
+ # links, which are files with the extension ".ln". A symbolic link is a
71
+ # text file containing one line, the filename of a target file. Reading
72
+ # data from the symbolic link actually reads from the target file. Path
73
+ # may be NULL, in which case it is not used.
74
+ # @param path [String, #to_str, #to_s]
75
+ # @param name [String, #to_str, #to_s]
76
+ # @return [CZMQ::Zfile]
77
+ def self.new(path, name)
78
+ path = String(path)
79
+ name = String(name)
80
+ ptr = ::CZMQ::FFI.zfile_new(path, name)
81
+ __new ptr
82
+ end
83
+
84
+ # Destroy a file item
85
+ #
86
+ # @return [void]
87
+ def destroy()
88
+ return unless @ptr
89
+ self_p = __ptr_give_ref
90
+ result = ::CZMQ::FFI.zfile_destroy(self_p)
91
+ result
92
+ end
93
+
94
+ # Duplicate a file item, returns a newly constructed item. If the file
95
+ # is null, or memory was exhausted, returns null.
96
+ #
97
+ # @return [Zfile]
98
+ def dup()
99
+ raise DestroyedError unless @ptr
100
+ self_p = @ptr
101
+ result = ::CZMQ::FFI.zfile_dup(self_p)
102
+ result = Zfile.__new result, true
103
+ result
104
+ end
105
+
106
+ # Return file name, remove path if provided
107
+ #
108
+ # @param path [String, #to_str, #to_s]
109
+ # @return [String]
110
+ def filename(path)
111
+ raise DestroyedError unless @ptr
112
+ self_p = @ptr
113
+ path = String(path)
114
+ result = ::CZMQ::FFI.zfile_filename(self_p, path)
115
+ result
116
+ end
117
+
118
+ # Refresh file properties from disk; this is not done automatically
119
+ # on access methods, otherwise it is not possible to compare directory
120
+ # snapshots.
121
+ #
122
+ # @return [void]
123
+ def restat()
124
+ raise DestroyedError unless @ptr
125
+ self_p = @ptr
126
+ result = ::CZMQ::FFI.zfile_restat(self_p)
127
+ result
128
+ end
129
+
130
+ # Return when the file was last modified. If you want this to reflect the
131
+ # current situation, call zfile_restat before checking this property.
132
+ #
133
+ # @return [::FFI::Pointer]
134
+ def modified()
135
+ raise DestroyedError unless @ptr
136
+ self_p = @ptr
137
+ result = ::CZMQ::FFI.zfile_modified(self_p)
138
+ result
139
+ end
140
+
141
+ # Return the last-known size of the file. If you want this to reflect the
142
+ # current situation, call zfile_restat before checking this property.
143
+ #
144
+ # @return [::FFI::Pointer]
145
+ def cursize()
146
+ raise DestroyedError unless @ptr
147
+ self_p = @ptr
148
+ result = ::CZMQ::FFI.zfile_cursize(self_p)
149
+ result
150
+ end
151
+
152
+ # Return true if the file is a directory. If you want this to reflect
153
+ # any external changes, call zfile_restat before checking this property.
154
+ #
155
+ # @return [Boolean]
156
+ def is_directory()
157
+ raise DestroyedError unless @ptr
158
+ self_p = @ptr
159
+ result = ::CZMQ::FFI.zfile_is_directory(self_p)
160
+ result
161
+ end
162
+
163
+ # Return true if the file is a regular file. If you want this to reflect
164
+ # any external changes, call zfile_restat before checking this property.
165
+ #
166
+ # @return [Boolean]
167
+ def is_regular()
168
+ raise DestroyedError unless @ptr
169
+ self_p = @ptr
170
+ result = ::CZMQ::FFI.zfile_is_regular(self_p)
171
+ result
172
+ end
173
+
174
+ # Return true if the file is readable by this process. If you want this to
175
+ # reflect any external changes, call zfile_restat before checking this
176
+ # property.
177
+ #
178
+ # @return [Boolean]
179
+ def is_readable()
180
+ raise DestroyedError unless @ptr
181
+ self_p = @ptr
182
+ result = ::CZMQ::FFI.zfile_is_readable(self_p)
183
+ result
184
+ end
185
+
186
+ # Return true if the file is writeable by this process. If you want this
187
+ # to reflect any external changes, call zfile_restat before checking this
188
+ # property.
189
+ #
190
+ # @return [Boolean]
191
+ def is_writeable()
192
+ raise DestroyedError unless @ptr
193
+ self_p = @ptr
194
+ result = ::CZMQ::FFI.zfile_is_writeable(self_p)
195
+ result
196
+ end
197
+
198
+ # Check if file has stopped changing and can be safely processed.
199
+ # Updates the file statistics from disk at every call.
200
+ #
201
+ # @return [Boolean]
202
+ def is_stable()
203
+ raise DestroyedError unless @ptr
204
+ self_p = @ptr
205
+ result = ::CZMQ::FFI.zfile_is_stable(self_p)
206
+ result
207
+ end
208
+
209
+ # Return true if the file was changed on disk since the zfile_t object
210
+ # was created, or the last zfile_restat() call made on it.
211
+ #
212
+ # @return [Boolean]
213
+ def has_changed()
214
+ raise DestroyedError unless @ptr
215
+ self_p = @ptr
216
+ result = ::CZMQ::FFI.zfile_has_changed(self_p)
217
+ result
218
+ end
219
+
220
+ # Remove the file from disk
221
+ #
222
+ # @return [void]
223
+ def remove()
224
+ raise DestroyedError unless @ptr
225
+ self_p = @ptr
226
+ result = ::CZMQ::FFI.zfile_remove(self_p)
227
+ result
228
+ end
229
+
230
+ # Open file for reading
231
+ # Returns 0 if OK, -1 if not found or not accessible
232
+ #
233
+ # @return [Integer]
234
+ def input()
235
+ raise DestroyedError unless @ptr
236
+ self_p = @ptr
237
+ result = ::CZMQ::FFI.zfile_input(self_p)
238
+ result
239
+ end
240
+
241
+ # Open file for writing, creating directory if needed
242
+ # File is created if necessary; chunks can be written to file at any
243
+ # location. Returns 0 if OK, -1 if error.
244
+ #
245
+ # @return [Integer]
246
+ def output()
247
+ raise DestroyedError unless @ptr
248
+ self_p = @ptr
249
+ result = ::CZMQ::FFI.zfile_output(self_p)
250
+ result
251
+ end
252
+
253
+ # Read chunk from file at specified position. If this was the last chunk,
254
+ # sets the eof property. Returns a null chunk in case of error.
255
+ #
256
+ # @param bytes [Integer, #to_int, #to_i]
257
+ # @param offset [::FFI::Pointer, #to_ptr]
258
+ # @return [::FFI::Pointer]
259
+ def read(bytes, offset)
260
+ raise DestroyedError unless @ptr
261
+ self_p = @ptr
262
+ bytes = Integer(bytes)
263
+ result = ::CZMQ::FFI.zfile_read(self_p, bytes, offset)
264
+ result
265
+ end
266
+
267
+ # Returns true if zfile_read() just read the last chunk in the file.
268
+ #
269
+ # @return [Boolean]
270
+ def eof()
271
+ raise DestroyedError unless @ptr
272
+ self_p = @ptr
273
+ result = ::CZMQ::FFI.zfile_eof(self_p)
274
+ result
275
+ end
276
+
277
+ # Write chunk to file at specified position
278
+ # Return 0 if OK, else -1
279
+ #
280
+ # @param chunk [::FFI::Pointer, #to_ptr]
281
+ # @param offset [::FFI::Pointer, #to_ptr]
282
+ # @return [Integer]
283
+ def write(chunk, offset)
284
+ raise DestroyedError unless @ptr
285
+ self_p = @ptr
286
+ result = ::CZMQ::FFI.zfile_write(self_p, chunk, offset)
287
+ result
288
+ end
289
+
290
+ # Read next line of text from file. Returns a pointer to the text line,
291
+ # or NULL if there was nothing more to read from the file.
292
+ #
293
+ # @return [String]
294
+ def readln()
295
+ raise DestroyedError unless @ptr
296
+ self_p = @ptr
297
+ result = ::CZMQ::FFI.zfile_readln(self_p)
298
+ result
299
+ end
300
+
301
+ # Close file, if open
302
+ #
303
+ # @return [void]
304
+ def close()
305
+ raise DestroyedError unless @ptr
306
+ self_p = @ptr
307
+ result = ::CZMQ::FFI.zfile_close(self_p)
308
+ result
309
+ end
310
+
311
+ # Return file handle, if opened
312
+ #
313
+ # @return [::FFI::Pointer]
314
+ def handle()
315
+ raise DestroyedError unless @ptr
316
+ self_p = @ptr
317
+ result = ::CZMQ::FFI.zfile_handle(self_p)
318
+ result
319
+ end
320
+
321
+ # Calculate SHA1 digest for file, using zdigest class.
322
+ #
323
+ # @return [String]
324
+ def digest()
325
+ raise DestroyedError unless @ptr
326
+ self_p = @ptr
327
+ result = ::CZMQ::FFI.zfile_digest(self_p)
328
+ result
329
+ end
330
+
331
+ # Self test of this class.
332
+ #
333
+ # @param verbose [Boolean]
334
+ # @return [void]
335
+ def self.test(verbose)
336
+ verbose = !(0==verbose||!verbose) # boolean
337
+ result = ::CZMQ::FFI.zfile_test(verbose)
338
+ result
339
+ end
340
+ end
341
+ end
342
+ end
343
+
344
+ ################################################################################
345
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
346
+ # Please refer to the README for information about making permanent changes. #
347
+ ################################################################################