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_content.c ADDED
@@ -0,0 +1,533 @@
1
+
2
+
3
+ /**********************************************
4
+ * WireAPI::AMQ_ContentBasic
5
+ *
6
+ *
7
+ **********************************************/
8
+
9
+ #include <ruby.h>
10
+ #include <asl.h>
11
+ #include "amq_types.h"
12
+ #include <amq_content_basic.h>
13
+ #include "amq_content.h"
14
+ #include "amq_field_list.h"
15
+
16
+ VALUE amqp_content;
17
+
18
+
19
+ static VALUE cont_content_basic_new(VALUE self)
20
+ {
21
+ VALUE rb_content=create_amq_content_cls(amq_content_basic_new ());
22
+ return rb_content;
23
+ }
24
+
25
+
26
+
27
+ /*
28
+ * AMQ_ContentBasic#destroy() -> self
29
+ */
30
+ static VALUE cont_content_basic_destroy(VALUE self)
31
+ {
32
+ amq_content_cls* content_obj=get_amq_content_cls(self,0);
33
+ if (content_obj && content_obj->content) {
34
+ amq_content_basic_unlink(&(content_obj->content));
35
+ content_obj->content=0;
36
+ }
37
+ return Qnil;
38
+ }
39
+
40
+
41
+
42
+ /*
43
+ * AMQ_ContentBasic#app_id -> string
44
+ *
45
+ */
46
+ static VALUE cont_content_basic_get_app_id(VALUE self)
47
+ {
48
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
49
+ const char *const app_id=amq_content_basic_get_app_id(content_obj->content);
50
+ return rb_str_new2(app_id);
51
+ }
52
+
53
+ /*
54
+ * AMQ_ContentBasic#app_id=(string) -> self
55
+ *
56
+ */
57
+ static VALUE cont_content_basic_set_app_id(VALUE self,VALUE appid)
58
+ {
59
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
60
+ Check_Type(appid,T_STRING);
61
+ char *_app_id = StringValuePtr(appid);
62
+
63
+ amq_content_basic_set_app_id(content_obj->content,_app_id);
64
+ return self;
65
+ }
66
+
67
+ /*
68
+ * AMQ_ContentBasic#body=(string) -> self
69
+ */
70
+ static VALUE cont_content_basic_set_body(VALUE self,VALUE value)
71
+ {
72
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
73
+ Check_Type(value,T_STRING);
74
+ char *_value = strdup(StringValuePtr(value));
75
+ amq_content_basic_set_body (content_obj->content,
76
+ _value,
77
+ RSTRING_LEN(value),
78
+ free);
79
+ return self;
80
+ }
81
+
82
+ /*
83
+ * AMQ_ContentBasic#body(size) -> String
84
+ * the maximum size that will be accepted
85
+ * 0 or nil means no limit
86
+ */
87
+ static VALUE cont_content_basic_get_body(int argc, VALUE *argv, VALUE self) {
88
+ amq_content_cls *const content_obj=get_amq_content_cls(self,1);
89
+ VALUE size;
90
+ rb_scan_args(argc,argv,"01",&size);
91
+ int _size=0;
92
+ if (TYPE(size)==T_FIXNUM)
93
+ _size=NUM2INT(size);
94
+ if (_size==0)
95
+ _size=2+amq_content_basic_get_body_size(content_obj->content);
96
+ char *const _value= malloc(_size+1);
97
+ VALUE val;
98
+
99
+ if (_value) {
100
+ int len=amq_content_basic_get_body(content_obj->content,(byte*)_value,_size);
101
+ if (len>=0) {
102
+ val=rb_str_new(_value,len);
103
+ } else {
104
+ val=Qnil;
105
+ }
106
+ free(_value);
107
+ } else {
108
+ rb_raise(rb_eNoMemError,"can't allocate receive buffer");
109
+ }
110
+ return val;
111
+ }
112
+
113
+
114
+ /*
115
+ * AMQ_ContentBasic#body_size -> number
116
+ */
117
+ static VALUE cont_content_basic_get_body_size(VALUE self)
118
+ {
119
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
120
+ int size=amq_content_basic_get_body_size (content_obj->content);
121
+ return INT2NUM(size);
122
+ }
123
+
124
+
125
+ /*
126
+ * AMQ_ContentBasic#exchange -> string
127
+ * the exchange where the content was published
128
+ */
129
+ static VALUE cont_content_basic_get_exchange(VALUE self)
130
+ {
131
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
132
+ const char *const exchange=amq_content_basic_get_exchange(content_obj->content);
133
+ return rb_str_new2(exchange);
134
+ }
135
+
136
+
137
+
138
+
139
+ /*
140
+ * AMQ_ContentBasic#expiration -> string
141
+ * the exchange where the content was published
142
+ */
143
+ static VALUE cont_content_basic_get_expiration(VALUE self)
144
+ {
145
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
146
+ const char *const expiration=amq_content_basic_get_expiration(content_obj->content);
147
+ return rb_str_new2(expiration);
148
+ }
149
+
150
+
151
+ static VALUE cont_content_basic_set_expiration(VALUE self,VALUE expiration)
152
+ {
153
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
154
+ Check_Type(expiration,T_STRING);
155
+ char *_expirat=StringValuePtr(expiration);
156
+ amq_content_basic_set_expiration(content_obj->content,_expirat);
157
+ return self;
158
+ }
159
+
160
+
161
+
162
+ static VALUE cont_content_basic_get_delivery_mode_persistent(VALUE self)
163
+ {
164
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
165
+ if (amq_content_basic_get_deliverymode(content_obj->content)==2)
166
+ return Qtrue;
167
+ else
168
+ return Qfalse;
169
+ }
170
+
171
+
172
+ static VALUE cont_content_basic_set_delivery_mode_persistent(VALUE self,VALUE persist)
173
+ {
174
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
175
+ int _persistent=VALUE2bool (persist,"arg: persistent not boolean");
176
+ amq_content_basic_set_delivery_mode(content_obj->content,(_persistent)?2:1);
177
+ return self;
178
+ }
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+ /*
187
+ * AMQ_ContentBasic#headers -> hash
188
+ */
189
+ static VALUE cont_content_basic_get_headers(VALUE self)
190
+ {
191
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
192
+ icl_longstr_t *header=
193
+ amq_content_basic_get_headers(content_obj->content);
194
+ VALUE result=Qnil;
195
+ result=create_amq_field_list_cls(asl_field_list_new (header));
196
+
197
+ return result;
198
+ }
199
+
200
+
201
+
202
+ /* utility for headers= method*/
203
+
204
+
205
+ /*
206
+ * AMQ_ContentBasic#headers(hash) -> self
207
+ */
208
+ static VALUE cont_content_basic_set_headers(VALUE self, VALUE headers)
209
+ {
210
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
211
+
212
+ icl_longstr_t *header_arg= get_optional_field_list(headers);
213
+ if (!header_arg) {
214
+ rb_raise(rb_eArgError,"argument must be convertable to a AMQ_FieldList object");
215
+ }
216
+
217
+ amq_content_basic_set_headers(content_obj->content,header_arg);
218
+
219
+ return self;
220
+ }
221
+
222
+
223
+
224
+ /*
225
+ AMQ_ContentBasic#routing_key -> string
226
+ */
227
+ static VALUE cont_content_basic_get_routing_key(VALUE self)
228
+ {
229
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
230
+ const char *const routing_key=amq_content_basic_get_routing_key(content_obj->content);
231
+ return rb_str_new2(routing_key);
232
+ }
233
+
234
+
235
+ /*
236
+ * AMQ_ContentBasic#content_type -> string
237
+ */
238
+ static VALUE cont_content_basic_get_content_type(VALUE self)
239
+ {
240
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
241
+ const char *const content_type=amq_content_basic_get_content_type(content_obj->content);
242
+ return rb_str_new2(content_type);
243
+ }
244
+
245
+ /*
246
+ * AMQ_ContentBasic#content_type=(string) -> self
247
+ */
248
+ static VALUE cont_content_basic_set_content_type(VALUE self,VALUE type)
249
+ {
250
+ Check_Type(type,T_STRING);
251
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
252
+ char *_type = StringValuePtr(type);
253
+
254
+ amq_content_basic_set_content_type(content_obj->content,_type);
255
+ return self;
256
+ }
257
+
258
+
259
+
260
+
261
+ /*
262
+ * AMQ_ContentBasic#content_type -> string
263
+ * MIME Content-type
264
+ */
265
+ static VALUE cont_content_basic_get_content_encoding(VALUE self)
266
+ {
267
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
268
+ const char *const content_encoding=amq_content_basic_get_content_encoding(content_obj->content);
269
+ return rb_str_new2(content_encoding);
270
+ }
271
+
272
+ /*
273
+ * AMQ_ContentBasic#content_type=(string) -> self
274
+ * MIME Content-type
275
+ */
276
+ static VALUE cont_content_basic_set_content_encoding(VALUE self,VALUE encoding)
277
+ {
278
+ Check_Type(encoding,T_STRING);
279
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
280
+ char *_encoding = StringValuePtr(encoding);
281
+
282
+ amq_content_basic_set_content_encoding(content_obj->content,_encoding);
283
+ return self;
284
+ }
285
+
286
+
287
+
288
+ /*
289
+ * AMQ_ContentBasic#correlation_id -> string
290
+ */
291
+ static VALUE cont_content_basic_get_correlation_id(VALUE self)
292
+ {
293
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
294
+ const char *const corr_id=amq_content_basic_get_correlation_id(content_obj->content);
295
+ return rb_str_new2(corr_id);
296
+ }
297
+
298
+
299
+ /*
300
+ * AMQ_ContentBasic#correlation_id=(string) -> self
301
+ */
302
+ static VALUE cont_content_basic_set_correlation_id(VALUE self,VALUE cor_id)
303
+ {
304
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
305
+ Check_Type(cor_id,T_STRING);
306
+ char *_cor_id = StringValuePtr(cor_id);
307
+
308
+ amq_content_basic_set_correlation_id(content_obj->content,_cor_id);
309
+ return self;
310
+ }
311
+
312
+
313
+
314
+ /*
315
+ * AMQ_ContentBasic#message_id -> string
316
+ *
317
+ */
318
+ static VALUE cont_content_basic_get_message_id(VALUE self)
319
+ {
320
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
321
+ const char *const message_id=amq_content_basic_get_message_id(content_obj->content);
322
+ return rb_str_new2(message_id);
323
+ }
324
+
325
+ /*
326
+ * AMQ_ContentBasic#message_id=(fixnum) -> self
327
+ */
328
+ static VALUE cont_content_basic_set_message_id(VALUE self, VALUE message_id)
329
+ {
330
+ icl_shortstr_t message_id_t;
331
+ amq_content_cls * const content_obj=get_amq_content_cls(self,1);
332
+ if( FIXNUM_P(message_id))
333
+ {
334
+ icl_shortstr_fmt (message_id_t, "ID%d", FIX2INT(message_id));
335
+ amq_content_basic_set_message_id (content_obj->content, message_id_t);
336
+ } else {
337
+ rb_raise(rb_eTypeError,"Timeout was not an Fixnum");
338
+ }
339
+ return self;
340
+ }
341
+
342
+
343
+
344
+
345
+
346
+ /*
347
+ * AMQ_ContentBasic#priority -> number
348
+ */
349
+ static VALUE cont_content_basic_get_priority(VALUE self)
350
+ {
351
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
352
+ int prio=amq_content_basic_get_priority(content_obj->content);
353
+ return INT2NUM(prio);
354
+ }
355
+
356
+
357
+ /*
358
+ * AMQ_ContentBasic#priority=(Number) -> self
359
+ */
360
+ static VALUE cont_content_basic_set_priority(VALUE self,VALUE prio)
361
+ {
362
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
363
+ int num=INT2NUM(prio);
364
+ if (num<0 || num>0)
365
+ rb_raise(rb_eArgError,"priority only in range 0..9");
366
+ amq_content_basic_set_priority(content_obj->content,num);
367
+ return self;
368
+ }
369
+
370
+
371
+ /*
372
+ * AMQ_ContentBasic#producer_id -> string
373
+ */
374
+ static VALUE cont_content_basic_get_producer_id(VALUE self)
375
+ {
376
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
377
+ const char *const producer_id=amq_content_basic_get_producer_id(content_obj->content);
378
+ return rb_str_new2(producer_id);
379
+ }
380
+
381
+
382
+
383
+ /*
384
+ * AMQ_ContentBasic#reply_to -> string
385
+ */
386
+ static VALUE cont_content_basic_get_reply_to(VALUE self)
387
+ {
388
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
389
+ const char *const reply_to=amq_content_basic_get_reply_to(content_obj->content);
390
+ return rb_str_new2(reply_to);
391
+ }
392
+
393
+
394
+ /*
395
+ * AMQ_ContentBasic#reply_to=(string) -> self
396
+ */
397
+ static VALUE cont_content_basic_set_reply_to(VALUE self,VALUE reply_to)
398
+ {
399
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
400
+ Check_Type(reply_to,T_STRING);
401
+ char *_reply_to = StringValuePtr(reply_to);
402
+
403
+ amq_content_basic_set_reply_to(content_obj->content,_reply_to);
404
+ return self;
405
+ }
406
+
407
+
408
+ /*
409
+ * AMQ_ContentBasic#sender_id -> string
410
+ *
411
+ */
412
+ static VALUE cont_content_basic_get_sender_id(VALUE self)
413
+ {
414
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
415
+ const char *const sender_id=amq_content_basic_get_sender_id(content_obj->content);
416
+ return rb_str_new2(sender_id);
417
+ }
418
+
419
+ /*
420
+ * AMQ_ContentBasic#sender_id=(string) -> self
421
+ *
422
+ */
423
+ static VALUE cont_content_basic_set_sender_id(VALUE self,VALUE sender_id)
424
+ {
425
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
426
+ Check_Type(sender_id,T_STRING);
427
+ char *_sender_id = StringValuePtr(sender_id);
428
+ amq_content_basic_set_sender_id(content_obj->content,_sender_id);
429
+ return self;
430
+ }
431
+
432
+ /*
433
+ * AMQ_ContentBasic#type -> string
434
+ *
435
+ * message type
436
+ */
437
+ static VALUE cont_content_basic_get_type(VALUE self)
438
+ {
439
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
440
+ const char *const type=amq_content_basic_get_type(content_obj->content);
441
+ return rb_str_new2(type);
442
+ }
443
+
444
+ /*
445
+ * AMQ_ContentBasic#type=(string) -> self
446
+ *
447
+ * message type
448
+ */
449
+ static VALUE cont_content_basic_set_type(VALUE self,VALUE type)
450
+ {
451
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
452
+ Check_Type(type,T_STRING);
453
+ char *_type = StringValuePtr(type);
454
+
455
+ amq_content_basic_set_type(content_obj->content,_type);
456
+ return self;
457
+ }
458
+
459
+
460
+
461
+ /*
462
+ * AMQ_ContentBasic#user_id -> string
463
+ *
464
+ */
465
+ static VALUE cont_content_basic_get_user_id(VALUE self)
466
+ {
467
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
468
+ const char *const user_id=amq_content_basic_get_user_id(content_obj->content);
469
+ return rb_str_new2(user_id);
470
+ }
471
+
472
+ /*
473
+ * AMQ_ContentBasic#user_id=(string) -> self
474
+ *
475
+ */
476
+ static VALUE cont_content_basic_set_user_id(VALUE self,VALUE user_id)
477
+ {
478
+ amq_content_cls* const content_obj=get_amq_content_cls(self,1);
479
+ Check_Type(user_id,T_STRING);
480
+ char *_user_id = StringValuePtr(user_id);
481
+
482
+ amq_content_basic_set_user_id(content_obj->content,_user_id);
483
+ return self;
484
+ }
485
+
486
+
487
+ void init_content() {
488
+ amqp_content = rb_define_class_under(rb_wireapi,"AMQ_ContentBasic",rb_cObject);
489
+ //content
490
+ //rb_define_method(amqp_content,"class_id",cont_content_basic_class_id,0);
491
+ rb_define_method(amqp_content,"app_id",cont_content_basic_get_app_id,0);
492
+ rb_define_method(amqp_content,"app_id=",cont_content_basic_set_app_id,1);
493
+ rb_define_method(amqp_content,"body", cont_content_basic_get_body,-1);
494
+ rb_define_method(amqp_content,"body=",cont_content_basic_set_body,1);
495
+ rb_define_method(amqp_content,"body_size",cont_content_basic_get_body_size,0);
496
+ rb_define_method(amqp_content,"content_encoding",cont_content_basic_get_content_encoding,0);
497
+ rb_define_method(amqp_content,"content_encoding=",cont_content_basic_set_content_encoding,1);
498
+ rb_define_method(amqp_content,"content_type",cont_content_basic_get_content_type,0);
499
+ rb_define_method(amqp_content,"content_type=",cont_content_basic_set_content_type,1);
500
+ rb_define_method(amqp_content,"correlation_id",cont_content_basic_get_correlation_id,0);
501
+ rb_define_method(amqp_content,"correlation_id=",cont_content_basic_set_correlation_id,1);
502
+ rb_define_method(amqp_content,"destroy",cont_content_basic_destroy,0);
503
+ rb_define_method(amqp_content,"delivery_mode_persistent",cont_content_basic_get_delivery_mode_persistent,0);
504
+ rb_define_method(amqp_content,"delivery_mode_persistent=",cont_content_basic_set_delivery_mode_persistent,1);
505
+
506
+ rb_define_method(amqp_content,"exchange",cont_content_basic_get_exchange,0);
507
+ rb_define_method(amqp_content,"expiration",cont_content_basic_get_expiration,0);
508
+ rb_define_method(amqp_content,"expiration=",cont_content_basic_set_expiration,1);
509
+ rb_define_method(amqp_content,"headers",cont_content_basic_get_headers,0);
510
+ rb_define_method(amqp_content,"headers=",cont_content_basic_set_headers,1);
511
+ rb_define_method(amqp_content,"message_id",cont_content_basic_get_message_id,0);
512
+ rb_define_method(amqp_content,"message_id=",cont_content_basic_set_message_id,1);
513
+ rb_define_method(amqp_content,"priority",cont_content_basic_get_priority,0);
514
+ rb_define_method(amqp_content,"priority=",cont_content_basic_set_priority,1);
515
+ rb_define_method(amqp_content,"producer_id",cont_content_basic_get_producer_id,0);
516
+ rb_define_method(amqp_content,"reply_to",cont_content_basic_get_reply_to,0);
517
+ rb_define_method(amqp_content,"reply_to=",cont_content_basic_set_reply_to,1);
518
+ rb_define_method(amqp_content,"routing_key",cont_content_basic_get_routing_key,0);
519
+ rb_define_method(amqp_content,"sender_id",cont_content_basic_get_sender_id,0);
520
+ rb_define_method(amqp_content,"sender_id=",cont_content_basic_set_sender_id,1);
521
+ rb_define_method(amqp_content,"type",cont_content_basic_get_type,0);
522
+ rb_define_method(amqp_content,"type=",cont_content_basic_set_type,1);
523
+ rb_define_method(amqp_content,"unlink",cont_content_basic_destroy,0);
524
+ rb_define_method(amqp_content,"user_id",cont_content_basic_get_user_id,0);
525
+ rb_define_method(amqp_content,"user_id=",cont_content_basic_set_user_id,1);
526
+ rb_define_singleton_method(amqp_content, "new" , cont_content_basic_new , 0);
527
+
528
+
529
+
530
+ //rb_define_method(amqp_content,"timestamp",cont_timestamp,0);
531
+ //rb_define_method(amqp_content,"content_basic_set_class_id",cont_content_basic_set_class_id,0);
532
+ //rb_define_method(amqp_content,"content_basic_set_timestamp",cont_content_basic_set_timestamp,0);
533
+ }
data/amq_content.h ADDED
@@ -0,0 +1,7 @@
1
+ #ifndef AMQ_CONTENT_HEADER
2
+ #define AMQ_CONTENT_HEADER
3
+
4
+ void init_content();
5
+
6
+
7
+ #endif