zmq 1.0 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/ext/zmq/zmq.cpp DELETED
@@ -1,200 +0,0 @@
1
- /*
2
- Copyright (c) 2007-2009 FastMQ Inc.
3
-
4
- This file is part of 0MQ.
5
-
6
- 0MQ is free software; you can redistribute it and/or modify it under
7
- the terms of the Lesser GNU General Public License as published by
8
- the Free Software Foundation; either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- 0MQ is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- Lesser GNU General Public License for more details.
15
-
16
- You should have received a copy of the Lesser GNU General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
-
20
- #include <zmq.hpp>
21
- #include <zmq/err.hpp>
22
- #include <ruby.h>
23
-
24
- struct context_t
25
- {
26
- zmq::dispatcher_t *dispatcher;
27
- zmq::locator_t *locator;
28
- zmq::i_thread *io_thread;
29
- zmq::api_thread_t *api_thread;
30
- };
31
-
32
- static VALUE rb_zmq;
33
- static VALUE rb_data;
34
-
35
- static void rb_free (void *p)
36
- {
37
- context_t *context = (context_t*) p;
38
-
39
- // Deallocate the 0MQ infrastructure.
40
- delete context->locator;
41
- delete context->dispatcher;
42
- delete context;
43
- }
44
-
45
- static VALUE rb_alloc (VALUE self_)
46
- {
47
- context_t *context;
48
- VALUE obj;
49
-
50
- context = new context_t;
51
- obj = Data_Wrap_Struct (self_, 0, rb_free, context);
52
-
53
- return obj;
54
- }
55
-
56
- static VALUE rb_init (VALUE self_, VALUE host_)
57
- {
58
- // Get the context.
59
- context_t* context;
60
- Data_Get_Struct (self_, context_t, context);
61
-
62
- context->dispatcher = new zmq::dispatcher_t (2);
63
- assert (context->dispatcher);
64
-
65
- context->locator = new zmq::locator_t (StringValueCStr (host_));
66
- assert (context->locator);
67
-
68
- context->io_thread = zmq::io_thread_t::create (context->dispatcher);
69
- assert (context->io_thread);
70
-
71
- context->api_thread = zmq::api_thread_t::create (context->dispatcher,
72
- context->locator);
73
- assert (context->api_thread);
74
-
75
- return self_;
76
- }
77
-
78
- static VALUE rb_mask (VALUE self_, VALUE notifications_)
79
- {
80
- // Get the context.
81
- context_t* context;
82
- Data_Get_Struct (self_, context_t, context);
83
-
84
- // Forward the call.
85
- context->api_thread->mask (NUM2UINT (notifications_));
86
-
87
- return self_;
88
- }
89
-
90
- static VALUE rb_create_exchange (VALUE self_, VALUE name_, VALUE scope_,
91
- VALUE location_, VALUE style_)
92
- {
93
- // Get the context.
94
- context_t* context;
95
- Data_Get_Struct (self_, context_t, context);
96
-
97
- // Forward the call to native 0MQ library.
98
- return INT2NUM (context->api_thread->create_exchange (
99
- StringValueCStr (name_), (zmq::scope_t) NUM2INT (scope_),
100
- StringValueCStr (location_), context->io_thread, 1, &context->io_thread,
101
- (zmq::style_t) NUM2INT (style_)));
102
- }
103
-
104
- static VALUE rb_create_queue (VALUE self_, VALUE name_, VALUE scope_,
105
- VALUE location_, VALUE hwm_, VALUE lwm_, VALUE swap_)
106
- {
107
- // Get the context.
108
- context_t* context;
109
- Data_Get_Struct (self_, context_t, context);
110
-
111
- // Forward the call to native 0MQ library.
112
- return INT2NUM ((context->api_thread->create_queue (
113
- StringValueCStr (name_), (zmq::scope_t) NUM2INT (scope_),
114
- StringValueCStr (location_), context->io_thread, 1,
115
- &context->io_thread, NUM2LL (hwm_), NUM2LL (lwm_), NUM2LL (swap_))));
116
- }
117
-
118
- static VALUE rb_bind (VALUE self_, VALUE exchange_name_, VALUE queue_name_,
119
- VALUE exchange_options_, VALUE queue_options_)
120
- {
121
- // Get the context.
122
- context_t* context;
123
- Data_Get_Struct (self_, context_t, context);
124
-
125
- // Forward the call to native 0MQ library.
126
- context->api_thread->bind (StringValueCStr (exchange_name_),
127
- StringValueCStr (queue_name_), context->io_thread, context->io_thread,
128
- StringValueCStr (exchange_options_), StringValueCStr (queue_options_));
129
-
130
- return self_;
131
- }
132
-
133
- static VALUE rb_send (VALUE self_, VALUE exchange_, VALUE data_, VALUE block_)
134
- {
135
- // Get the context.
136
- context_t* context;
137
- Data_Get_Struct (self_, context_t, context);
138
-
139
- // Forward the call to native 0MQ library.
140
- zmq::message_t msg ((size_t) RSTRING_LEN (data_));
141
- memcpy (msg.data (), (void*) RSTRING_PTR (data_),
142
- RSTRING_LEN (data_));
143
-
144
- return context->api_thread->send (NUM2INT (exchange_), msg,
145
- NUM2INT (block_) ? true : false);
146
- }
147
-
148
- static VALUE rb_receive (VALUE self_, VALUE block_)
149
- {
150
- // Get the context.
151
- context_t* context;
152
- Data_Get_Struct (self_, context_t, context);
153
-
154
- // Forward the call to native 0MQ library.
155
- zmq::message_t msg;
156
- int qid = context->api_thread->receive (&msg,
157
- NUM2INT(block_) ? true : false);
158
-
159
- VALUE rb_msg = rb_str_new ((char *) msg.data (), msg.size ());
160
- VALUE rb_type = INT2NUM (msg.type ());
161
- VALUE rb_qid = INT2NUM (qid);
162
-
163
- return rb_struct_new (rb_data, rb_msg, rb_type, rb_qid, NULL);
164
- }
165
-
166
- extern "C"
167
- void Init_zmq_native() {
168
-
169
- rb_zmq = rb_define_class ("Zmq", rb_cObject);
170
-
171
- rb_define_alloc_func (rb_zmq, rb_alloc);
172
-
173
- rb_define_method (rb_zmq, "initialize", (VALUE(*)(...)) rb_init, 1);
174
- rb_define_method (rb_zmq, "mask", (VALUE(*)(...)) rb_mask, 1);
175
- rb_define_method (rb_zmq, "create_exchange",
176
- (VALUE(*)(...)) rb_create_exchange, 4);
177
- rb_define_method (rb_zmq, "create_queue",
178
- (VALUE(*)(...)) rb_create_queue, 6);
179
- rb_define_method (rb_zmq, "bind", (VALUE(*)(...)) rb_bind, 4);
180
- rb_define_method (rb_zmq, "send", (VALUE(*)(...)) rb_send, 3);
181
- rb_define_method (rb_zmq, "receive", (VALUE(*)(...)) rb_receive, 1);
182
- rb_define_method (rb_zmq, "free", (VALUE(*)(...)) rb_free, 0);
183
-
184
- rb_data = rb_struct_define (NULL, "msg", "type", "qid", NULL);
185
- rb_define_const (rb_zmq, "DATA", rb_data);
186
-
187
- rb_define_global_const ("ZMQ_SCOPE_LOCAL", INT2NUM (zmq::scope_local));
188
- rb_define_global_const ("ZMQ_SCOPE_PROCESS", INT2NUM (zmq::scope_process));
189
- rb_define_global_const ("ZMQ_SCOPE_GLOBAL", INT2NUM (zmq::scope_global));
190
- rb_define_global_const ("ZMQ_MESSAGE_DATA", INT2NUM (zmq::message_data));
191
- rb_define_global_const ("ZMQ_MESSAGE_GAP", INT2NUM (zmq::message_gap));
192
- rb_define_global_const ("ZMQ_STYLE_DATA_DISTRIBUTION",
193
- INT2NUM (zmq::style_data_distribution));
194
- rb_define_global_const ("ZMQ_STYLE_LOAD_BALANCING",
195
- INT2NUM (zmq::style_load_balancing));
196
- rb_define_global_const ("ZMQ_NO_LIMIT", INT2NUM (zmq::no_limit));
197
- rb_define_global_const ("ZMQ_NO_SWAP", INT2NUM (zmq::no_swap));
198
- rb_define_global_const ("ZMQ_TRUE", INT2NUM (1));
199
- rb_define_global_const ("ZMQ_FALSE", INT2NUM (0));
200
- }
data/lib/zmq.rb DELETED
@@ -1 +0,0 @@
1
- require "zmq_native"
data/test/all_tests.rb DELETED
@@ -1,3 +0,0 @@
1
- Dir["#{File.dirname __FILE__}/**/*_tests.rb"].each do |test_case|
2
- require test_case
3
- end
data/test/test_helper.rb DELETED
@@ -1,7 +0,0 @@
1
- $:.unshift File.dirname(__FILE__) + '/../lib'
2
- $:.unshift File.dirname(__FILE__) + '/../ext/zmq'
3
- $: << File.dirname(__FILE__) + "/../vendor/gems/spartan-1.0/lib"
4
- require 'test/unit'
5
- require 'spartan'
6
- # require 'mocha'
7
- require 'zmq'
@@ -1,9 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- functional_tests do
4
-
5
- test "to be done" do
6
- puts "To be done"
7
- end
8
-
9
- end