lwes 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/README +1 -1
- data/Rakefile +7 -0
- data/ext/lwes/emitter.c +50 -17
- data/ext/lwes/extconf.rb +4 -2
- data/ext/lwes/lwes_ruby.h +3 -0
- data/ext/lwes/type_db.c +1 -1
- data/lib/lwes.rb +1 -1
- data/lwes.gemspec +3 -1
- data/test/unit/meta_only.esf +8 -0
- data/test/unit/namespaced.esf +19 -0
- data/test/unit/test_emit_struct.rb +43 -0
- metadata +4 -2
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.2.1 (erik-s-chang)
|
2
|
+
* Emitter#<< for structs
|
3
|
+
* fix full installs OSX
|
4
|
+
* check arguments for invalid structs due to code errors
|
5
|
+
|
1
6
|
Version 0.1.2 (erik-s-chang)
|
2
7
|
* TypeDB.new raises ArgumentError on non-String args
|
3
8
|
* extra test for empty Event definitions (MetaEventInfo-only)
|
data/README
CHANGED
@@ -63,7 +63,7 @@ gem.
|
|
63
63
|
my_event.field2 = value2
|
64
64
|
my_event.field3 = value3
|
65
65
|
my_event.finished = Time.now.to_i
|
66
|
-
emitter
|
66
|
+
emitter << my_event
|
67
67
|
|
68
68
|
# Alternatively, if you know ahead of time all the fields you want to
|
69
69
|
# set for an event, you can emit an event in one step:
|
data/Rakefile
CHANGED
@@ -9,3 +9,10 @@ Rake::TestTask.new('test:unit') do |t|
|
|
9
9
|
t.test_files = FileList['test/unit/test_*.rb']
|
10
10
|
t.verbose = true if ENV["VERBOSE"].to_i > 0
|
11
11
|
end
|
12
|
+
|
13
|
+
gem 'rdoc', '>= 2.4.3'
|
14
|
+
require 'rdoc/task'
|
15
|
+
RDoc::Task.new do |rd|
|
16
|
+
rd.main = "README"
|
17
|
+
rd.rdoc_files.include("README", "lib/**/*.rb", "ext/lwes/*.c")
|
18
|
+
end
|
data/ext/lwes/emitter.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include "lwes_ruby.h"
|
2
2
|
|
3
3
|
static VALUE cLWES_Emitter;
|
4
|
-
static ID
|
4
|
+
static ID id_TYPE_DB, id_TYPE_LIST, id_NAME;
|
5
5
|
static ID id_new;
|
6
6
|
|
7
7
|
/* the underlying struct for LWES::Emitter */
|
@@ -132,10 +132,14 @@ static VALUE _emit_struct(VALUE _argv)
|
|
132
132
|
VALUE self = argv[0];
|
133
133
|
VALUE _event = argv[1];
|
134
134
|
struct lwes_event *event = (struct lwes_event *)argv[2];
|
135
|
-
VALUE type_list =
|
136
|
-
long i
|
135
|
+
VALUE type_list = argv[3];
|
136
|
+
long i;
|
137
137
|
VALUE *tmp;
|
138
138
|
|
139
|
+
if (TYPE(type_list) != T_ARRAY)
|
140
|
+
rb_raise(rb_eArgError, "could not get TYPE_LIST const");
|
141
|
+
|
142
|
+
i = RARRAY_LEN(type_list);
|
139
143
|
for (tmp = RARRAY_PTR(type_list); --i >= 0; tmp++) {
|
140
144
|
/* inner: [ :field_sym, "field_name", type ] */
|
141
145
|
VALUE *inner = RARRAY_PTR(*tmp);
|
@@ -191,30 +195,60 @@ static VALUE emit_hash(VALUE self, VALUE name, VALUE _event)
|
|
191
195
|
return _event;
|
192
196
|
}
|
193
197
|
|
194
|
-
static struct lwes_event_type_db * get_type_db(VALUE
|
198
|
+
static struct lwes_event_type_db * get_type_db(VALUE event_class)
|
195
199
|
{
|
196
|
-
VALUE type_db = rb_const_get(
|
200
|
+
VALUE type_db = rb_const_get(event_class, id_TYPE_DB);
|
201
|
+
|
202
|
+
if (CLASS_OF(type_db) != cLWES_TypeDB)
|
203
|
+
rb_raise(rb_eArgError, "class does not have valid TYPE_DB");
|
197
204
|
|
198
205
|
return lwesrb_get_type_db(type_db);
|
199
206
|
}
|
200
207
|
|
201
|
-
static VALUE emit_struct(VALUE self, VALUE
|
208
|
+
static VALUE emit_struct(VALUE self, VALUE _event)
|
202
209
|
{
|
203
|
-
VALUE argv[
|
204
|
-
|
205
|
-
struct
|
210
|
+
VALUE argv[4];
|
211
|
+
VALUE event_class = CLASS_OF(_event);
|
212
|
+
struct lwes_event_type_db *db = get_type_db(event_class);
|
213
|
+
struct lwes_event *event;
|
214
|
+
VALUE name = rb_const_get(event_class, id_NAME);
|
215
|
+
VALUE type_list = rb_const_get(event_class, id_TYPE_LIST);
|
216
|
+
|
217
|
+
if (TYPE(name) != T_STRING || TYPE(type_list) != T_ARRAY)
|
218
|
+
rb_raise(rb_eArgError,
|
219
|
+
"could not get class NAME or TYPE_LIST from: %s",
|
220
|
+
RSTRING_PTR(rb_inspect(_event)));
|
206
221
|
|
222
|
+
event = lwes_event_create(db, RSTRING_PTR(name));
|
207
223
|
if (!event)
|
208
224
|
rb_raise(rb_eRuntimeError, "failed to create lwes_event");
|
209
225
|
|
210
226
|
argv[0] = self;
|
211
227
|
argv[1] = _event;
|
212
228
|
argv[2] = (VALUE)event;
|
229
|
+
argv[3] = type_list;
|
213
230
|
rb_ensure(_emit_struct, (VALUE)&argv, _destroy_event, (VALUE)event);
|
214
231
|
|
215
232
|
return _event;
|
216
233
|
}
|
217
234
|
|
235
|
+
/*
|
236
|
+
* call-seq:
|
237
|
+
* emitter = LWES::Emitter.new
|
238
|
+
* event = EventStruct.new
|
239
|
+
* event.foo = "bar"
|
240
|
+
* emitter << event
|
241
|
+
*/
|
242
|
+
static VALUE emitter_ltlt(VALUE self, VALUE event)
|
243
|
+
{
|
244
|
+
if (TYPE(event) != T_STRUCT)
|
245
|
+
rb_raise(rb_eArgError,
|
246
|
+
"Must be a Struct: %s",
|
247
|
+
RSTRING_PTR(rb_inspect(event)));
|
248
|
+
|
249
|
+
return emit_struct(self, event);
|
250
|
+
}
|
251
|
+
|
218
252
|
/*
|
219
253
|
* call-seq:
|
220
254
|
* emitter = LWES::Emitter.new
|
@@ -246,8 +280,7 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
|
|
246
280
|
"second argument not allowed when first"
|
247
281
|
" is a Struct");
|
248
282
|
event = name;
|
249
|
-
|
250
|
-
return emit_struct(self, name, event);
|
283
|
+
return emit_struct(self, event);
|
251
284
|
case T_CLASS:
|
252
285
|
if (TYPE(event) != T_HASH)
|
253
286
|
rb_raise(rb_eArgError,
|
@@ -259,8 +292,7 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
|
|
259
292
|
* struct created
|
260
293
|
*/
|
261
294
|
event = rb_funcall(name, id_new, 1, event);
|
262
|
-
|
263
|
-
return emit_struct(self, name, event);
|
295
|
+
return emit_struct(self, event);
|
264
296
|
default:
|
265
297
|
rb_raise(rb_eArgError,
|
266
298
|
"bad argument: %s, must be a String, Struct or Class",
|
@@ -355,12 +387,13 @@ void lwesrb_init_emitter(void)
|
|
355
387
|
VALUE mLWES = rb_define_module("LWES");
|
356
388
|
cLWES_Emitter = rb_define_class_under(mLWES, "Emitter", rb_cObject);
|
357
389
|
|
390
|
+
rb_define_method(cLWES_Emitter, "<<", emitter_ltlt, 1);
|
358
391
|
rb_define_method(cLWES_Emitter, "emit", emitter_emit, -1);
|
359
392
|
rb_define_method(cLWES_Emitter, "_create", _create, 1);
|
360
393
|
rb_define_method(cLWES_Emitter, "close", emitter_close, 0);
|
361
394
|
rb_define_alloc_func(cLWES_Emitter, rle_alloc);
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
395
|
+
LWESRB_MKID(TYPE_DB);
|
396
|
+
LWESRB_MKID(TYPE_LIST);
|
397
|
+
LWESRB_MKID(NAME);
|
398
|
+
LWESRB_MKID(new);
|
366
399
|
}
|
data/ext/lwes/extconf.rb
CHANGED
@@ -37,7 +37,8 @@ unless have_library('lwes') && have_header('lwes.h')
|
|
37
37
|
FileUtils.rm_rf(dir)
|
38
38
|
system('tar', 'zxf', tgz) or abort "tar failed with #{$?}"
|
39
39
|
Dir.chdir(dir) do
|
40
|
-
|
40
|
+
args = %w(--disable-hardcore --with-pic --disable-dependency-tracking)
|
41
|
+
system("./configure", "--prefix=#{inst}", *args) or
|
41
42
|
abort "configure failed with #{$?}"
|
42
43
|
system("make") or abort "make failed with #{$?}"
|
43
44
|
system("make", "install") or abort "make install failed with #{$?}"
|
@@ -46,7 +47,8 @@ unless have_library('lwes') && have_header('lwes.h')
|
|
46
47
|
File.open("#{inst}/.ok", "wb") { }
|
47
48
|
end
|
48
49
|
$CFLAGS = "-I#{inst}/include/lwes-0 #{$CFLAGS}"
|
49
|
-
|
50
|
+
Dir.glob("#{inst}/lib/*") { |f| f =~ /\.l?a\z/ or FileUtils.rm_rf(f) }
|
51
|
+
$LDFLAGS = "-L#{inst}/lib #{$LDFLAGS}"
|
50
52
|
have_library('lwes') && have_header('lwes.h') or
|
51
53
|
abort "installation failed"
|
52
54
|
end
|
data/ext/lwes/lwes_ruby.h
CHANGED
data/ext/lwes/type_db.c
CHANGED
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.1
|
3
|
+
s.version = "0.2.1"
|
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}
|
@@ -33,6 +33,8 @@ lib/lwes/struct.rb
|
|
33
33
|
lib/lwes/type_db.rb
|
34
34
|
lwes.gemspec
|
35
35
|
test/test_helper.rb
|
36
|
+
test/unit/meta_only.esf
|
37
|
+
test/unit/namespaced.esf
|
36
38
|
test/unit/test1.esf
|
37
39
|
test/unit/test2.esf
|
38
40
|
test/unit/test_emit_struct.rb
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
2
|
|
3
|
+
class InvalidStruct1 < Struct.new(:invalid)
|
4
|
+
TYPE_DB = []
|
5
|
+
end
|
6
|
+
|
3
7
|
class TestEmitStruct < Test::Unit::TestCase
|
4
8
|
|
5
9
|
def setup
|
@@ -8,6 +12,18 @@ class TestEmitStruct < Test::Unit::TestCase
|
|
8
12
|
@options = LISTENER_DEFAULTS.dup
|
9
13
|
end
|
10
14
|
|
15
|
+
def test_emit_non_lwes_struct
|
16
|
+
emitter = LWES::Emitter.new(@options)
|
17
|
+
assert_raise(ArgumentError) { emitter << InvalidStruct1.new }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_emit_crap
|
21
|
+
emitter = LWES::Emitter.new(@options)
|
22
|
+
assert_raise(ArgumentError) { emitter << "HHI" }
|
23
|
+
assert_raise(ArgumentError) { emitter << [] }
|
24
|
+
assert_raise(ArgumentError) { emitter << {} }
|
25
|
+
end
|
26
|
+
|
11
27
|
def test_emit_struct_full
|
12
28
|
s = nil
|
13
29
|
out = lwes_listener do
|
@@ -35,6 +51,33 @@ class TestEmitStruct < Test::Unit::TestCase
|
|
35
51
|
end
|
36
52
|
end
|
37
53
|
|
54
|
+
def test_emit_struct_cplusplus
|
55
|
+
s = nil
|
56
|
+
out = lwes_listener do
|
57
|
+
assert_nothing_raised do
|
58
|
+
emitter = LWES::Emitter.new(@options)
|
59
|
+
s = Event1.new
|
60
|
+
s.t_bool = true
|
61
|
+
s.t_int16 = -1000
|
62
|
+
s.t_uint16 = 1000
|
63
|
+
s.t_int32 = -64444
|
64
|
+
s.t_uint32 = 64444
|
65
|
+
s.t_int64 = 10_000_000_000
|
66
|
+
s.t_uint64 = 10_000_000_000
|
67
|
+
s.t_ip_addr = '192.168.0.1'
|
68
|
+
s.t_string = "STRING"
|
69
|
+
emitter << s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
out = out.readlines
|
73
|
+
s.members.each do |m|
|
74
|
+
value = s[m.to_sym] or next
|
75
|
+
regex = /\b#{m} = #{value};/
|
76
|
+
assert_equal 1, out.grep(regex).size,
|
77
|
+
"#{regex.inspect} didn't match #{out.inspect}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
38
81
|
def test_emit_from_class
|
39
82
|
opt = {
|
40
83
|
:t_bool => true,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lwes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik S. Chang
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-12-
|
13
|
+
date: 2009-12-09 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -46,6 +46,8 @@ files:
|
|
46
46
|
- lib/lwes/type_db.rb
|
47
47
|
- lwes.gemspec
|
48
48
|
- test/test_helper.rb
|
49
|
+
- test/unit/meta_only.esf
|
50
|
+
- test/unit/namespaced.esf
|
49
51
|
- test/unit/test1.esf
|
50
52
|
- test/unit/test2.esf
|
51
53
|
- test/unit/test_emit_struct.rb
|