WireAPI 0.3
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.
- data/amq_connection.c +232 -0
- data/amq_connection.h +5 -0
- data/amq_content.c +533 -0
- data/amq_content.h +7 -0
- data/amq_field_list.c +318 -0
- data/amq_field_list.h +13 -0
- data/amq_session.c +954 -0
- data/amq_session.h +5 -0
- data/amq_types.c +273 -0
- data/amq_types.h +128 -0
- data/amq_wireapi.c +195 -0
- data/extconf.rb +30 -0
- metadata +64 -0
data/amq_connection.c
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
|
2
|
+
/**********************************************
|
3
|
+
* Document-class: WireAPI::AMQ_Connection
|
4
|
+
*
|
5
|
+
*
|
6
|
+
**********************************************/
|
7
|
+
|
8
|
+
|
9
|
+
#include <ruby.h>
|
10
|
+
#include "amq_types.h"
|
11
|
+
#include "amq_connection.h"
|
12
|
+
#include <amq_client_connection.h>
|
13
|
+
|
14
|
+
VALUE amqp_connection;
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Document-method: alive
|
18
|
+
* call-seq:
|
19
|
+
* AMQ_Connection#alive -> boolean
|
20
|
+
*/
|
21
|
+
static VALUE con_alive(VALUE self)
|
22
|
+
{
|
23
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
24
|
+
if (amq_client_connection_get_alive(connection_obj->connection))
|
25
|
+
return Qtrue;
|
26
|
+
else
|
27
|
+
return Qfalse;
|
28
|
+
}
|
29
|
+
|
30
|
+
/* Document-method: client_session_new
|
31
|
+
*
|
32
|
+
* AMQ_Connection#client_session_new -> AMQP_Session
|
33
|
+
*/
|
34
|
+
static VALUE con_client_session_new(VALUE self)
|
35
|
+
{
|
36
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
37
|
+
amq_client_session_t *session = NULL;
|
38
|
+
VALUE rb_session;
|
39
|
+
if (connection_obj) {
|
40
|
+
session = amq_client_session_new (connection_obj->connection);
|
41
|
+
rb_session = create_amq_session_cls(session);
|
42
|
+
} else {
|
43
|
+
rb_raise(rb_eRuntimeError,"Could not connect to server");
|
44
|
+
}
|
45
|
+
|
46
|
+
return(rb_session);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
/*
|
52
|
+
* AMQ_Connection#destroy -> nil
|
53
|
+
*
|
54
|
+
*/
|
55
|
+
static VALUE con_client_connection_destroy(VALUE self)
|
56
|
+
{
|
57
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,0);
|
58
|
+
if (connection_obj && connection_obj->connection) {
|
59
|
+
amq_client_connection_destroy(&(connection_obj->connection));
|
60
|
+
connection_obj->connection=0;
|
61
|
+
}
|
62
|
+
return Qnil;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* AMQ_Connection#error_text -> string
|
68
|
+
*/
|
69
|
+
static VALUE con_error_text(VALUE self)
|
70
|
+
{
|
71
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
72
|
+
const char *error_text=amq_client_connection_get_error_text(connection_obj->connection);
|
73
|
+
return rb_str_new2(error_text);
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
/*
|
78
|
+
* AMQ_Connection#reply_code -> Fixnum
|
79
|
+
*/
|
80
|
+
static VALUE con_reply_code(VALUE self)
|
81
|
+
{
|
82
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
83
|
+
int reply_code=amq_client_connection_get_reply_code(connection_obj->connection);
|
84
|
+
return INT2FIX(reply_code);
|
85
|
+
}
|
86
|
+
|
87
|
+
/*
|
88
|
+
* AMQ_Connection#reply_text -> string
|
89
|
+
*/
|
90
|
+
static VALUE con_reply_text(VALUE self)
|
91
|
+
{
|
92
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
93
|
+
const char *reply_text=amq_client_connection_get_reply_text(connection_obj->connection);
|
94
|
+
return rb_str_new2(reply_text);
|
95
|
+
}
|
96
|
+
|
97
|
+
/*
|
98
|
+
* AMQ_Connection#server_copyright -> string
|
99
|
+
*/
|
100
|
+
static VALUE con_server_copyright(VALUE self)
|
101
|
+
{
|
102
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
103
|
+
return rb_str_new2(connection_obj->connection->server_copyright);
|
104
|
+
}
|
105
|
+
|
106
|
+
/*
|
107
|
+
* AMQ_Connection#server_information -> string
|
108
|
+
*/
|
109
|
+
static VALUE con_server_information(VALUE self)
|
110
|
+
{
|
111
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
112
|
+
return rb_str_new2(connection_obj->connection->server_information);
|
113
|
+
}
|
114
|
+
|
115
|
+
/*
|
116
|
+
* AMQ_Connection#server_platform -> string
|
117
|
+
*/
|
118
|
+
static VALUE con_server_platform(VALUE self)
|
119
|
+
{
|
120
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
121
|
+
return rb_str_new2(connection_obj->connection->server_platform);
|
122
|
+
}
|
123
|
+
|
124
|
+
/*
|
125
|
+
* AMQ_Connection#server_product -> string
|
126
|
+
*/
|
127
|
+
static VALUE con_server_product(VALUE self)
|
128
|
+
{
|
129
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
130
|
+
return rb_str_new2(connection_obj->connection->server_product);
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* AMQ_Connection#server_version -> string
|
135
|
+
*/
|
136
|
+
static VALUE con_server_version(VALUE self)
|
137
|
+
{
|
138
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
139
|
+
return rb_str_new2(connection_obj->connection->server_version);
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/*
|
144
|
+
* AMQ_Connection#silent -> boolean
|
145
|
+
*/
|
146
|
+
static VALUE con_get_silent(VALUE self)
|
147
|
+
{
|
148
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
149
|
+
if ( amq_client_connection_get_silent(connection_obj->connection))
|
150
|
+
return Qtrue;
|
151
|
+
else
|
152
|
+
return Qfalse;
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
/*
|
157
|
+
* AMQ_Connection#silent=(boolean) -> self
|
158
|
+
*/
|
159
|
+
static VALUE con_set_silent(VALUE self,VALUE nval)
|
160
|
+
{
|
161
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
162
|
+
int result=0;
|
163
|
+
if (nval==Qtrue) {
|
164
|
+
result=amq_client_connection_set_silent(connection_obj->connection,1);
|
165
|
+
} else if (nval==Qfalse) {
|
166
|
+
result=amq_client_connection_set_silent(connection_obj->connection,0);
|
167
|
+
} else {
|
168
|
+
rb_raise(rb_amq_error,"AMQ_Connection#silent=(boolean) argument not boolean");
|
169
|
+
}
|
170
|
+
if (result) {
|
171
|
+
rb_raise(rb_amq_error,"amq_client_connection_set_silent(..) failed");
|
172
|
+
}
|
173
|
+
return self;
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
/*
|
178
|
+
* AMQ_Connection#version_major -> Fixnum
|
179
|
+
*/
|
180
|
+
static VALUE con_version_major(VALUE self)
|
181
|
+
{
|
182
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
183
|
+
int version_major=amq_client_connection_get_version_major(connection_obj->connection);
|
184
|
+
return INT2FIX(version_major);
|
185
|
+
}
|
186
|
+
|
187
|
+
/*
|
188
|
+
* AMQ_Connection#version_minor -> Fixnum
|
189
|
+
*/
|
190
|
+
static VALUE con_version_minor(VALUE self)
|
191
|
+
{
|
192
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
193
|
+
int version_minor=amq_client_connection_get_version_minor(connection_obj->connection);
|
194
|
+
return INT2FIX(version_minor);
|
195
|
+
}
|
196
|
+
|
197
|
+
/*
|
198
|
+
* AMQ_Connection#version -> String
|
199
|
+
*/
|
200
|
+
static VALUE con_version(VALUE self)
|
201
|
+
{
|
202
|
+
amq_connection_cls *const connection_obj=get_amq_connection_cls(self,1);
|
203
|
+
const int len=80;
|
204
|
+
char buffer[len+1];
|
205
|
+
int version_major=amq_client_connection_get_version_major(connection_obj->connection);
|
206
|
+
int version_minor=amq_client_connection_get_version_minor(connection_obj->connection);
|
207
|
+
snprintf(buffer,len,"%i.%i",version_major,version_minor);
|
208
|
+
return rb_str_new2(buffer);
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
void init_connection() {
|
215
|
+
amqp_connection = rb_define_class_under(rb_wireapi,"AMQ_Connection",rb_cObject); // in amq_client.c
|
216
|
+
rb_define_method(amqp_connection,"alive",con_alive,0);
|
217
|
+
rb_define_method(amqp_connection,"client_session_new", con_client_session_new,0);
|
218
|
+
rb_define_method(amqp_connection,"destroy",con_client_connection_destroy,0);
|
219
|
+
rb_define_method(amqp_connection,"error_text",con_error_text,0);
|
220
|
+
rb_define_method(amqp_connection,"reply_code",con_reply_code,0);
|
221
|
+
rb_define_method(amqp_connection,"reply_text",con_reply_text,0);
|
222
|
+
rb_define_method(amqp_connection,"server_copyright",con_server_copyright,0);
|
223
|
+
rb_define_method(amqp_connection,"server_information",con_server_information,0);
|
224
|
+
rb_define_method(amqp_connection,"server_platform",con_server_platform,0);
|
225
|
+
rb_define_method(amqp_connection,"server_product",con_server_product,0);
|
226
|
+
rb_define_method(amqp_connection,"server_version",con_server_version,0);
|
227
|
+
rb_define_method(amqp_connection,"silent",con_get_silent,0);
|
228
|
+
rb_define_method(amqp_connection,"silent=",con_set_silent,1);
|
229
|
+
rb_define_method(amqp_connection,"version_major",con_version_major,0);
|
230
|
+
rb_define_method(amqp_connection,"version_minor",con_version_minor,0);
|
231
|
+
rb_define_method(amqp_connection,"version",con_version,0);
|
232
|
+
}
|