lwes 0.4.0 → 0.5.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/README CHANGED
@@ -25,6 +25,12 @@ may support listening and journaling capabilities as time allows.
25
25
 
26
26
  See the SourceForge project.
27
27
 
28
+ == DEVELOPMENT:
29
+
30
+ Our SVN repository is here:
31
+
32
+ https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-ruby
33
+
28
34
  == INSTALL:
29
35
 
30
36
  This library is easy to install, if you have the LWES library already
@@ -34,14 +34,19 @@ static int dump_bool(VALUE name, VALUE val, LWES_BYTE_P buf, size_t *off)
34
34
 
35
35
  static int dump_string(VALUE name, VALUE val, LWES_BYTE_P buf, size_t *off)
36
36
  {
37
- volatile VALUE raise_inspect;
37
+ char *dst;
38
+
39
+ switch (TYPE(val)) {
40
+ case T_FLOAT:
41
+ case T_BIGNUM:
42
+ case T_FIXNUM:
43
+ val = rb_obj_as_string(val);
44
+ }
45
+ dst = StringValuePtr(val);
38
46
 
39
- if (TYPE(val) != T_STRING)
40
- rb_raise(rb_eTypeError, "not a string: %s",
41
- RAISE_INSPECT(val));
42
47
  dump_name(name, buf, off);
43
48
  lwesrb_dump_type(LWES_STRING_TOKEN, buf, off);
44
- return marshall_LONG_STRING(RSTRING_PTR(val), buf, MAX_MSG_SIZE, off);
49
+ return marshall_LONG_STRING(dst, buf, MAX_MSG_SIZE, off);
45
50
  }
46
51
 
47
52
  static void dump_enc(VALUE enc, LWES_BYTE_P buf, size_t *off)
@@ -234,7 +239,6 @@ static void lwes_struct_class(
234
239
  VALUE event)
235
240
  {
236
241
  VALUE type_db;
237
- volatile VALUE raise_inspect;
238
242
 
239
243
  *event_class = CLASS_OF(event);
240
244
  type_db = rb_const_get(*event_class, id_TYPE_DB);
@@ -243,16 +247,9 @@ static void lwes_struct_class(
243
247
  rb_raise(rb_eArgError, "class does not have valid TYPE_DB");
244
248
 
245
249
  *name = rb_const_get(*event_class, id_NAME);
246
- if (TYPE(*name) != T_STRING)
247
- rb_raise(rb_eArgError,
248
- "could not get valid const NAME: %s",
249
- RAISE_INSPECT(event));
250
-
250
+ Check_Type(*name, T_STRING);
251
251
  *type_list = rb_const_get(*event_class, id_TYPE_LIST);
252
- if (TYPE(*type_list) != T_ARRAY)
253
- rb_raise(rb_eArgError,
254
- "could not get valid const TYPE_LIST: %s",
255
- RAISE_INSPECT(event));
252
+ Check_Type(*type_list, T_ARRAY);
256
253
 
257
254
  *have_enc = rb_const_get(*event_class, id_HAVE_ENCODING);
258
255
  }
@@ -330,12 +327,9 @@ static VALUE emit_struct(VALUE self, VALUE event)
330
327
  */
331
328
  static VALUE emitter_ltlt(VALUE self, VALUE event)
332
329
  {
333
- volatile VALUE raise_inspect;
330
+ Check_Type(event, T_STRUCT);
334
331
 
335
- if (TYPE(event) == T_STRUCT)
336
- return emit_struct(self, event);
337
-
338
- rb_raise(rb_eArgError, "Must be a Struct: %s", RAISE_INSPECT(event));
332
+ return emit_struct(self, event);
339
333
  }
340
334
 
341
335
  /*
@@ -373,7 +367,7 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
373
367
  return emit_struct(self, event);
374
368
  case T_CLASS:
375
369
  if (TYPE(event) != T_HASH)
376
- rb_raise(rb_eArgError,
370
+ rb_raise(rb_eTypeError,
377
371
  "second argument must be a Hash when first"
378
372
  " is a Class");
379
373
 
@@ -6,6 +6,7 @@ static ID
6
6
  sym_int32, sym_uint32,
7
7
  sym_int64, sym_uint64,
8
8
  sym_ip_addr;
9
+ static ID id_to_i;
9
10
 
10
11
  void lwesrb_dump_type(LWES_BYTE type, LWES_BYTE_P buf, size_t *off)
11
12
  {
@@ -136,6 +137,9 @@ static int dump_num(
136
137
  LWES_BYTE_P buf,
137
138
  size_t *off)
138
139
  {
140
+ if (type != LWES_TYPE_IP_ADDR && TYPE(val) == T_STRING)
141
+ val = rb_funcall(val, id_to_i, 0, 0);
142
+
139
143
  switch (type) {
140
144
  case LWES_TYPE_U_INT_16: return dump_uint16(val, buf, off);
141
145
  case LWES_TYPE_INT_16: return dump_int16(val, buf, off);
@@ -210,6 +214,7 @@ void lwesrb_init_numeric(void)
210
214
  LWESRB_MKSYM(int64);
211
215
  LWESRB_MKSYM(uint64);
212
216
  LWESRB_MKSYM(ip_addr);
217
+ id_to_i = rb_intern("to_i");
213
218
 
214
219
  /*
215
220
  * we needed to have constants for compilation, so we set the
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{lwes}
3
- s.version = "0.4.0"
3
+ s.version = "0.5.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}
@@ -24,6 +24,7 @@ examples/my_events.esf
24
24
  ext/lwes/emitter.c
25
25
  ext/lwes/extconf.rb
26
26
  ext/lwes/lwes-0.22.3.diff
27
+ ext/lwes/lwes-0.22.3.tar.gz
27
28
  ext/lwes/lwes.c
28
29
  ext/lwes/lwes_ruby.h
29
30
  ext/lwes/numeric.c
@@ -19,9 +19,9 @@ class TestEmitStruct < Test::Unit::TestCase
19
19
 
20
20
  def test_emit_crap
21
21
  emitter = LWES::Emitter.new(@options)
22
- assert_raise(ArgumentError) { emitter << "HHI" }
23
- assert_raise(ArgumentError) { emitter << [] }
24
- assert_raise(ArgumentError) { emitter << {} }
22
+ assert_raise(TypeError) { emitter << "HHI" }
23
+ assert_raise(TypeError) { emitter << [] }
24
+ assert_raise(TypeError) { emitter << {} }
25
25
  end
26
26
 
27
27
  def test_emit_struct_full
@@ -51,6 +51,33 @@ class TestEmitStruct < Test::Unit::TestCase
51
51
  end
52
52
  end
53
53
 
54
+ def test_emit_struct_coerce_type
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 = 1234567
69
+ emitter.emit(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
+
54
81
  def test_emit_struct_cplusplus
55
82
  s = nil
56
83
  out = lwes_listener do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lwes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Erik S. Chang
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-04-20 00:00:00 +00:00
18
+ date: 2010-09-14 00:00:00 +00:00
14
19
  default_executable:
15
20
  dependencies: []
16
21
 
@@ -37,6 +42,7 @@ files:
37
42
  - ext/lwes/emitter.c
38
43
  - ext/lwes/extconf.rb
39
44
  - ext/lwes/lwes-0.22.3.diff
45
+ - ext/lwes/lwes-0.22.3.tar.gz
40
46
  - ext/lwes/lwes.c
41
47
  - ext/lwes/lwes_ruby.h
42
48
  - ext/lwes/numeric.c
@@ -65,21 +71,25 @@ rdoc_options: []
65
71
  require_paths:
66
72
  - lib
67
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
68
75
  requirements:
69
76
  - - ">="
70
77
  - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
71
80
  version: "0"
72
- version:
73
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
74
83
  requirements:
75
84
  - - ">="
76
85
  - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
77
88
  version: "0"
78
- version:
79
89
  requirements: []
80
90
 
81
91
  rubyforge_project: lwes
82
- rubygems_version: 1.3.5
92
+ rubygems_version: 1.3.7
83
93
  signing_key:
84
94
  specification_version: 3
85
95
  summary: Ruby API for the Light Weight Event System