czmq-ffi-gen 0.14.0 → 1.0.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,263 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Read the zproject/README.md for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # Http response that can be received from zhttp_client or sent to zhttp_server.
10
+ # Class can be reused between send & recv calls.
11
+ # Headers and Content is being destroyed after every send call.
12
+ # @note This class is 100% generated using zproject.
13
+ class ZhttpResponse
14
+ # Raised when one tries to use an instance of {ZhttpResponse} after
15
+ # the internal pointer to the native object has been nullified.
16
+ class DestroyedError < RuntimeError; end
17
+
18
+ # Boilerplate for self pointer, initializer, and finalizer
19
+ class << self
20
+ alias :__new :new
21
+ end
22
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
23
+ # it if necessary.
24
+ # @param ptr [::FFI::Pointer]
25
+ # @param finalize [Boolean]
26
+ def initialize(ptr, finalize = true)
27
+ @ptr = ptr
28
+ if @ptr.null?
29
+ @ptr = nil # Remove null pointers so we don't have to test for them.
30
+ elsif finalize
31
+ @finalizer = self.class.create_finalizer_for @ptr
32
+ ObjectSpace.define_finalizer self, @finalizer
33
+ end
34
+ end
35
+ # @param ptr [::FFI::Pointer]
36
+ # @return [Proc]
37
+ def self.create_finalizer_for(ptr)
38
+ Proc.new do
39
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
40
+ ptr_ptr.write_pointer ptr
41
+ ::CZMQ::FFI.zhttp_response_destroy ptr_ptr
42
+ end
43
+ end
44
+ # @return [Boolean]
45
+ def null?
46
+ !@ptr or @ptr.null?
47
+ end
48
+ # Return internal pointer
49
+ # @return [::FFI::Pointer]
50
+ def __ptr
51
+ raise DestroyedError unless @ptr
52
+ @ptr
53
+ end
54
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
55
+ alias_method :to_ptr, :__ptr
56
+ # Nullify internal pointer and return pointer pointer.
57
+ # @note This detaches the current instance from the native object
58
+ # and thus makes it unusable.
59
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
60
+ # pointing to the native object
61
+ def __ptr_give_ref
62
+ raise DestroyedError unless @ptr
63
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
64
+ ptr_ptr.write_pointer @ptr
65
+ __undef_finalizer if @finalizer
66
+ @ptr = nil
67
+ ptr_ptr
68
+ end
69
+ # Undefines the finalizer for this object.
70
+ # @note Only use this if you need to and can guarantee that the native
71
+ # object will be freed by other means.
72
+ # @return [void]
73
+ def __undef_finalizer
74
+ ObjectSpace.undefine_finalizer self
75
+ @finalizer = nil
76
+ end
77
+
78
+ # Create a new zhttp_response.
79
+ # @return [CZMQ::ZhttpResponse]
80
+ def self.new()
81
+ ptr = ::CZMQ::FFI.zhttp_response_new()
82
+ __new ptr
83
+ end
84
+
85
+ # Destroy the zhttp_response.
86
+ #
87
+ # @return [void]
88
+ def destroy()
89
+ return unless @ptr
90
+ self_p = __ptr_give_ref
91
+ result = ::CZMQ::FFI.zhttp_response_destroy(self_p)
92
+ result
93
+ end
94
+
95
+ # Send a response to a request.
96
+ # Returns 0 if successful and -1 otherwise.
97
+ #
98
+ # @param sock [Zsock, #__ptr]
99
+ # @param connection [::FFI::Pointer, #to_ptr]
100
+ # @return [Integer]
101
+ def send(sock, connection)
102
+ raise DestroyedError unless @ptr
103
+ self_p = @ptr
104
+ sock = sock.__ptr if sock
105
+ result = ::CZMQ::FFI.zhttp_response_send(self_p, sock, connection)
106
+ result
107
+ end
108
+
109
+ # Receive a response from zhttp_client.
110
+ # On success return 0, -1 otherwise.
111
+ #
112
+ # Recv returns the two user arguments which was provided with the request.
113
+ # The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
114
+ #
115
+ # @param client [ZhttpClient, #__ptr]
116
+ # @param arg [::FFI::Pointer, #to_ptr]
117
+ # @param arg2 [::FFI::Pointer, #to_ptr]
118
+ # @return [Integer]
119
+ def recv(client, arg, arg2)
120
+ raise DestroyedError unless @ptr
121
+ self_p = @ptr
122
+ client = client.__ptr if client
123
+ result = ::CZMQ::FFI.zhttp_response_recv(self_p, client, arg, arg2)
124
+ result
125
+ end
126
+
127
+ # Get the response content type
128
+ #
129
+ # @return [String]
130
+ def content_type()
131
+ raise DestroyedError unless @ptr
132
+ self_p = @ptr
133
+ result = ::CZMQ::FFI.zhttp_response_content_type(self_p)
134
+ result
135
+ end
136
+
137
+ # Set the content type of the response.
138
+ #
139
+ # @param value [String, #to_s, nil]
140
+ # @return [void]
141
+ def set_content_type(value)
142
+ raise DestroyedError unless @ptr
143
+ self_p = @ptr
144
+ result = ::CZMQ::FFI.zhttp_response_set_content_type(self_p, value)
145
+ result
146
+ end
147
+
148
+ # Get the status code of the response.
149
+ #
150
+ # @return [Integer]
151
+ def status_code()
152
+ raise DestroyedError unless @ptr
153
+ self_p = @ptr
154
+ result = ::CZMQ::FFI.zhttp_response_status_code(self_p)
155
+ result
156
+ end
157
+
158
+ # Set the status code of the response.
159
+ #
160
+ # @param status_code [Integer, #to_int, #to_i]
161
+ # @return [void]
162
+ def set_status_code(status_code)
163
+ raise DestroyedError unless @ptr
164
+ self_p = @ptr
165
+ status_code = Integer(status_code)
166
+ result = ::CZMQ::FFI.zhttp_response_set_status_code(self_p, status_code)
167
+ result
168
+ end
169
+
170
+ # Get the headers of the response.
171
+ #
172
+ # @return [Zhash]
173
+ def headers()
174
+ raise DestroyedError unless @ptr
175
+ self_p = @ptr
176
+ result = ::CZMQ::FFI.zhttp_response_headers(self_p)
177
+ result = Zhash.__new result, false
178
+ result
179
+ end
180
+
181
+ # Get the content length of the response
182
+ #
183
+ # @return [Integer]
184
+ def content_length()
185
+ raise DestroyedError unless @ptr
186
+ self_p = @ptr
187
+ result = ::CZMQ::FFI.zhttp_response_content_length(self_p)
188
+ result
189
+ end
190
+
191
+ # Get the content of the response.
192
+ #
193
+ # @return [String]
194
+ def content()
195
+ raise DestroyedError unless @ptr
196
+ self_p = @ptr
197
+ result = ::CZMQ::FFI.zhttp_response_content(self_p)
198
+ result
199
+ end
200
+
201
+ # Get the content of the response.
202
+ #
203
+ # @return [::FFI::AutoPointer]
204
+ def get_content()
205
+ raise DestroyedError unless @ptr
206
+ self_p = @ptr
207
+ result = ::CZMQ::FFI.zhttp_response_get_content(self_p)
208
+ result = ::FFI::AutoPointer.new(result, LibC.method(:free))
209
+ result
210
+ end
211
+
212
+ # Set the content of the response.
213
+ # Content must by dynamically allocated string.
214
+ # Takes ownership of the content.
215
+ #
216
+ # @param content [::FFI::Pointer, #to_ptr]
217
+ # @return [void]
218
+ def set_content(content)
219
+ raise DestroyedError unless @ptr
220
+ self_p = @ptr
221
+ result = ::CZMQ::FFI.zhttp_response_set_content(self_p, content)
222
+ result
223
+ end
224
+
225
+ # Set the content of the response.
226
+ # The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
227
+ #
228
+ # @param content [String, #to_s, nil]
229
+ # @return [void]
230
+ def set_content_const(content)
231
+ raise DestroyedError unless @ptr
232
+ self_p = @ptr
233
+ result = ::CZMQ::FFI.zhttp_response_set_content_const(self_p, content)
234
+ result
235
+ end
236
+
237
+ # Set the content to NULL
238
+ #
239
+ # @return [void]
240
+ def reset_content()
241
+ raise DestroyedError unless @ptr
242
+ self_p = @ptr
243
+ result = ::CZMQ::FFI.zhttp_response_reset_content(self_p)
244
+ result
245
+ end
246
+
247
+ # Self test of this class.
248
+ #
249
+ # @param verbose [Boolean]
250
+ # @return [void]
251
+ def self.test(verbose)
252
+ verbose = !(0==verbose||!verbose) # boolean
253
+ result = ::CZMQ::FFI.zhttp_response_test(verbose)
254
+ result
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ ################################################################################
261
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
262
+ # Read the zproject/README.md for information about making permanent changes. #
263
+ ################################################################################
@@ -0,0 +1,135 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Read the zproject/README.md for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # Simple http server.
10
+ # To start handling requests:
11
+ # 1. Create a dealer socket
12
+ # 2. Connect the socket to the server backend address provided in the options.
13
+ # 3. Create a zhttp_request.
14
+ # 4. Call zhttp_request_recv to accept a new request.
15
+ # 5. Call zhttp_response_send to send a response.
16
+ #
17
+ # You can connect as many dealers as you want.
18
+ # The Server is using simple dealer socket to route the requests.
19
+ #
20
+ # NOTE: when using libmicrohttpd << 0.9.34 the application might experience
21
+ # high CPU usage due to the lack of MHD_suspend_connection and
22
+ # MHD_resume_connection APIs. It is recommended to use this class only with
23
+ # libmicrohttpd at least 0.9.34 in production.
24
+ # @note This class is 100% generated using zproject.
25
+ class ZhttpServer
26
+ # Raised when one tries to use an instance of {ZhttpServer} after
27
+ # the internal pointer to the native object has been nullified.
28
+ class DestroyedError < RuntimeError; end
29
+
30
+ # Boilerplate for self pointer, initializer, and finalizer
31
+ class << self
32
+ alias :__new :new
33
+ end
34
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
35
+ # it if necessary.
36
+ # @param ptr [::FFI::Pointer]
37
+ # @param finalize [Boolean]
38
+ def initialize(ptr, finalize = true)
39
+ @ptr = ptr
40
+ if @ptr.null?
41
+ @ptr = nil # Remove null pointers so we don't have to test for them.
42
+ elsif finalize
43
+ @finalizer = self.class.create_finalizer_for @ptr
44
+ ObjectSpace.define_finalizer self, @finalizer
45
+ end
46
+ end
47
+ # @param ptr [::FFI::Pointer]
48
+ # @return [Proc]
49
+ def self.create_finalizer_for(ptr)
50
+ Proc.new do
51
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
52
+ ptr_ptr.write_pointer ptr
53
+ ::CZMQ::FFI.zhttp_server_destroy ptr_ptr
54
+ end
55
+ end
56
+ # @return [Boolean]
57
+ def null?
58
+ !@ptr or @ptr.null?
59
+ end
60
+ # Return internal pointer
61
+ # @return [::FFI::Pointer]
62
+ def __ptr
63
+ raise DestroyedError unless @ptr
64
+ @ptr
65
+ end
66
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
67
+ alias_method :to_ptr, :__ptr
68
+ # Nullify internal pointer and return pointer pointer.
69
+ # @note This detaches the current instance from the native object
70
+ # and thus makes it unusable.
71
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
72
+ # pointing to the native object
73
+ def __ptr_give_ref
74
+ raise DestroyedError unless @ptr
75
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
76
+ ptr_ptr.write_pointer @ptr
77
+ __undef_finalizer if @finalizer
78
+ @ptr = nil
79
+ ptr_ptr
80
+ end
81
+ # Undefines the finalizer for this object.
82
+ # @note Only use this if you need to and can guarantee that the native
83
+ # object will be freed by other means.
84
+ # @return [void]
85
+ def __undef_finalizer
86
+ ObjectSpace.undefine_finalizer self
87
+ @finalizer = nil
88
+ end
89
+
90
+ # Create a new http server
91
+ # @param options [ZhttpServerOptions, #__ptr]
92
+ # @return [CZMQ::ZhttpServer]
93
+ def self.new(options)
94
+ options = options.__ptr if options
95
+ ptr = ::CZMQ::FFI.zhttp_server_new(options)
96
+ __new ptr
97
+ end
98
+
99
+ # Destroy an http server
100
+ #
101
+ # @return [void]
102
+ def destroy()
103
+ return unless @ptr
104
+ self_p = __ptr_give_ref
105
+ result = ::CZMQ::FFI.zhttp_server_destroy(self_p)
106
+ result
107
+ end
108
+
109
+ # Return the port the server is listening on.
110
+ #
111
+ # @return [Integer]
112
+ def port()
113
+ raise DestroyedError unless @ptr
114
+ self_p = @ptr
115
+ result = ::CZMQ::FFI.zhttp_server_port(self_p)
116
+ result
117
+ end
118
+
119
+ # Self test of this class.
120
+ #
121
+ # @param verbose [Boolean]
122
+ # @return [void]
123
+ def self.test(verbose)
124
+ verbose = !(0==verbose||!verbose) # boolean
125
+ result = ::CZMQ::FFI.zhttp_server_test(verbose)
126
+ result
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ ################################################################################
133
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
134
+ # Read the zproject/README.md for information about making permanent changes. #
135
+ ################################################################################
@@ -0,0 +1,91 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Read the zproject/README.md for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ #
10
+ # @note This class is 100% generated using zproject.
11
+ class ZhttpServerConnection
12
+ # Raised when one tries to use an instance of {ZhttpServerConnection} 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
+ # @return [Proc]
34
+ def self.create_finalizer_for(ptr)
35
+ Proc.new do
36
+ "WARNING: "\
37
+ "Objects of type #{self} cannot be destroyed implicitly. "\
38
+ "Please call the correct destroy method with the relevant arguments."
39
+ end
40
+ end
41
+ # @return [Boolean]
42
+ def null?
43
+ !@ptr or @ptr.null?
44
+ end
45
+ # Return internal pointer
46
+ # @return [::FFI::Pointer]
47
+ def __ptr
48
+ raise DestroyedError unless @ptr
49
+ @ptr
50
+ end
51
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
52
+ alias_method :to_ptr, :__ptr
53
+ # Nullify internal pointer and return pointer pointer.
54
+ # @note This detaches the current instance from the native object
55
+ # and thus makes it unusable.
56
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
57
+ # pointing to the native object
58
+ def __ptr_give_ref
59
+ raise DestroyedError unless @ptr
60
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
61
+ ptr_ptr.write_pointer @ptr
62
+ __undef_finalizer if @finalizer
63
+ @ptr = nil
64
+ ptr_ptr
65
+ end
66
+ # Undefines the finalizer for this object.
67
+ # @note Only use this if you need to and can guarantee that the native
68
+ # object will be freed by other means.
69
+ # @return [void]
70
+ def __undef_finalizer
71
+ ObjectSpace.undefine_finalizer self
72
+ @finalizer = nil
73
+ end
74
+
75
+ # Self test of this class.
76
+ #
77
+ # @param verbose [Boolean]
78
+ # @return [void]
79
+ def self.test(verbose)
80
+ verbose = !(0==verbose||!verbose) # boolean
81
+ result = ::CZMQ::FFI.zhttp_server_connection_test(verbose)
82
+ result
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ ################################################################################
89
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
90
+ # Read the zproject/README.md for information about making permanent changes. #
91
+ ################################################################################