lwes 0.5.0 → 0.6.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.
- data/ChangeLog +9 -0
- data/Rakefile +5 -0
- data/ext/lwes/emitter.c +17 -3
- data/ext/lwes/event.c +224 -0
- data/ext/lwes/extconf.rb +1 -1
- data/ext/lwes/lwes.c +1 -0
- data/ext/lwes/lwes_ruby.h +8 -0
- data/lib/lwes.rb +1 -0
- data/lwes.gemspec +2 -1
- metadata +4 -3
data/ChangeLog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
Version 0.6.0 (erik-s-chang)
|
2
|
+
* start of a new LWES::Event type, mostly incomplete, but able
|
3
|
+
to parse UDP buffers into a hash.
|
4
|
+
|
5
|
+
Version 0.5.0 (erik-s-chang)
|
6
|
+
* automatic type coercion between String and Integer types when
|
7
|
+
using Structs
|
8
|
+
* bundled LWES C library to avoid network dependency during install
|
9
|
+
|
1
10
|
Version 0.4.0 (erik-s-chang)
|
2
11
|
* large performance improvements for ESF + Struct users with large events,
|
3
12
|
one real world app is nearly twice as fast
|
data/Rakefile
CHANGED
@@ -17,3 +17,8 @@ RDoc::Task.new do |rd|
|
|
17
17
|
rd.main = "README"
|
18
18
|
rd.rdoc_files.include("README", "lib/**/*.rb", "ext/lwes/*.c")
|
19
19
|
end
|
20
|
+
|
21
|
+
desc "update website"
|
22
|
+
task :update_website => :rerdoc do
|
23
|
+
system 'rsync -avz html/ rubyforge.org:/var/www/gforge-projects/lwes/'
|
24
|
+
end
|
data/ext/lwes/emitter.c
CHANGED
@@ -37,7 +37,6 @@ static int dump_string(VALUE name, VALUE val, LWES_BYTE_P buf, size_t *off)
|
|
37
37
|
char *dst;
|
38
38
|
|
39
39
|
switch (TYPE(val)) {
|
40
|
-
case T_FLOAT:
|
41
40
|
case T_BIGNUM:
|
42
41
|
case T_FIXNUM:
|
43
42
|
val = rb_obj_as_string(val);
|
@@ -318,6 +317,15 @@ static VALUE emit_struct(VALUE self, VALUE event)
|
|
318
317
|
return event;
|
319
318
|
}
|
320
319
|
|
320
|
+
static VALUE emit_event(VALUE self, VALUE event)
|
321
|
+
{
|
322
|
+
struct lwes_event *e = lwesrb_get_event(event);
|
323
|
+
|
324
|
+
if (lwes_emitter_emit(_rle(self)->emitter, e) < 0)
|
325
|
+
rb_raise(rb_eRuntimeError, "failed to emit event");
|
326
|
+
|
327
|
+
return event;
|
328
|
+
}
|
321
329
|
/*
|
322
330
|
* call-seq:
|
323
331
|
* emitter = LWES::Emitter.new
|
@@ -327,9 +335,13 @@ static VALUE emit_struct(VALUE self, VALUE event)
|
|
327
335
|
*/
|
328
336
|
static VALUE emitter_ltlt(VALUE self, VALUE event)
|
329
337
|
{
|
330
|
-
|
338
|
+
if (rb_obj_is_kind_of(event, cLWES_Event)) {
|
339
|
+
return emit_event(self, event);
|
340
|
+
} else {
|
341
|
+
Check_Type(event, T_STRUCT);
|
331
342
|
|
332
|
-
|
343
|
+
return emit_struct(self, event);
|
344
|
+
}
|
333
345
|
}
|
334
346
|
|
335
347
|
/*
|
@@ -378,6 +390,8 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
|
|
378
390
|
event = rb_funcall(name, id_new, 1, event);
|
379
391
|
return emit_struct(self, event);
|
380
392
|
default:
|
393
|
+
if (rb_obj_is_kind_of(name, cLWES_Event))
|
394
|
+
return emit_event(self, name);
|
381
395
|
rb_raise(rb_eArgError,
|
382
396
|
"bad argument: %s, must be a String, Struct or Class",
|
383
397
|
RAISE_INSPECT(name));
|
data/ext/lwes/event.c
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
#include "lwes_ruby.h"
|
2
|
+
VALUE cLWES_Event;
|
3
|
+
|
4
|
+
static ID id_TYPE_DB, id_NAME;
|
5
|
+
static VALUE sym_name;
|
6
|
+
|
7
|
+
struct lwes_event * lwesrb_get_event(VALUE self)
|
8
|
+
{
|
9
|
+
struct lwes_event *event;
|
10
|
+
|
11
|
+
Data_Get_Struct(self, struct lwes_event, event);
|
12
|
+
|
13
|
+
return event;
|
14
|
+
}
|
15
|
+
|
16
|
+
static void event_free(void *ptr)
|
17
|
+
{
|
18
|
+
struct lwes_event *event = ptr;
|
19
|
+
|
20
|
+
lwes_event_destroy(event);
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
static VALUE event_alloc(VALUE klass)
|
25
|
+
{
|
26
|
+
struct lwes_event *e;
|
27
|
+
|
28
|
+
if (klass == cLWES_Event) {
|
29
|
+
e = lwes_event_create_no_name(NULL);
|
30
|
+
if (e == NULL) {
|
31
|
+
rb_gc();
|
32
|
+
e = lwes_event_create_no_name(NULL);
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
VALUE type_db = rb_const_get(klass, id_TYPE_DB);
|
36
|
+
struct lwes_event_type_db *tdb = lwesrb_get_type_db(type_db);
|
37
|
+
VALUE name = rb_const_get(klass, id_NAME);
|
38
|
+
const char *ename = StringValuePtr(name);
|
39
|
+
|
40
|
+
e = lwes_event_create(tdb, ename);
|
41
|
+
if (e == NULL) {
|
42
|
+
rb_gc();
|
43
|
+
e = lwes_event_create(tdb, ename);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
if (e == NULL)
|
47
|
+
rb_memerror();
|
48
|
+
|
49
|
+
return Data_Wrap_Struct(klass, NULL, event_free, e);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* kv - Array:
|
54
|
+
* key => String,
|
55
|
+
* key => [ numeric_type, Numeric ],
|
56
|
+
* key => true,
|
57
|
+
* key => false,
|
58
|
+
* memo - lwes_event pointer
|
59
|
+
*/
|
60
|
+
static VALUE event_hash_iter_i(VALUE kv, VALUE memo)
|
61
|
+
{
|
62
|
+
/* TODO */
|
63
|
+
}
|
64
|
+
|
65
|
+
static struct lwes_event_type_db * get_type_db(VALUE self)
|
66
|
+
{
|
67
|
+
VALUE type_db = rb_const_get(CLASS_OF(self), id_TYPE_DB);
|
68
|
+
struct lwes_event_type_db *tdb = lwesrb_get_type_db(type_db);
|
69
|
+
|
70
|
+
return tdb;
|
71
|
+
}
|
72
|
+
|
73
|
+
static VALUE event_init(int argc, VALUE *argv, VALUE self)
|
74
|
+
{
|
75
|
+
VALUE hash;
|
76
|
+
struct lwes_event *event;
|
77
|
+
|
78
|
+
rb_scan_args(argc, argv, "01", &hash);
|
79
|
+
|
80
|
+
Data_Get_Struct(self, struct lwes_event, event);
|
81
|
+
|
82
|
+
return self;
|
83
|
+
}
|
84
|
+
|
85
|
+
static VALUE event_aset(VALUE self, VALUE key, VALUE val)
|
86
|
+
{
|
87
|
+
struct lwes_event_type_db *tdb = get_type_db(self);
|
88
|
+
struct lwes_event *e = lwesrb_get_event(self);
|
89
|
+
const char *attr = StringValuePtr(key);
|
90
|
+
struct lwes_hash *ehash = lwes_hash_get(tdb->events, e->eventName);
|
91
|
+
LWES_BYTE *attr_type;
|
92
|
+
|
93
|
+
if (ehash == NULL)
|
94
|
+
rb_raise(rb_eArgError, "invalid event: %s\n", e->eventName);
|
95
|
+
|
96
|
+
attr_type = lwes_hash_get(ehash, attr);
|
97
|
+
if (attr_type == NULL)
|
98
|
+
rb_raise(rb_eArgError, "invalid attribute: %s\n", attr);
|
99
|
+
|
100
|
+
switch (*attr_type) {
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE lwesrb_attr_to_value(struct lwes_event_attribute *attr)
|
105
|
+
{
|
106
|
+
if (attr->type == LWES_STRING_TOKEN) {
|
107
|
+
return rb_str_new2((const char *)attr->value);
|
108
|
+
} else if (attr->type == LWES_U_INT_16_TOKEN) {
|
109
|
+
return UINT2NUM(*((uint16_t *)attr->value));
|
110
|
+
} else if (attr->type == LWES_INT_16_TOKEN) {
|
111
|
+
return INT2FIX(*((int16_t *)attr->value));
|
112
|
+
} else if (attr->type == LWES_U_INT_32_TOKEN) {
|
113
|
+
return UINT2NUM(*((uint32_t *)attr->value));
|
114
|
+
} else if (attr->type == LWES_INT_32_TOKEN) {
|
115
|
+
return INT2NUM(*((int32_t *)attr->value));
|
116
|
+
} else if (attr->type == LWES_U_INT_64_TOKEN) {
|
117
|
+
return ULL2NUM(*((uint64_t *)attr->value));
|
118
|
+
} else if (attr->type == LWES_INT_64_TOKEN) {
|
119
|
+
return LL2NUM(*((int64_t *)attr->value));
|
120
|
+
} else if (attr->type == LWES_BOOLEAN_TOKEN) {
|
121
|
+
LWES_BOOLEAN b = *(LWES_BOOLEAN*)attr->value;
|
122
|
+
return b ? Qtrue : Qfalse;
|
123
|
+
} else if (attr->type == LWES_IP_ADDR_TOKEN) {
|
124
|
+
LWES_IP_ADDR *addr = attr->value;
|
125
|
+
VALUE str = rb_str_new(0, INET_ADDRSTRLEN);
|
126
|
+
socklen_t len = (socklen_t)INET_ADDRSTRLEN;
|
127
|
+
const char *name;
|
128
|
+
|
129
|
+
name = inet_ntop(AF_INET, addr, RSTRING_PTR(str), len);
|
130
|
+
if (name == NULL)
|
131
|
+
rb_raise(rb_eTypeError, "invalid IP address");
|
132
|
+
rb_str_set_len(str, strlen(name));
|
133
|
+
return str;
|
134
|
+
} else {
|
135
|
+
/*
|
136
|
+
* possible event corruption
|
137
|
+
* skip it like the C library does ...
|
138
|
+
*/
|
139
|
+
}
|
140
|
+
return Qnil;
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* Returns an LWES::Event object as a plain Ruby hash
|
145
|
+
*/
|
146
|
+
static VALUE to_hash(VALUE self)
|
147
|
+
{
|
148
|
+
struct lwes_event *e = lwesrb_get_event(self);
|
149
|
+
|
150
|
+
return lwesrb_event_to_hash(e);
|
151
|
+
}
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
*
|
156
|
+
* receiver = UDPSocket.new
|
157
|
+
* receiver.bind(nil, 12345)
|
158
|
+
* buf, addr = receiver.recvfrom(65536)
|
159
|
+
* parsed = LWES::Event.parse(buf)
|
160
|
+
* parsed.to_hash -> hash
|
161
|
+
*
|
162
|
+
* Parses a string +buf+ and returns a new LWES::Event object
|
163
|
+
*/
|
164
|
+
static VALUE parse(VALUE self, VALUE buf)
|
165
|
+
{
|
166
|
+
VALUE event = event_alloc(cLWES_Event);
|
167
|
+
struct lwes_event *e = lwesrb_get_event(event);
|
168
|
+
struct lwes_event_deserialize_tmp dtmp;
|
169
|
+
LWES_BYTE_P bytes;
|
170
|
+
size_t num_bytes;
|
171
|
+
int rc;
|
172
|
+
|
173
|
+
StringValue(buf);
|
174
|
+
bytes = (LWES_BYTE_P)RSTRING_PTR(buf);
|
175
|
+
num_bytes = (size_t)RSTRING_LEN(buf);
|
176
|
+
rc = lwes_event_from_bytes(e, bytes, num_bytes, 0, &dtmp);
|
177
|
+
if (rc < 0)
|
178
|
+
rb_raise(rb_eRuntimeError,
|
179
|
+
"failed to parse LWES event (code: %d)\n", rc);
|
180
|
+
return event;
|
181
|
+
}
|
182
|
+
|
183
|
+
VALUE lwesrb_event_to_hash(struct lwes_event *e)
|
184
|
+
{
|
185
|
+
VALUE rv = rb_hash_new();
|
186
|
+
VALUE val;
|
187
|
+
struct lwes_hash_enumeration hen;
|
188
|
+
LWES_SHORT_STRING name;
|
189
|
+
VALUE sym_attr_name;
|
190
|
+
struct lwes_event_attribute *attr;
|
191
|
+
|
192
|
+
if (e->eventName != NULL) {
|
193
|
+
val = rb_str_new2(e->eventName);
|
194
|
+
rb_hash_aset(rv, sym_name, val);
|
195
|
+
}
|
196
|
+
|
197
|
+
if (! lwes_hash_keys(e->attributes, &hen))
|
198
|
+
return rv;
|
199
|
+
while (lwes_hash_enumeration_has_more_elements(&hen)) {
|
200
|
+
name = lwes_hash_enumeration_next_element(&hen);
|
201
|
+
sym_attr_name = ID2SYM(rb_intern(name));
|
202
|
+
attr = lwes_hash_get(e->attributes, name);
|
203
|
+
val = lwesrb_attr_to_value(attr);
|
204
|
+
if (! NIL_P(val))
|
205
|
+
rb_hash_aset(rv, sym_attr_name, val);
|
206
|
+
}
|
207
|
+
|
208
|
+
return rv;
|
209
|
+
}
|
210
|
+
|
211
|
+
void lwesrb_init_event(void)
|
212
|
+
{
|
213
|
+
VALUE mLWES = rb_define_module("LWES");
|
214
|
+
cLWES_Event = rb_define_class_under(mLWES, "Event", rb_cObject);
|
215
|
+
|
216
|
+
rb_define_method(cLWES_Event, "initialize", event_init, -1);
|
217
|
+
rb_define_alloc_func(cLWES_Event, event_alloc);
|
218
|
+
rb_define_singleton_method(cLWES_Event, "parse", parse, 1);
|
219
|
+
rb_define_method(cLWES_Event, "to_hash", to_hash, 0);
|
220
|
+
|
221
|
+
LWESRB_MKID(TYPE_DB);
|
222
|
+
LWESRB_MKID(NAME);
|
223
|
+
LWESRB_MKSYM(name);
|
224
|
+
}
|
data/ext/lwes/extconf.rb
CHANGED
@@ -25,7 +25,7 @@ def fetch(uri_str, limit = 10)
|
|
25
25
|
end
|
26
26
|
|
27
27
|
unless have_library('lwes') && have_header('lwes.h')
|
28
|
-
warn "LWES library not found,
|
28
|
+
warn "LWES library not found, building locally"
|
29
29
|
Dir.chdir(pwd) do
|
30
30
|
unless test ?r, tgz
|
31
31
|
response = fetch(url)
|
data/ext/lwes/lwes.c
CHANGED
data/ext/lwes/lwes_ruby.h
CHANGED
@@ -19,6 +19,8 @@ void lwesrb_init_emitter(void);
|
|
19
19
|
|
20
20
|
void lwesrb_init_numeric(void);
|
21
21
|
|
22
|
+
void lwesrb_init_event(void);
|
23
|
+
|
22
24
|
void lwesrb_dump_type(LWES_BYTE type, LWES_BYTE_P buf, size_t *off);
|
23
25
|
|
24
26
|
void lwesrb_dump_num(LWES_BYTE type, VALUE val, LWES_BYTE_P buf, size_t *off);
|
@@ -42,4 +44,10 @@ void lwesrb_dump_num_ary(VALUE array, LWES_BYTE_P buf, size_t *off);
|
|
42
44
|
|
43
45
|
#define RAISE_INSPECT(v) RSTRING_PTR(raise_inspect = rb_inspect(v))
|
44
46
|
|
47
|
+
extern VALUE cLWES_Event;
|
48
|
+
|
49
|
+
struct lwes_event * lwesrb_get_event(VALUE self);
|
50
|
+
|
51
|
+
VALUE lwesrb_event_to_hash(struct lwes_event *e);
|
52
|
+
|
45
53
|
#endif /* LWES_RUBY_H */
|
data/lib/lwes.rb
CHANGED
data/lwes.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{lwes}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.6.0"
|
4
4
|
s.date = Time.now
|
5
5
|
s.authors = ["Erik S. Chang", "Frank Maritato"]
|
6
6
|
s.email = %q{lwes-devel@lists.sourceforge.net}
|
@@ -27,6 +27,7 @@ ext/lwes/lwes-0.22.3.diff
|
|
27
27
|
ext/lwes/lwes-0.22.3.tar.gz
|
28
28
|
ext/lwes/lwes.c
|
29
29
|
ext/lwes/lwes_ruby.h
|
30
|
+
ext/lwes/event.c
|
30
31
|
ext/lwes/numeric.c
|
31
32
|
ext/lwes/type_db.c
|
32
33
|
lib/lwes.rb
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 6
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Erik S. Chang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-29 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- ext/lwes/lwes-0.22.3.tar.gz
|
46
46
|
- ext/lwes/lwes.c
|
47
47
|
- ext/lwes/lwes_ruby.h
|
48
|
+
- ext/lwes/event.c
|
48
49
|
- ext/lwes/numeric.c
|
49
50
|
- ext/lwes/type_db.c
|
50
51
|
- lib/lwes.rb
|