czmq-ffi-gen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
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
+ VERSION = '3.0.3'
9
+ end
10
+ end
11
+
12
+ ################################################################################
13
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
14
+ # Please refer to the README for information about making permanent changes. #
15
+ ################################################################################
@@ -0,0 +1,179 @@
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
+ # The zactor class provides a simple actor framework.
10
+ # @note This class is 100% generated using zproject.
11
+ class Zactor
12
+ # Raised when one tries to use an instance of {Zactor} 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.zactor_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
+ # Actors get a pipe and arguments from caller
71
+ # typedef void (zactor_fn) (
72
+ # zsock_t *pipe, void *args);
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.fn
79
+ ::FFI::Function.new :void, [:pointer, :pointer], blocking: true do |pipe, args|
80
+ pipe = Zsock.__new pipe, false
81
+ result = yield pipe, args
82
+ result
83
+ end
84
+ end
85
+
86
+ # Create a new actor passing arbitrary arguments reference.
87
+ # @param task [::FFI::Pointer, #to_ptr]
88
+ # @param args [::FFI::Pointer, #to_ptr]
89
+ # @return [CZMQ::Zactor]
90
+ def self.new(task, args)
91
+ ptr = ::CZMQ::FFI.zactor_new(task, args)
92
+ __new ptr
93
+ end
94
+
95
+ # Destroy an actor.
96
+ #
97
+ # @return [void]
98
+ def destroy()
99
+ return unless @ptr
100
+ self_p = __ptr_give_ref
101
+ result = ::CZMQ::FFI.zactor_destroy(self_p)
102
+ result
103
+ end
104
+
105
+ # Send a zmsg message to the actor, take ownership of the message
106
+ # and destroy when it has been sent.
107
+ #
108
+ # @param msg_p [#__ptr_give_ref]
109
+ # @return [Integer]
110
+ def send(msg_p)
111
+ raise DestroyedError unless @ptr
112
+ self_p = @ptr
113
+ msg_p = msg_p.__ptr_give_ref
114
+ result = ::CZMQ::FFI.zactor_send(self_p, msg_p)
115
+ result
116
+ end
117
+
118
+ # Receive a zmsg message from the actor. Returns NULL if the actor
119
+ # was interrupted before the message could be received, or if there
120
+ # was a timeout on the actor.
121
+ #
122
+ # @return [Zmsg]
123
+ def recv()
124
+ raise DestroyedError unless @ptr
125
+ self_p = @ptr
126
+ result = ::CZMQ::FFI.zactor_recv(self_p)
127
+ result = Zmsg.__new result, true
128
+ result
129
+ end
130
+
131
+ # Probe the supplied object, and report if it looks like a zactor_t.
132
+ #
133
+ # @param self_ [::FFI::Pointer, #to_ptr]
134
+ # @return [Boolean]
135
+ def self.is(self_)
136
+ result = ::CZMQ::FFI.zactor_is(self_)
137
+ result
138
+ end
139
+
140
+ # Probe the supplied reference. If it looks like a zactor_t instance,
141
+ # return the underlying libzmq actor handle; else if it looks like
142
+ # a libzmq actor handle, return the supplied value.
143
+ #
144
+ # @param self_ [::FFI::Pointer, #to_ptr]
145
+ # @return [::FFI::Pointer]
146
+ def self.resolve(self_)
147
+ result = ::CZMQ::FFI.zactor_resolve(self_)
148
+ result
149
+ end
150
+
151
+ # Return the actor's zsock handle. Use this when you absolutely need
152
+ # to work with the zsock instance rather than the actor.
153
+ #
154
+ # @return [Zsock]
155
+ def sock()
156
+ raise DestroyedError unless @ptr
157
+ self_p = @ptr
158
+ result = ::CZMQ::FFI.zactor_sock(self_p)
159
+ result = Zsock.__new result, false
160
+ result
161
+ end
162
+
163
+ # Self test of this class.
164
+ #
165
+ # @param verbose [Boolean]
166
+ # @return [void]
167
+ def self.test(verbose)
168
+ verbose = !(0==verbose||!verbose) # boolean
169
+ result = ::CZMQ::FFI.zactor_test(verbose)
170
+ result
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ ################################################################################
177
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
178
+ # Please refer to the README for information about making permanent changes. #
179
+ ################################################################################
@@ -0,0 +1,259 @@
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
+ # zarmour - armoured text encoding and decoding
10
+ # @note This class is 100% generated using zproject.
11
+ class Zarmour
12
+ # Raised when one tries to use an instance of {Zarmour} 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.zarmour_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 zarmour.
70
+ # @return [CZMQ::Zarmour]
71
+ def self.new()
72
+ ptr = ::CZMQ::FFI.zarmour_new()
73
+ __new ptr
74
+ end
75
+
76
+ # Destroy the zarmour.
77
+ #
78
+ # @return [void]
79
+ def destroy()
80
+ return unless @ptr
81
+ self_p = __ptr_give_ref
82
+ result = ::CZMQ::FFI.zarmour_destroy(self_p)
83
+ result
84
+ end
85
+
86
+ # Get printable string for mode.
87
+ #
88
+ # @return [String]
89
+ def mode_str()
90
+ raise DestroyedError unless @ptr
91
+ self_p = @ptr
92
+ result = ::CZMQ::FFI.zarmour_mode_str(self_p)
93
+ result
94
+ end
95
+
96
+ # Encode a stream of bytes into an armoured string.
97
+ #
98
+ # @param data [::FFI::Pointer, #to_ptr]
99
+ # @param size [Integer, #to_int, #to_i]
100
+ # @return [::FFI::AutoPointer]
101
+ def encode(data, size)
102
+ raise DestroyedError unless @ptr
103
+ self_p = @ptr
104
+ size = Integer(size)
105
+ result = ::CZMQ::FFI.zarmour_encode(self_p, data, size)
106
+ result = ::FFI::AutoPointer.new(result, LibC.method(:free))
107
+ result
108
+ end
109
+
110
+ # Decode an armoured string into a string of bytes.
111
+ # The decoded output is null-terminated, so it may be treated
112
+ # as a string, if that's what it was prior to encoding.
113
+ #
114
+ # @param data [String, #to_str, #to_s]
115
+ # @param decode_size [::FFI::Pointer, #to_ptr]
116
+ # @return [::FFI::Pointer]
117
+ def decode(data, decode_size)
118
+ raise DestroyedError unless @ptr
119
+ self_p = @ptr
120
+ data = String(data)
121
+ result = ::CZMQ::FFI.zarmour_decode(self_p, data, decode_size)
122
+ result
123
+ end
124
+
125
+ # Get the mode property.
126
+ #
127
+ # @return [Symbol]
128
+ def mode()
129
+ raise DestroyedError unless @ptr
130
+ self_p = @ptr
131
+ result = ::CZMQ::FFI.zarmour_mode(self_p)
132
+ result
133
+ end
134
+
135
+ # Set the mode property.
136
+ #
137
+ # @param mode [Symbol]
138
+ # @return [void]
139
+ def set_mode(mode)
140
+ raise DestroyedError unless @ptr
141
+ self_p = @ptr
142
+ result = ::CZMQ::FFI.zarmour_set_mode(self_p, mode)
143
+ result
144
+ end
145
+
146
+ # Return true if padding is turned on.
147
+ #
148
+ # @return [Boolean]
149
+ def pad()
150
+ raise DestroyedError unless @ptr
151
+ self_p = @ptr
152
+ result = ::CZMQ::FFI.zarmour_pad(self_p)
153
+ result
154
+ end
155
+
156
+ # Turn padding on or off. Default is on.
157
+ #
158
+ # @param pad [Boolean]
159
+ # @return [void]
160
+ def set_pad(pad)
161
+ raise DestroyedError unless @ptr
162
+ self_p = @ptr
163
+ pad = !(0==pad||!pad) # boolean
164
+ result = ::CZMQ::FFI.zarmour_set_pad(self_p, pad)
165
+ result
166
+ end
167
+
168
+ # Get the padding character.
169
+ #
170
+ # @return [::FFI::Pointer]
171
+ def pad_char()
172
+ raise DestroyedError unless @ptr
173
+ self_p = @ptr
174
+ result = ::CZMQ::FFI.zarmour_pad_char(self_p)
175
+ result
176
+ end
177
+
178
+ # Set the padding character.
179
+ #
180
+ # @param pad_char [::FFI::Pointer, #to_ptr]
181
+ # @return [void]
182
+ def set_pad_char(pad_char)
183
+ raise DestroyedError unless @ptr
184
+ self_p = @ptr
185
+ result = ::CZMQ::FFI.zarmour_set_pad_char(self_p, pad_char)
186
+ result
187
+ end
188
+
189
+ # Return if splitting output into lines is turned on. Default is off.
190
+ #
191
+ # @return [Boolean]
192
+ def line_breaks()
193
+ raise DestroyedError unless @ptr
194
+ self_p = @ptr
195
+ result = ::CZMQ::FFI.zarmour_line_breaks(self_p)
196
+ result
197
+ end
198
+
199
+ # Turn splitting output into lines on or off.
200
+ #
201
+ # @param line_breaks [Boolean]
202
+ # @return [void]
203
+ def set_line_breaks(line_breaks)
204
+ raise DestroyedError unless @ptr
205
+ self_p = @ptr
206
+ line_breaks = !(0==line_breaks||!line_breaks) # boolean
207
+ result = ::CZMQ::FFI.zarmour_set_line_breaks(self_p, line_breaks)
208
+ result
209
+ end
210
+
211
+ # Get the line length used for splitting lines.
212
+ #
213
+ # @return [Integer]
214
+ def line_length()
215
+ raise DestroyedError unless @ptr
216
+ self_p = @ptr
217
+ result = ::CZMQ::FFI.zarmour_line_length(self_p)
218
+ result
219
+ end
220
+
221
+ # Set the line length used for splitting lines.
222
+ #
223
+ # @param line_length [Integer, #to_int, #to_i]
224
+ # @return [void]
225
+ def set_line_length(line_length)
226
+ raise DestroyedError unless @ptr
227
+ self_p = @ptr
228
+ line_length = Integer(line_length)
229
+ result = ::CZMQ::FFI.zarmour_set_line_length(self_p, line_length)
230
+ result
231
+ end
232
+
233
+ # Print properties of object
234
+ #
235
+ # @return [void]
236
+ def print()
237
+ raise DestroyedError unless @ptr
238
+ self_p = @ptr
239
+ result = ::CZMQ::FFI.zarmour_print(self_p)
240
+ result
241
+ end
242
+
243
+ # Self test of this class.
244
+ #
245
+ # @param verbose [Boolean]
246
+ # @return [void]
247
+ def self.test(verbose)
248
+ verbose = !(0==verbose||!verbose) # boolean
249
+ result = ::CZMQ::FFI.zarmour_test(verbose)
250
+ result
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ ################################################################################
257
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
258
+ # Please refer to the README for information about making permanent changes. #
259
+ ################################################################################